Module: ListHelper

Defined in:
app/helpers/list_helper.rb

Instance Method Summary collapse

Instance Method Details



19
20
21
22
23
24
# File 'app/helpers/list_helper.rb', line 19

def link_to_list_item(*args, &block)
  options = combine_options(args.extract_options!, class: 'list-item')
  (:li) do
    link_to(*args, options, &block)
  end
end

#list(options = {}) ⇒ Object



2
3
4
# File 'app/helpers/list_helper.rb', line 2

def list(options = {})
  component(defaults: { class: 'list' }, options: options) { yield }
end

#list_item(options = {}) ⇒ Object



6
7
8
9
10
11
12
13
# File 'app/helpers/list_helper.rb', line 6

def list_item(options = {})
  options = combine_options(options, class: 'list-item')
  label = options.delete(:label)
  value = options.delete(:value)
  component(defaults: { class: 'list-item' }) do
    (list_item_label(label) + list_item_value(value) + (block_given? ? yield : "")).html_safe
  end
end

#list_item_label(label = nil) ⇒ Object



26
27
28
29
# File 'app/helpers/list_helper.rb', line 26

def list_item_label(label = nil)
  return '' unless label.present? || block_given?
  (:span, class: 'list-item-label') { block_given? ? yield : label }
end

#list_item_value(value = nil) ⇒ Object



31
32
33
34
# File 'app/helpers/list_helper.rb', line 31

def list_item_value(value = nil)
  return '' unless value.present? || block_given?
  (:span, class: 'list-item-value') { block_given? ? yield : value }
end

#list_of(items, options = {}, &block) ⇒ Object



15
16
17
# File 'app/helpers/list_helper.rb', line 15

def list_of(items, options = {}, &block)
  list(options) { component_items(items, defaults: { class: 'list-item' }, &block) }
end