Class: ExpressTemplates::Components::TableFor
- Includes:
- Capabilities::Building, Capabilities::Configurable
- Defined in:
- lib/express_templates/components/table_for.rb
Overview
Create an html table from a collection of data.
Typically this will be a collection of models of the same type. Each member of the collection must respond to the column names provided.
Example:
“‘ruby table_for(:people) do |t|
t.column :name
t.column :email
t.column :phone
end “‘
This assumes that a @people variable will exist in the view and that it will be a collection whose members respond to :name, :email, and :phone
This will result in markup like the following:
<table id="people">
<thead>
<tr>
<th class="name">Name</th>
<th class="email">Email</th>
<th class="phone">Phone</th>
</tr>
</thead>
<tbody>
<tr id="person-1">
<td class="name">Steven Talcott Smith</td>
<td class="email">[email protected]</td>
<td class="phone">415-555-1212</td>
</tr>
</tbody>
</table>
Defined Under Namespace
Classes: Column
Instance Attribute Summary collapse
-
#columns ⇒ Object
readonly
Returns the value of attribute columns.
Attributes inherited from Expander
Instance Method Summary collapse
- #column(name, options = {}) ⇒ Object
- #compile ⇒ Object
-
#initialize(*args) {|_self| ... } ⇒ TableFor
constructor
A new instance of TableFor.
- #wrap_for_stack_trace(body) ⇒ Object
Methods included from Capabilities::Configurable
Methods inherited from Base
Methods included from Capabilities::Iterating
Methods included from Capabilities::Wrapping
Methods included from Capabilities::Rendering
Methods included from Capabilities::Templating
Methods included from Macro
Methods inherited from Expander
#expand, #initialize_expander, #method_missing, #process_children!, register_macros_for
Constructor Details
#initialize(*args) {|_self| ... } ⇒ TableFor
Returns a new instance of TableFor.
46 47 48 49 50 |
# File 'lib/express_templates/components/table_for.rb', line 46 def initialize(*args) super(*args) _process_args!(args) # from Configurable yield(self) if block_given? end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class ExpressTemplates::Expander
Instance Attribute Details
#columns ⇒ Object (readonly)
Returns the value of attribute columns.
52 53 54 |
# File 'lib/express_templates/components/table_for.rb', line 52 def columns @columns end |
Instance Method Details
#column(name, options = {}) ⇒ Object
54 55 56 57 |
# File 'lib/express_templates/components/table_for.rb', line 54 def column(name, = {}) @columns ||= [] @columns << Column.new(name, ) end |
#compile ⇒ Object
91 92 93 |
# File 'lib/express_templates/components/table_for.rb', line 91 def compile wrap_for_stack_trace(lookup(:markup)) end |
#wrap_for_stack_trace(body) ⇒ Object
87 88 89 |
# File 'lib/express_templates/components/table_for.rb', line 87 def wrap_for_stack_trace(body) "ExpressTemplates::Components::TableFor.render_in(self) {\n#{body}\n}" end |