Module: Workarea::Storefront::ApplicationHelper
- Defined in:
- app/helpers/workarea/storefront/application_helper.rb
Instance Method Summary collapse
- #add_css(css) ⇒ Object
- #add_head_content(content) ⇒ Object
- #add_javascript(js) ⇒ Object
- #flash_messages ⇒ Object
- #loading_indicator(message, *modifiers) ⇒ Object
- #optional_field(prompt, *fields, &block) ⇒ Object
- #page_title(title_content = @title) ⇒ Object
- #render_message(type, message = nil, html_options = {}, &block) ⇒ Object
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 content_tag(: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 content_tag(:script, js.html_safe) end end |
#flash_messages ⇒ Object
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.keys.inject('') do |memo, name| msg = flash[name] = { data: { analytics: { event: 'flashMessage', payload: { type: name } }.to_json } } if msg.is_a?(Enumerable) msg.each do || if .is_a?(String) memo << (name, , ) end end elsif msg.is_a?(String) memo << (name, msg, ) 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(, *modifiers) css_classes = modifiers.map { |c| "loading--#{c}" }.join(' ') content_tag(:span, , 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?) content_tag(: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 (type, = nil, = {}, &block) = if .is_a?(Hash) = capture(&block) if block_given? [:class] = "message--#{type.systemize}" render('workarea/storefront/shared/message', type: type.systemize, message: , html_options: ) end |