Module: Workarea::Storefront::ApplicationHelper

Defined in:
app/helpers/workarea/storefront/application_helper.rb

Instance Method Summary collapse

Instance Method Details

#add_css(css) ⇒ Object



16
17
18
19
20
21
22
# File 'app/helpers/workarea/storefront/application_helper.rb', line 16

def add_css(css)
  return unless css.present?

  content_for(:css) do
    (:style, css.html_safe)
  end
end

#add_javascript(js) ⇒ Object



24
25
26
27
28
29
30
# File 'app/helpers/workarea/storefront/application_helper.rb', line 24

def add_javascript(js)
  return unless js.present?

  content_for(:javascript) do
    (:script, js.html_safe)
  end
end

#flash_messagesObject



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'app/helpers/workarea/storefront/application_helper.rb', line 32

def flash_messages
  flash.keys.inject('') do |memo, name|
    msg = flash[name]
    html_options = {
      data: {
        analytics: {
          event: 'flashMessage',
          payload: { type: name }
        }.to_json
      }
    }

    if msg.is_a?(Enumerable)
      msg.each do |message|
        if message.is_a?(String)
          memo << render_message(name, message, html_options)
        end
      end
    elsif msg.is_a?(String)
      memo << render_message(name, msg, html_options)
    end

    flash.delete(name)
    memo
  end.html_safe
end

#loading_indicator(message, *modifiers) ⇒ Object



67
68
69
70
# File 'app/helpers/workarea/storefront/application_helper.rb', line 67

def loading_indicator(message, *modifiers)
  css_classes = modifiers.map { |c| "loading--#{c}" }.join(' ')
  (:span, message, class: "loading loading--inline #{css_classes}")
end

#optional_field(prompt, *fields, &block) ⇒ Object



72
73
74
75
76
# File 'app/helpers/workarea/storefront/application_helper.rb', line 72

def optional_field(prompt, *fields, &block)
  return capture(&block) if fields.any?(&:present?)
  (:div, capture(&block), { class: 'hidden-if-js-enabled',
                                       data: { optional_field: prompt } })
end

#page_title(title_content = @title) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
# File 'app/helpers/workarea/storefront/application_helper.rb', line 4

def page_title(title_content = @title)
  title = [title_content, Workarea.config.site_name]
            .reject(&:blank?)
            .join(' - ')

  unless Rails.env.in?(%w(test development production))
    title = "[#{Rails.env.upcase}] #{title}"
  end

  title
end

#render_message(type, message = nil, html_options = {}, &block) ⇒ Object



59
60
61
62
63
64
65
# File 'app/helpers/workarea/storefront/application_helper.rb', line 59

def render_message(type, message = nil, html_options = {}, &block)
  html_options = message if message.is_a?(Hash)
  message = capture(&block) if block_given?

  html_options[:class] = "message--#{type.systemize}"
  render('workarea/storefront/shared/message', type: type.systemize, message: message, html_options: html_options)
end