Module: Lcms::Engine::ViewHelper
- Included in:
- ApplicationHelper
- Defined in:
- app/helpers/lcms/engine/view_helper.rb
Overview
rubocop:disable Metrics/ModuleLength
Constant Summary collapse
- ENABLE_BASE64_CACHING =
ActiveRecord::ConnectionAdapters::Column::TRUE_VALUES.include?( ENV.fetch('ENABLE_BASE64_CACHING', true) )
Instance Method Summary collapse
- #add_class_for_action(controller_name, action_name, klass, klass_prefix = nil) ⇒ Object
- #add_class_for_path(link_path, klass, klass_prefix = nil) ⇒ Object
- #base64_encoded_asset(path) ⇒ Object
- #color_code(model, base: false) ⇒ Object
- #flash_to_hash ⇒ Object
- #header_mod ⇒ Object
- #inlined_asset(path) ⇒ Object
- #lcms_engine_url_helpers ⇒ Object
- #nav_link(link_text, link_path, attrs = {}, link_attrs = {}) ⇒ Object
- #page_description ⇒ Object
- #page_og_image ⇒ Object
- #page_title ⇒ Object
-
#redirect_meta_tag ⇒ Object
Render meta tag.
-
#redirect_via_meta_tag(to_url:, delay: 5) ⇒ Object
Use in views as redirection directive.
- #selected_id?(id) ⇒ Boolean
-
#set_canonical_url(value) ⇒ Object
rubocop:disable Naming/AccessorMethodName.
-
#set_page_description(dsc) ⇒ Object
rubocop:disable Naming/AccessorMethodName.
-
#set_page_title(title) ⇒ Object
rubocop:disable Naming/AccessorMethodName.
-
#set_social_media_sharing(target) ⇒ Object
rubocop:disable Naming/AccessorMethodName.
- #social_media ⇒ Object
- #strip_tags_and_squish(str) ⇒ Object
Instance Method Details
#add_class_for_action(controller_name, action_name, klass, klass_prefix = nil) ⇒ Object
17 18 19 20 21 22 |
# File 'app/helpers/lcms/engine/view_helper.rb', line 17 def add_class_for_action(controller_name, action_name, klass, klass_prefix = nil) if controller.controller_name == controller_name.to_s && controller.action_name == action_name.to_s sufix = klass end "#{klass_prefix} #{sufix}" end |
#add_class_for_path(link_path, klass, klass_prefix = nil) ⇒ Object
10 11 12 13 14 15 |
# File 'app/helpers/lcms/engine/view_helper.rb', line 10 def add_class_for_path(link_path, klass, klass_prefix = nil) [ klass_prefix, current_page?(link_path) ? klass : nil ].compact.join(' ') end |
#base64_encoded_asset(path) ⇒ Object
88 89 90 |
# File 'app/helpers/lcms/engine/view_helper.rb', line 88 def base64_encoded_asset(path) AssetHelper.base64_encoded path, cache: ENABLE_BASE64_CACHING end |
#color_code(model, base: false) ⇒ Object
110 111 112 113 114 |
# File 'app/helpers/lcms/engine/view_helper.rb', line 110 def color_code(model, base: false) subject_color_code = model.try(:subject) || 'default' grade_avg = base ? 'base' : model.grades.average "#{subject_color_code}-#{grade_avg}" end |
#flash_to_hash ⇒ Object
29 30 31 32 33 34 35 36 |
# File 'app/helpers/lcms/engine/view_helper.rb', line 29 def flash_to_hash result = { message: nil, message_type: 'alert', status: false } flash.to_hash.slice('notice', 'alert').each do |name, | result = { message: result[:message].present? ? "#{result.message}\n#{message}" : , message_type: name, status: true } end result end |
#header_mod ⇒ Object
38 39 40 |
# File 'app/helpers/lcms/engine/view_helper.rb', line 38 def header_mod controller.controller_name end |
#inlined_asset(path) ⇒ Object
92 93 94 |
# File 'app/helpers/lcms/engine/view_helper.rb', line 92 def inlined_asset(path) AssetHelper.inlined path end |
#lcms_engine_url_helpers ⇒ Object
128 129 130 |
# File 'app/helpers/lcms/engine/view_helper.rb', line 128 def lcms_engine_url_helpers @lcms_engine_url_helpers ||= Lcms::Engine::Engine.routes.url_helpers end |
#nav_link(link_text, link_path, attrs = {}, link_attrs = {}) ⇒ Object
24 25 26 27 |
# File 'app/helpers/lcms/engine/view_helper.rb', line 24 def nav_link(link_text, link_path, attrs = {}, link_attrs = {}) cls = add_class_for_path(link_path, 'active', attrs[:class]) content_tag(:li, attrs.merge(class: cls)) { link_to link_text, link_path, link_attrs } end |
#page_description ⇒ Object
46 47 48 |
# File 'app/helpers/lcms/engine/view_helper.rb', line 46 def page_description page_content_for :description end |
#page_og_image ⇒ Object
50 51 52 53 54 55 56 57 58 |
# File 'app/helpers/lcms/engine/view_helper.rb', line 50 def page_og_image if content_for?(:og_image) page_og_image = content_for(:og_image) else controller = controller_path.tr('/', '.') page_og_image = t("#{controller}.#{action_name}.og_image", default: t('default_og_image')) end page_og_image end |
#page_title ⇒ Object
42 43 44 |
# File 'app/helpers/lcms/engine/view_helper.rb', line 42 def page_title page_content_for :page_title end |
#redirect_meta_tag ⇒ Object
Render meta tag
61 62 63 |
# File 'app/helpers/lcms/engine/view_helper.rb', line 61 def content_for(:redirect_meta_tag) if content_for?(:redirect_meta_tag) end |
#redirect_via_meta_tag(to_url:, delay: 5) ⇒ Object
Use in views as redirection directive
66 67 68 69 70 |
# File 'app/helpers/lcms/engine/view_helper.rb', line 66 def (to_url:, delay: 5) content_for(:redirect_meta_tag) do content_tag(:meta, nil, { content: "#{delay};url=#{to_url}", 'http-equiv' => 'refresh' }, true) end end |
#selected_id?(id) ⇒ Boolean
116 117 118 119 120 121 122 123 124 125 126 |
# File 'app/helpers/lcms/engine/view_helper.rb', line 116 def selected_id?(id) selected_ids = params[:selected_ids] return unless selected_ids.present? case selected_ids when Array then selected_ids.include?(id.to_s) else selected_ids.split(',').include?(id.to_s) end end |
#set_canonical_url(value) ⇒ Object
rubocop:disable Naming/AccessorMethodName
84 85 86 |
# File 'app/helpers/lcms/engine/view_helper.rb', line 84 def set_canonical_url(value) # rubocop:disable Naming/AccessorMethodName content_for(:canonical_url, value) end |
#set_page_description(dsc) ⇒ Object
rubocop:disable Naming/AccessorMethodName
78 79 80 81 82 |
# File 'app/helpers/lcms/engine/view_helper.rb', line 78 def set_page_description(dsc) # rubocop:disable Naming/AccessorMethodName content_for :description do dsc end end |
#set_page_title(title) ⇒ Object
rubocop:disable Naming/AccessorMethodName
72 73 74 75 76 |
# File 'app/helpers/lcms/engine/view_helper.rb', line 72 def set_page_title(title) # rubocop:disable Naming/AccessorMethodName content_for :page_title do title end end |
#set_social_media_sharing(target) ⇒ Object
rubocop:disable Naming/AccessorMethodName
102 103 104 |
# File 'app/helpers/lcms/engine/view_helper.rb', line 102 def (target) # rubocop:disable Naming/AccessorMethodName = SocialMediaPresenter.new(target: target, view: self) end |
#social_media ⇒ Object
106 107 108 |
# File 'app/helpers/lcms/engine/view_helper.rb', line 106 def || SocialMediaPresenter.new(target: nil, view: self) end |
#strip_tags_and_squish(str) ⇒ Object
96 97 98 99 100 |
# File 'app/helpers/lcms/engine/view_helper.rb', line 96 def (str) return unless str.respond_to? :squish (str).squish end |