Module: Wallaby::BaseHelper
- Includes:
- LinksHelper, StylingHelper
- Included in:
- ResourcesHelper
- Defined in:
- lib/helpers/wallaby/base_helper.rb
Overview
Some basic helper methods
Constant Summary
Constants included from StylingHelper
StylingHelper::FONT_AWESOME_MAPPING
Instance Method Summary collapse
-
#body_class ⇒ String
Generate body class from the following sources:.
-
#model_classes(classes = wallaby_controller.all_models) ⇒ Array<Node>
Turn a list of model classes into an inheritance tree.
-
#model_tree(array, base_class = nil) ⇒ String
Render the HTML for the given model class tree.
-
#to_model_label(model_class) ⇒ String
Label for given model class.
-
#to_resources_name(model_class) ⇒ String
Resources name for given model class.
Methods included from LinksHelper
#cancel_link, #delete_link, #edit_link, #index_link, #new_link, #show_link
Methods included from StylingHelper
#fa_icon, #fa_map, #html_classes, #imodal, #itooltip, #muted, #na, #null
Instance Method Details
#body_class ⇒ String
Generate body class from the following sources:
-
‘:action` parameter
-
converted current resources name (e.g. ‘order__item` from `Order::Item`)
-
‘:custom_body_class` content
27 28 29 30 31 32 33 34 |
# File 'lib/helpers/wallaby/base_helper.rb', line 27 def body_class [ params[:action], controller_path.gsub(SLASH, '__'), current_resources_name.try(:gsub, COLONS, '__'), content_for(:custom_body_class) ].compact.join SPACE end |
#model_classes(classes = wallaby_controller.all_models) ⇒ Array<Node>
Turn a list of model classes into an inheritance tree.
39 40 41 42 43 44 45 46 47 48 |
# File 'lib/helpers/wallaby/base_helper.rb', line 39 def model_classes(classes = wallaby_controller.all_models) nested_hash = classes.each_with_object({}) do |klass, hash| hash[klass] = Node.new(klass) end nested_hash.each do |klass, node| node.parent = parent = nested_hash[klass.superclass] parent.children << node if parent end nested_hash.values.select { |v| v.parent.nil? } end |
#model_tree(array, base_class = nil) ⇒ String
Render the HTML for the given model class tree.
53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/helpers/wallaby/base_helper.rb', line 53 def model_tree(array, base_class = nil) return EMPTY_STRING if array.blank? || current_engine_name.blank? = { html_options: { class: 'dropdown-item' } } content_tag :ul, class: 'dropdown-menu', 'aria-labelledby': base_class do array.sort_by(&:name).each do |node| content = index_link(node.klass, **).try :<<, model_tree(node.children) concat content_tag(:li, content) end end end |
#to_model_label(model_class) ⇒ String
Returns label for given model class.
11 12 13 |
# File 'lib/helpers/wallaby/base_helper.rb', line 11 def to_model_label(model_class) Inflector.to_model_label(model_class) end |
#to_resources_name(model_class) ⇒ String
Returns resources name for given model class.
17 18 19 |
# File 'lib/helpers/wallaby/base_helper.rb', line 17 def to_resources_name(model_class) Map.resources_name_map model_class end |