Module: CoreHelper
- Defined in:
- app/helpers/core_helper.rb
Overview
helpers for core views
Instance Method Summary collapse
-
#breadcrumbs(&block) ⇒ Object
Set the bread crumbs for navigation.
- #class_action_path(action, query = nil) ⇒ Object
- #edit_model_path(model) ⇒ Object
-
#flash_map_name(key) ⇒ Object
Map alerts to a valid icon.
- #index_path ⇒ Object
-
#mask_system_configuration(field) ⇒ Object
Pull the value from system configuration and mask the ones that match the given strings.
-
#mask_value(value, default: '************') ⇒ Object
Mask a value, i.e.
- #model_action_path(model, action, query = nil) ⇒ Object
- #model_path(model) ⇒ Object
-
#search_url(search_url) ⇒ Object
Record the search url if one is needed.
-
#title(page_title) ⇒ Object
Set the title for the page.
Instance Method Details
#breadcrumbs(&block) ⇒ Object
Set the bread crumbs for navigation
24 25 26 |
# File 'app/helpers/core_helper.rb', line 24 def (&block) content_for(:breadcrumb_content) { block } end |
#class_action_path(action, query = nil) ⇒ Object
87 88 89 |
# File 'app/helpers/core_helper.rb', line 87 def class_action_path(action, query = nil) [[index_path, action].join('/'), query&.to_query].compact.join('?') end |
#edit_model_path(model) ⇒ Object
91 92 93 |
# File 'app/helpers/core_helper.rb', line 91 def edit_model_path(model) model_action_path(model, :edit) end |
#flash_map_name(key) ⇒ Object
Map alerts to a valid icon
31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'app/helpers/core_helper.rb', line 31 def flash_map_name(key) case key when 'alert' 'notification_important' when 'success' 'check_circle' when 'notice' 'note' else key end end |
#index_path ⇒ Object
75 76 77 |
# File 'app/helpers/core_helper.rb', line 75 def index_path "/#{controller_path}" end |
#mask_system_configuration(field) ⇒ Object
Pull the value from system configuration and mask the ones that match the given strings
47 48 49 50 51 52 53 54 |
# File 'app/helpers/core_helper.rb', line 47 def mask_system_configuration(field) should_mask = false %w[password token secret access_key api_key].each do |mask| should_mask |= field.include?(mask) end value = SystemConfiguration.send(field) should_mask ? mask_value(value, default: 'Not Set') : value end |
#mask_value(value, default: '************') ⇒ Object
Mask a value, i.e. password field
-
If blank or nil, return the default
-
Length of 1-4 only show the first character
-
Length 5-10 only show the first and last character
-
Otherwise show the first and last three characters
62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'app/helpers/core_helper.rb', line 62 def mask_value(value, default: '************') return default if value.blank? case value.length when 1..4 "#{value.first}***********" when 5..10 "#{value.first}**********#{value.last}" else "#{value[0..2]}**********#{value[-3..-1]}" end end |
#model_action_path(model, action, query = nil) ⇒ Object
83 84 85 |
# File 'app/helpers/core_helper.rb', line 83 def model_action_path(model, action, query = nil) [[model_path(model), action].join('/'), query&.to_query].compact.join('?') end |
#model_path(model) ⇒ Object
79 80 81 |
# File 'app/helpers/core_helper.rb', line 79 def model_path(model) [index_path, model.id.to_s].join('/') end |
#search_url(search_url) ⇒ Object
Record the search url if one is needed
17 18 19 |
# File 'app/helpers/core_helper.rb', line 17 def search_url(search_url) content_for(:search_url) { search_url } end |
#title(page_title) ⇒ Object
Set the title for the page
10 11 12 |
# File 'app/helpers/core_helper.rb', line 10 def title(page_title) content_for(:title) { page_title } end |