Module: Lcms::Engine::ViewHelper
- Included in:
- Admin::ResourcesController, ApplicationHelper
- Defined in:
- app/helpers/lcms/engine/view_helper.rb
Overview
rubocop:disable Metrics/ModuleLength
Constant Summary collapse
- ENABLE_BASE64_CACHING =
ActiveRecord::Type::Boolean.new.cast 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.
- #strip_tags_and_squish(str) ⇒ Object
Instance Method Details
#add_class_for_action(controller_name, action_name, klass, klass_prefix = nil) ⇒ Object
15 16 17 18 19 20 |
# File 'app/helpers/lcms/engine/view_helper.rb', line 15 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
8 9 10 11 12 13 |
# File 'app/helpers/lcms/engine/view_helper.rb', line 8 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
86 87 88 |
# File 'app/helpers/lcms/engine/view_helper.rb', line 86 def base64_encoded_asset(path) AssetHelper.base64_encoded path, cache: ENABLE_BASE64_CACHING end |
#color_code(model, base: false) ⇒ Object
100 101 102 103 104 |
# File 'app/helpers/lcms/engine/view_helper.rb', line 100 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
27 28 29 30 31 32 33 34 |
# File 'app/helpers/lcms/engine/view_helper.rb', line 27 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.}\n#{}" : , message_type: name, status: true } end result end |
#header_mod ⇒ Object
36 37 38 |
# File 'app/helpers/lcms/engine/view_helper.rb', line 36 def header_mod controller.controller_name end |
#inlined_asset(path) ⇒ Object
90 91 92 |
# File 'app/helpers/lcms/engine/view_helper.rb', line 90 def inlined_asset(path) AssetHelper.inlined path end |
#lcms_engine_url_helpers ⇒ Object
118 119 120 |
# File 'app/helpers/lcms/engine/view_helper.rb', line 118 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
22 23 24 25 |
# File 'app/helpers/lcms/engine/view_helper.rb', line 22 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
44 45 46 |
# File 'app/helpers/lcms/engine/view_helper.rb', line 44 def page_description page_content_for :description end |
#page_og_image ⇒ Object
48 49 50 51 52 53 54 55 56 |
# File 'app/helpers/lcms/engine/view_helper.rb', line 48 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
40 41 42 |
# File 'app/helpers/lcms/engine/view_helper.rb', line 40 def page_title page_content_for :page_title end |
#redirect_meta_tag ⇒ Object
Render meta tag
59 60 61 |
# File 'app/helpers/lcms/engine/view_helper.rb', line 59 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
64 65 66 67 68 |
# File 'app/helpers/lcms/engine/view_helper.rb', line 64 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
106 107 108 109 110 111 112 113 114 115 116 |
# File 'app/helpers/lcms/engine/view_helper.rb', line 106 def selected_id?(id) selected_ids = params[:selected_ids] return unless selected_ids.present? case selected_ids when Array 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
82 83 84 |
# File 'app/helpers/lcms/engine/view_helper.rb', line 82 def set_canonical_url(value) # rubocop:disable Naming/AccessorMethodName content_for(:canonical_url, value) end |
#set_page_description(dsc) ⇒ Object
rubocop:disable Naming/AccessorMethodName
76 77 78 79 80 |
# File 'app/helpers/lcms/engine/view_helper.rb', line 76 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
70 71 72 73 74 |
# File 'app/helpers/lcms/engine/view_helper.rb', line 70 def set_page_title(title) # rubocop:disable Naming/AccessorMethodName content_for :page_title do title end end |
#strip_tags_and_squish(str) ⇒ Object
94 95 96 97 98 |
# File 'app/helpers/lcms/engine/view_helper.rb', line 94 def (str) return unless str.respond_to? :squish (str).squish end |