Class: SuperTable::Builder
- Inherits:
-
Object
- Object
- SuperTable::Builder
show all
- Includes:
- ViewHelpers
- Defined in:
- lib/super_table/builder.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
#del, #div, included, #small, #span, #strong, #td, #th, #tr
Constructor Details
#initialize(table, view_context) ⇒ Builder
Returns a new instance of Builder.
11
12
13
14
|
# File 'lib/super_table/builder.rb', line 11
def initialize(table, view_context)
self.view_context = view_context
self.table = table
end
|
Instance Attribute Details
#table ⇒ Object
Returns the value of attribute table.
6
7
8
|
# File 'lib/super_table/builder.rb', line 6
def table
@table
end
|
#view_context ⇒ Object
Returns the value of attribute view_context.
6
7
8
|
# File 'lib/super_table/builder.rb', line 6
def view_context
@view_context
end
|
Instance Method Details
#column(key = nil, options = {}, &block) ⇒ Object
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
# File 'lib/super_table/builder.rb', line 84
def column(key=nil, options={}, &block)
if block_given?
options = key
return td(options, &block)
end
content = case key
when Symbol
@rows.last.send(key)
else
key
end
td(content, options)
end
|
#columns(*args, &block) ⇒ Object
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
# File 'lib/super_table/builder.rb', line 61
def columns(*args, &block)
@rows = []
options = args.
wrap_options = options.delete(:wrap) || {}
if collection.empty?
return placeholder_row
end
collection.each do |record|
@rows << record
html = wrap_tr(options, wrap_options) do
if block_given?
yield record
else
args.each do |key|
concat td(record.send(key))
end
end
end
concat html
end
nil
end
|
#head(key = nil, options = {}, &block) ⇒ Object
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
# File 'lib/super_table/builder.rb', line 34
def head(key=nil, options={}, &block)
if block_given?
options = key
return th(options, &block)
end
case key
when Symbol
column_options = table.columns[key].clone
title, desc = column_options.delete(:title), column_options.delete(:desc)
else
column_options = {}
title = key
end
classes = []
classes << options.delete(:class) if options[:class]
classes << column_options.delete(:class) if column_options[:class]
column_options.merge!(options)
column_options.merge!(class: classes.join(" ")) if classes.present?
th(column_options) do
concat(title)
concat content_tag(:div, desc, class: 'small text-primary') if desc
end
end
|
#heads(*args, &block) ⇒ Object
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/super_table/builder.rb', line 16
def heads(*args, &block)
options = args.
classes = ['table-secondary']
classes << options[:class] if options[:class]
options[:class] = classes.join(" ")
if block_given?
tr(options, &block)
else
tr(options) do
args.each do |key|
concat head(key)
end
end
end
end
|
#placeholder_row ⇒ Object
99
100
101
102
103
104
|
# File 'lib/super_table/builder.rb', line 99
def placeholder_row
tr do
content = table.placeholder || "尚無資料"
td(content, colspan: table.columns.length, class: 'text-center')
end
end
|