Module: ComponentHelper

Included in:
ScavengerHunt::ApplicationHelper
Defined in:
app/helpers/component_helper.rb

Instance Method Summary collapse

Instance Method Details

#component(defaults: {}, options: {}, tag: :ul) ⇒ Object

Builds an HTML tag (`tag` parameter) that includes an optional screen reader title and deep-merges options.



4
5
6
7
8
# File 'app/helpers/component_helper.rb', line 4

def component(defaults: {}, options: {}, tag: :ul)
  tag = options.delete(:tag) || tag
  options = combine_options(options, defaults) unless defaults.empty?
  title_for(options) + (tag, options) { yield }
end

#component_items(items, defaults: {}, options: {}, tag: :li) ⇒ Object

Iterate through a passed-in collection of items, yielding each to an iterator block, and combining them into a content block. Used internally for building helpers like `list_of` or `segmented_control_for`.



13
14
15
16
17
# File 'app/helpers/component_helper.rb', line 13

def component_items(items, defaults: {}, options: {}, tag: :li)
  items.map { |item|
    component(defaults: defaults, options: options, tag: tag) { yield item }
  }.join.html_safe
end