Class: Aerogel::Admin::TableBuilder
- Inherits:
-
Render::BlockHelper
- Object
- Render::BlockHelper
- Aerogel::Admin::TableBuilder
- Defined in:
- lib/aerogel/admin/table_builder.rb
Overview
TableBuilder constructs and displays a table populated with data obtained from passed object.
Example:
table User.all do
column :full_name
column :roles
end
Defined Under Namespace
Classes: Column
Constant Summary collapse
- DEFAULT_OPTIONS =
{ class: 'table-striped', style: 'standard', html_params: {} }
Instance Attribute Summary collapse
-
#columns ⇒ Object
Returns the value of attribute columns.
-
#object ⇒ Object
Returns the value of attribute object.
-
#options ⇒ Object
Returns the value of attribute options.
-
#style ⇒ Object
Returns the value of attribute style.
Instance Method Summary collapse
- #column(*args, &block) ⇒ Object
-
#html_params ⇒ Object
Renders html params for <table …>.
-
#initialize(object, options = {}, &block) ⇒ TableBuilder
constructor
A new instance of TableBuilder.
- #template(name) ⇒ Object
- #wrap(content) ⇒ Object
Constructor Details
#initialize(object, options = {}, &block) ⇒ TableBuilder
Returns a new instance of TableBuilder.
22 23 24 25 26 27 28 |
# File 'lib/aerogel/admin/table_builder.rb', line 22 def initialize( object, = {}, &block ) super( &block ) self.object = object self. = DEFAULT_OPTIONS.deep_merge( ) self.style = self.[:style] self.columns = [] end |
Instance Attribute Details
#columns ⇒ Object
Returns the value of attribute columns.
14 15 16 |
# File 'lib/aerogel/admin/table_builder.rb', line 14 def columns @columns end |
#object ⇒ Object
Returns the value of attribute object.
14 15 16 |
# File 'lib/aerogel/admin/table_builder.rb', line 14 def object @object end |
#options ⇒ Object
Returns the value of attribute options.
14 15 16 |
# File 'lib/aerogel/admin/table_builder.rb', line 14 def @options end |
#style ⇒ Object
Returns the value of attribute style.
14 15 16 |
# File 'lib/aerogel/admin/table_builder.rb', line 14 def style @style end |
Instance Method Details
#column(*args, &block) ⇒ Object
30 31 32 33 |
# File 'lib/aerogel/admin/table_builder.rb', line 30 def column( *args, &block ) self.columns << Column.new( self, *args, &block ) nil end |
#html_params ⇒ Object
Renders html params for <table …>
45 46 47 48 49 50 51 |
# File 'lib/aerogel/admin/table_builder.rb', line 45 def html_params attrs = @options[:html_params].dup attrs.merge!({ # :action => @options[:action] }) attrs.map{|n, v| v.nil? ? "#{n}" : "#{n}=\"#{v}\""}.join(" ") end |
#template(name) ⇒ Object
35 36 37 |
# File 'lib/aerogel/admin/table_builder.rb', line 35 def template( name ) "admin/table_builder/#{style}/#{name}".to_sym end |
#wrap(content) ⇒ Object
39 40 41 |
# File 'lib/aerogel/admin/table_builder.rb', line 39 def wrap( content ) erb template("table.html"), locals: { table: self }, layout: false end |