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
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, , &proc) raise ArgumentError, "Missing block" unless block_given? # TODO: should :as be required? [:html] ||= {} [:html][:class] = add_class([:html][:class], 'semantic-list') [:html][:id] ||= "#{[:as] || collection.first ? collection.first.class.name.underscore : 'semantic'}_list" if [:sort_url] [:html][:class] = add_class([:html][:class], 'sortable') [:html]['data-sorturl'] = url_for([:sort_url]) end [:html][:class] = add_class([:html][:class], 'selectable') if [:selectable] [:html][:class] = add_class([:html][:class], 'expandable') if [:expandable] builder = [:builder] || TableBuilder builder.new(@template, collection, , &proc) end |