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

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_classString

Generate body class from the following sources:

  • ‘:action` parameter

  • converted current resources name (e.g. ‘order__item` from `Order::Item`)

  • ‘:custom_body_class` content

Returns:

  • (String)

    css classes for body tag



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.

Parameters:

  • classes (Array<Class>) (defaults to: wallaby_controller.all_models)

Returns:



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.

Parameters:

  • array (Array<Node>)

    root classes

Returns:

  • (String)

    HTML for the whole 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?

  options = { html_options: { class: 'dropdown-item' } }
   :ul, class: 'dropdown-menu', 'aria-labelledby': base_class do
    array.sort_by(&:name).each do |node|
      content = index_link(node.klass, **options).try :<<, model_tree(node.children)
      concat (:li, content)
    end
  end
end

#to_model_label(model_class) ⇒ String

Returns label for given model class.

Returns:

  • (String)

    label for given model class

See Also:



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.

Returns:

  • (String)

    resources name for given model class

See Also:



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