Module: Workarea::Storefront::ApplicationHelper

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

Instance Method Summary collapse

Instance Method Details

#add_css(css) ⇒ Object



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

def add_css(css)
  return unless css.present?

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

#add_head_content(content) ⇒ Object



40
41
42
43
44
45
46
# File 'app/helpers/workarea/storefront/application_helper.rb', line 40

def add_head_content(content)
  return unless content.present?

  content_for(:head_content) do
    content.html_safe
  end
end

#add_javascript(js) ⇒ Object



32
33
34
35
36
37
38
# File 'app/helpers/workarea/storefront/application_helper.rb', line 32

def add_javascript(js)
  return unless js.present?

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

#flash_messagesObject



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'app/helpers/workarea/storefront/application_helper.rb', line 48

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



83
84
85
86
# File 'app/helpers/workarea/storefront/application_helper.rb', line 83

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



88
89
90
91
92
# File 'app/helpers/workarea/storefront/application_helper.rb', line 88

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
15
16
17
18
19
20
21
22
# File 'app/helpers/workarea/storefront/application_helper.rb', line 4

def page_title(title_content = @title)
  if title_content.present?
    title = t(
      'workarea.storefront.layouts.page_title_with_content',
      title_content: title_content,
      site_name: Workarea.config.site_name
    )
  else
    title = t('workarea.storefront.layouts.page_title',
      site_name: Workarea.config.site_name
    )
  end

  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



75
76
77
78
79
80
81
# File 'app/helpers/workarea/storefront/application_helper.rb', line 75

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