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

Raises:

  • (ArgumentError)


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, 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].to_s

  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