Sha256: 5d1513188c9631606111b5e5e46a41f3e04d7bc70183bce587e339635b7845d1
Contents?: true
Size: 1.83 KB
Versions: 4
Compression:
Stored size: 1.83 KB
Contents
module DiningTable class Table attr_accessor :collection, :presenter, :options, :index, :columns, :action_columns, :view_context attr_accessor :no_header, :no_footer private :no_header, :no_footer, :no_header=, :no_footer= def initialize( collection, view_context, options = {} ) self.collection = collection self.view_context = view_context self.index = 0 self.columns = [ ] self.options = options initialize_presenter( options ) define end def define raise NotImplementedError end def render presenter.start_table presenter.render_header unless no_header presenter.start_body collection.each_with_index do |object, index_| self.index = index_ presenter.render_row( object ) end presenter.end_body presenter.render_footer unless no_footer presenter.end_table presenter.output end def helpers view_context end alias_method :h, :helpers def skip_header self.no_header = true end def skip_footer self.no_footer = true end def object_class options[:class] end private # auxiliary function def column(name, options = {}, &block) klass = options[:class] klass ||= Columns::Column self.columns << klass.new(self, name, options, &block) end def actions(options = {}, &block) column(:actions__, { :class => Columns::ActionsColumn }.merge( options ), &block ) end def initialize_presenter( options ) self.presenter = options[ :presenter ] self.presenter ||= default_presenter.new self.presenter.connect_to( self ) end def default_presenter Presenters::HTMLPresenter end end end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
dining-table-1.1.3 | lib/dining-table/table.rb |
dining-table-1.1.2 | lib/dining-table/table.rb |
dining-table-1.1.1 | lib/dining-table/table.rb |
dining-table-1.1.0 | lib/dining-table/table.rb |