Class: Tableize::TableBuilder
- Inherits:
-
Object
- Object
- Tableize::TableBuilder
- Defined in:
- lib/tableize/table_builder.rb
Constant Summary collapse
- DEFAULT_OPTIONS =
{ :default_table_class => true, :default_tr_class => true }
Instance Method Summary collapse
- #column(*args, &block) ⇒ Object
- #columns(*args) ⇒ Object
- #defaults ⇒ Object
- #extra(&block) ⇒ Object
-
#initialize(view_context, *args, &block) ⇒ TableBuilder
constructor
A new instance of TableBuilder.
- #render ⇒ Object
Constructor Details
#initialize(view_context, *args, &block) ⇒ TableBuilder
Returns a new instance of TableBuilder.
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/tableize/table_builder.rb', line 11 def initialize(view_context, *args, &block) @options = DEFAULT_OPTIONS.merge(args.) @table_options = @options.delete(:html) || {} @tr_options = @table_options.delete(:tr) || {} @view_context = view_context @block = block @resource_class = get_resource_class(args) @collection = get_collection(args) @columns = [] @extras = [] end |
Instance Method Details
#column(*args, &block) ⇒ Object
35 36 37 |
# File 'lib/tableize/table_builder.rb', line 35 def column(*args, &block) @columns << Tableize::ColumnBuilder.new(@resource_class, *args, &block) end |
#columns(*args) ⇒ Object
29 30 31 32 33 |
# File 'lib/tableize/table_builder.rb', line 29 def columns(*args) args.each do |arg| column(arg) end end |
#defaults ⇒ Object
23 24 25 26 27 |
# File 'lib/tableize/table_builder.rb', line 23 def defaults (@resource_class.new.attributes.keys - @resource_class.protected_attributes.to_a).each do |attribute| column(attribute.to_sym) end end |
#extra(&block) ⇒ Object
39 40 41 |
# File 'lib/tableize/table_builder.rb', line 39 def extra(&block) @extras << block if block_given? end |
#render ⇒ Object
43 44 45 46 47 48 49 |
# File 'lib/tableize/table_builder.rb', line 43 def render @view_context.capture{ @block.call(self) } content_tag(:table, ) do [thead, tbody].join.html_safe end end |