Module: Cheveret::Table::Rendering
- Included in:
- Base
- Defined in:
- lib/cheveret/table/rendering.rb
Defined Under Namespace
Modules: ClassMethods
Instance Attribute Summary collapse
-
#template ⇒ Object
Returns the value of attribute template.
Class Method Summary collapse
Instance Method Summary collapse
- #render(*args, &block) ⇒ Object
- #render_rows(options = {}) ⇒ Object
- #render_table(options = {}) ⇒ Object
- #render_tbody(options = {}) ⇒ Object
- #render_td(column, options = {}) ⇒ Object
-
#render_th(column, options = {}) ⇒ Object
generates a <th> tag for the specified column using the configured builder.
- #render_thead(options = {}) ⇒ Object
Instance Attribute Details
#template ⇒ Object
Returns the value of attribute template.
34 35 36 |
# File 'lib/cheveret/table/rendering.rb', line 34 def template @template end |
Class Method Details
.included(base) ⇒ Object
28 29 30 31 32 |
# File 'lib/cheveret/table/rendering.rb', line 28 def self.included(base) base.module_eval do extend ClassMethods end end |
Instance Method Details
#render(*args, &block) ⇒ Object
112 113 114 115 116 117 118 |
# File 'lib/cheveret/table/rendering.rb', line 112 def render(*args, &block) if args.empty? && block_given? template.instance_eval(&block) else template.render(*args, &block) end end |
#render_rows(options = {}) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/cheveret/table/rendering.rb', line 71 def render_rows(={}) template.reset_cycle('cheveret') collection.map do |item| cycle = template.cycle('', 'alt', :name => 'cheveret') tr_tag(:class => cycle) do columns.values.map do |column| render_td(column) { table_data(column, item) } end end end.join("\n") end |
#render_table(options = {}) ⇒ Object
42 43 44 45 46 |
# File 'lib/cheveret/table/rendering.rb', line 42 def render_table(={}) table_tag() do render_thead << render_tbody end end |
#render_tbody(options = {}) ⇒ Object
64 65 66 |
# File 'lib/cheveret/table/rendering.rb', line 64 def render_tbody(={}) tbody_tag() { render_rows } end |
#render_td(column, options = {}) ⇒ Object
102 103 104 105 106 107 |
# File 'lib/cheveret/table/rendering.rb', line 102 def render_td(column, ={}) .reverse_merge!(column.td_html) if column.td_html [:class] = [ column.name, *[:class] ].flatten.join(' ').strip td_tag() { yield } end |
#render_th(column, options = {}) ⇒ Object
generates a <th> tag for the specified column using the configured builder
88 89 90 91 92 93 94 95 96 97 |
# File 'lib/cheveret/table/rendering.rb', line 88 def render_th(column, ={}) .reverse_merge!(column.th_html) if column.th_html # phwarrrgg! [:class] = ([ column.name, [:class], column.th_html ? column.th_html[:class] : nil ]).flatten.join(' ').strip th_tag() { yield } end |
#render_thead(options = {}) ⇒ Object
51 52 53 54 55 56 57 58 59 |
# File 'lib/cheveret/table/rendering.rb', line 51 def render_thead(={}) thead_tag() do tr_tag do columns.values.map do |column| render_th(column) { table_header(column) } end end end end |