Class: TableHelper::TableBuilder
- Inherits:
-
Object
- Object
- TableHelper::TableBuilder
show all
- Defined in:
- lib/table_builder/table_builder.rb
Instance Method Summary
collapse
Constructor Details
#initialize(objects, template, options) ⇒ TableBuilder
Returns a new instance of TableBuilder.
10
11
12
13
|
# File 'lib/table_builder/table_builder.rb', line 10
def initialize objects, template, options
raise ArgumentError, "TableBuilder expects an Array or ActiveRecord::NamedScope::Scope but found a #{objects.class}" unless Array === objects or ActiveRecord::NamedScope::Scope === objects
@objects, @template, @options = objects, template, options
end
|
Instance Method Details
#body(options = {}) ⇒ Object
15
16
17
|
# File 'lib/table_builder/table_builder.rb', line 15
def body options = {}
concat content_tag(:tbody, @objects.map{ |o| capture {yield o} }, options)
end
|
#body_r(options = {}) ⇒ Object
19
20
21
|
# File 'lib/table_builder/table_builder.rb', line 19
def body_r options = {}
concat content_tag(:tbody, @objects.map{ |o| r capture {yield o}, options })
end
|
#d(*args, &block) ⇒ Object
42
43
44
|
# File 'lib/table_builder/table_builder.rb', line 42
def d *args, &block
tag :td, *args, &block
end
|
#h(*args, &block) ⇒ Object
38
39
40
|
# File 'lib/table_builder/table_builder.rb', line 38
def h *args, &block
tag :th, *args, &block
end
|
#head(*args, &block) ⇒ Object
23
24
25
26
27
28
|
# File 'lib/table_builder/table_builder.rb', line 23
def head *args, &block
return tag(:thead, *args, &block) if block_given?
options = args.
content = (args.size == 1 ? args.first : args).map{|c|"<th>#{c}</th>"}
content_tag :thead, r(content), options
end
|
#head_r(*args, &block) ⇒ Object
30
31
32
|
# File 'lib/table_builder/table_builder.rb', line 30
def head_r *args, &block
head { tag :tr, *args, &block }
end
|
#r(*args, &block) ⇒ Object
34
35
36
|
# File 'lib/table_builder/table_builder.rb', line 34
def r *args, &block
tag :tr, *args, &block
end
|