Module: Wallaby::BaseHelper

Includes:
LinksHelper, StylingHelper
Defined in:
lib/helpers/wallaby/base_helper.rb

Overview

NOTE: Global helper methods should go in here

Instance Method Summary collapse

Methods included from LinksHelper

#cancel_link, #delete_link, #edit_link, #edit_path, #index_link, #index_params, #index_path, #new_link, #new_path, #show_link, #show_path

Methods included from StylingHelper

#fa_icon, #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



24
25
26
27
28
29
30
# File 'lib/helpers/wallaby/base_helper.rb', line 24

def body_class
  [
    params[:action],
    current_resources_name.try(:gsub, COLONS, '__'),
    content_for(:custom_body_class)
  ].compact.join SPACE
end

#model_classes(classes = Map.model_classes) ⇒ Array<Wallaby::Node>

Turn a list of classes into tree structure by inheritance.

Parameters:

  • classes (Array<Class>) (defaults to: Map.model_classes)

    a list of all the classes that wallaby supports

Returns:



36
37
38
39
40
41
42
43
44
45
# File 'lib/helpers/wallaby/base_helper.rb', line 36

def model_classes(classes = Map.model_classes)
  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) ⇒ String

Turn the tree of classes into a nested ‘ul` list.

Parameters:

Returns:

  • (String)

    HTML for the whole tree



50
51
52
53
54
55
56
57
58
# File 'lib/helpers/wallaby/base_helper.rb', line 50

def model_tree(array)
  return EMPTY_STRING.html_safe if array.blank?
   :ul, class: 'dropdown-menu' do
    array.sort_by(&:name).each do |node|
      content = index_link(node.klass).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:



9
10
11
# File 'lib/helpers/wallaby/base_helper.rb', line 9

def to_model_label(model_class)
  Utils.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:



15
16
17
# File 'lib/helpers/wallaby/base_helper.rb', line 15

def to_resources_name(model_class)
  Map.resources_name_map model_class
end