Module: Listalicious::SemanticListHelper

Defined in:
lib/listalicious.rb

Overview

Semantic list helper methods

Example Usage:

Constant Summary collapse

@@builder =
::Listalicious::TableBuilder

Instance Method Summary collapse

Instance Method Details

#add_class(classnames, classname) ⇒ Object



37
38
39
40
# File 'lib/listalicious.rb', line 37

def add_class(classnames, classname)
  out = (classnames.is_a?(String) ? classnames.split(' ') : []) << classname
  out.join(' ')
end

#semantic_list_for(collection, options, &proc) ⇒ Object

Raises:

  • (ArgumentError)


16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/listalicious.rb', line 16

def semantic_list_for(collection, options, &proc)
  raise ArgumentError, "Missing block" unless block_given?

  # TODO: should :as be required?

  options[:html] ||= {}
  options[:html][:class] = add_class(options[:html][:class], 'semantic-list')
  options[:html][:id] ||= "#{options[:as] || collection.first ? collection.first.class.name.underscore : 'semantic'}_list"

  if options[:sort_url]
    options[:html][:class] = add_class(options[:html][:class], 'sortable')
    options[:html]['data-sorturl'] = url_for(options[:sort_url])
  end

  options[:html][:class] = add_class(options[:html][:class], 'selectable') if options[:selectable]
  options[:html][:class] = add_class(options[:html][:class], 'expandable') if options[:expandable]

  builder = options[:builder] || TableBuilder
  builder.new(@template, collection, options, &proc)
end