Module: Listalicious::SemanticListHelper
- Defined in:
- lib/listalicious.rb
Overview
Semantic list helper methods
Example Usage (HAML)
-
semantic_list_for @users, :as => :user, :html => => ‘user-list’ do |l|
l.columns [:head, :body] do |user, index|
l.column “#useruser.first_name #useruser.last_name”, :title => ‘User Name’, :sort => ‘first_name’, :width => ‘20%’
l.column :login, :width => ‘20%’
l.column link_to(user.email, “mailto:#useruser.email”), :title => ‘Email Address’, :sort => ‘email’, :width => ‘40%’
l.controls do
= link_to('edit', edit_user_path(user))
Constant Summary collapse
- @@builder =
::Listalicious::TableBuilder
Instance Method Summary collapse
Instance Method Details
#add_class(classnames, classname) ⇒ Object
44 45 46 47 |
# File 'lib/listalicious.rb', line 44 def add_class(classnames, classname) out = (classnames.is_a?(String) ? classnames.split(' ') : []) << classname out.join(' ') end |
#semantic_list_for(collection, options, &proc) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/listalicious.rb', line 23 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].to_s 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 |