module KingList # The List Helper aides in lists anddetail views by providing helpers for: # tables, action icons, action buttons and action links, definition list helper module ListHelper # Build a definition list(dl/dt/dd) for a collection # Usage examples: # - dl_for(client) # - dl_for(:client, my_client_object) # === Example haml # - dl_for(current_object) do |f| # - f.show :first_name # - f.show :last_name # # =>
#
Firstname
#
Otto
#
Lastname
#
Bismark
#
# # Parameters are like "form_for" def dl_for(record_or_name, *args) raise ArgumentError, "Missing block" unless block_given? options = args.extract_options! case record_or_name when String, Symbol object_name = record_or_name object = args.first else object = record_or_name object_name = ActionController::RecordIdentifier.singular_class_name(object) end haml_tag :dl, options do yield KingList::Builder::Show.new(object_name, object, @template) end end # Create a section # A section is a group of related object information and # generates a fieldset with optional legend # # === Example haml # - section :caption => _('legend.user.details'), :class => 'my_css_class' do # %p= "This is the content" # # => #
# User Details #

This is the content

#
# def section(options = {}, &block) # Short form of usage if options.is_a?(String) caption = options options = {} end caption ||= options.delete(:caption) @template.haml_tag :fieldset, options do @template.haml_tag :legend, caption unless caption.blank? @template.haml_concat @template.capture_haml(&block) end end # Create a div for form actions def actions(options = {}, &block) @template.haml_tag :div, options.merge(:class => 'form_actions') do @template.haml_concat @template.capture_haml(&block) end end # Build a table-tag for a collection # # Available option keys: # :sorting => Enable/Disable sorting for ALL columns (default is true) # # === Usage example: # # Header linking for all, default # - table_for(@users) do |t, user| # - t.column :name # with sorting # - t.column :email # with sorting # # Header linking for all, but exclude individual columns from sorting: # - table_for(@users)do |t, user| # - t.column :name, :sorting => false # without sorting # - t.column :last_name # with sorting # # NO header linking for all columns: # - table_for(@users, :sorting => false) do |t, user| # - t.column :name # without sorting # - t.column :email # without sorting # # No header linking for all, but allow sorting for individual columns: # - table_for(@users, :sorting => false) do |t, user| # - t.column :name, :sorting => true # with sorting # - t.column :last_name # without sorting # def table_for(collection, options={}, html_options={}, &block) return if collection.nil? || collection.empty? builder = KingList::Builder::Table.new(@template, collection) # extract options builder.sorting = options.delete(:sorting) != false # default => true # First step: Yield the block just for counting the columns builder.mode = :counter builder.start_row(collection.first) yield(builder, builder.current_record) haml_tag :table, { :summary => '' }.merge(html_options) do # Build header row haml_tag :thead do haml_tag :tr do builder.mode = :header builder.start_row(collection.first) yield(builder, builder.current_record) end end # TODO: Build footer here # haml_tag :tfoot do # end haml_tag :tbody do builder.mode = :content # Build content row for each collection item collection.each do |c| tr_options = {} # zebra styling tr_options[:class] = @template.cycle('odd','even') haml_tag :tr, tr_options do builder.start_row(c) yield(builder, builder.current_record) end end end end end # Show a list of options as ul / li list. # Each actions li gets a special class so image replacement can be done via css # ==== Example # - action_group do # = action_icon :edit, edit_object_path(client) # = action_icon :invoice_add, new_client_invoice_path(client), :title => 'New Invoice' # = action_text t(:'web_templates.new'), new_object_path,{},{ :class=>'btn_add'} # #