tableficate 0.2.1 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.markdown +6 -4
- data/app/views/tableficate/_data.html.erb +7 -1
- data/app/views/tableficate/_header.html.erb +2 -2
- data/app/views/tableficate/_table.html.erb +16 -23
- data/app/views/tableficate/_table_for.html.erb +9 -0
- data/app/views/tableficate/filters/_check_box_choice.html.erb +3 -0
- data/app/views/tableficate/filters/_form.html.erb +16 -0
- data/app/views/tableficate/filters/_radio_choice.html.erb +3 -0
- data/changelog.markdown +17 -0
- data/lib/generators/tableficate/theme/theme_generator.rb +17 -1
- data/lib/tableficate.rb +3 -0
- data/lib/tableficate/action_column.rb +2 -2
- data/lib/tableficate/caption.rb +29 -0
- data/lib/tableficate/column.rb +13 -7
- data/lib/tableficate/empty.rb +34 -0
- data/lib/tableficate/filters/base.rb +7 -5
- data/lib/tableficate/filters/check_box.rb +1 -1
- data/lib/tableficate/filters/choice.rb +2 -2
- data/lib/tableficate/filters/collection_base.rb +13 -0
- data/lib/tableficate/filters/input.rb +2 -2
- data/lib/tableficate/filters/input_range.rb +6 -6
- data/lib/tableficate/filters/radio.rb +1 -1
- data/lib/tableficate/filters/select.rb +1 -1
- data/lib/tableficate/filters/select_range.rb +4 -4
- data/lib/tableficate/finder.rb +70 -28
- data/lib/tableficate/helper.rb +44 -47
- data/lib/tableficate/table.rb +64 -24
- data/lib/tableficate/utils.rb +27 -2
- data/lib/tableficate/version.rb +1 -1
- data/spec/action_column_spec.rb +9 -1
- data/spec/base_spec.rb +10 -0
- data/spec/caption_spec.rb +33 -0
- data/spec/column_spec.rb +29 -0
- data/spec/empty_spec.rb +45 -0
- data/spec/filters/base_spec.rb +6 -5
- data/spec/filters/choice_spec.rb +5 -2
- data/spec/filters/collection_spec.rb +4 -4
- data/spec/filters/input_range_spec.rb +10 -8
- data/spec/filters/select_range_spec.rb +79 -0
- data/spec/finder_spec.rb +48 -1
- data/spec/generators/tableficate_theme_spec.rb +14 -0
- data/spec/table_spec.rb +114 -3
- data/spec/test_app/app/controllers/filters_controller.rb +1 -1
- data/spec/test_app/app/controllers/tests_controller.rb +5 -0
- data/spec/test_app/app/controllers/themes_controller.rb +7 -0
- data/spec/test_app/app/views/filters/html5_input_types.html.erb +31 -0
- data/spec/test_app/app/views/tableficate/custom_check_box_block/filters/_check_box_choice.html.erb +2 -0
- data/spec/test_app/app/views/tableficate/custom_radio_block/filters/_radio_choice.html.erb +2 -0
- data/spec/test_app/app/views/tests/index.html.erb +13 -0
- data/spec/test_app/app/views/themes/caption.html.erb +9 -0
- data/spec/test_app/app/views/themes/column_attrs.html.erb +7 -0
- data/spec/test_app/app/views/themes/column_cell_attrs.html.erb +7 -0
- data/spec/test_app/app/views/themes/column_cell_attrs_with_proc.html.erb +7 -0
- data/spec/test_app/app/views/themes/column_header_attrs.html.erb +7 -0
- data/spec/test_app/app/views/themes/empty_with_data.html.erb +9 -0
- data/spec/test_app/app/views/themes/empty_with_no_data.html.erb +9 -0
- data/spec/test_app/app/views/themes/no_caption.html.erb +7 -0
- data/spec/test_app/app/views/themes/no_column_attrs.html.erb +7 -0
- data/spec/test_app/config/application.rb +1 -1
- data/spec/test_app/config/routes.rb +2 -0
- data/spec/test_app/db/migrate/20111227224959_additional_columns.rb +73 -0
- data/spec/test_app/db/migrate/20111230203456_created_at_specific_dates.rb +11 -0
- data/spec/test_app/db/schema.rb +10 -3
- data/spec/test_app/db/test.sqlite3 +0 -0
- data/spec/theme/caption_spec.rb +15 -0
- data/spec/theme/column_spec.rb +35 -0
- data/spec/theme/empty_spec.rb +15 -0
- data/spec/utils_spec.rb +44 -4
- metadata +69 -58
- data/spec/test_app/app/views/tableficate/custom_check_box_block/_data.html.erb +0 -1
- data/spec/test_app/app/views/tableficate/custom_check_box_block/_header.html.erb +0 -8
- data/spec/test_app/app/views/tableficate/custom_check_box_block/_row.html.erb +0 -5
- data/spec/test_app/app/views/tableficate/custom_check_box_block/_table.html.erb +0 -36
- data/spec/test_app/app/views/tableficate/custom_check_box_block/filters/_check_box.html.erb +0 -7
- data/spec/test_app/app/views/tableficate/custom_check_box_block/filters/_input.html.erb +0 -4
- data/spec/test_app/app/views/tableficate/custom_check_box_block/filters/_input_range.html.erb +0 -6
- data/spec/test_app/app/views/tableficate/custom_check_box_block/filters/_radio.html.erb +0 -4
- data/spec/test_app/app/views/tableficate/custom_check_box_block/filters/_select.html.erb +0 -4
- data/spec/test_app/app/views/tableficate/custom_check_box_block/filters/_select_range_filter.html.erb +0 -6
- data/spec/test_app/app/views/tableficate/custom_radio_block/_data.html.erb +0 -1
- data/spec/test_app/app/views/tableficate/custom_radio_block/_header.html.erb +0 -8
- data/spec/test_app/app/views/tableficate/custom_radio_block/_row.html.erb +0 -5
- data/spec/test_app/app/views/tableficate/custom_radio_block/_table.html.erb +0 -36
- data/spec/test_app/app/views/tableficate/custom_radio_block/filters/_check_box.html.erb +0 -4
- data/spec/test_app/app/views/tableficate/custom_radio_block/filters/_input.html.erb +0 -4
- data/spec/test_app/app/views/tableficate/custom_radio_block/filters/_input_range.html.erb +0 -6
- data/spec/test_app/app/views/tableficate/custom_radio_block/filters/_radio.html.erb +0 -7
- data/spec/test_app/app/views/tableficate/custom_radio_block/filters/_select.html.erb +0 -4
- data/spec/test_app/app/views/tableficate/custom_radio_block/filters/_select_range_filter.html.erb +0 -6
- data/spec/test_app/public/index.html +0 -241
data/lib/tableficate/helper.rb
CHANGED
|
@@ -3,100 +3,97 @@ module Tableficate
|
|
|
3
3
|
def table_for(rows, options = {})
|
|
4
4
|
t = Tableficate::Table.new(self, rows, options, rows.tableficate_get_data)
|
|
5
5
|
yield(t)
|
|
6
|
-
t.render
|
|
6
|
+
t.template.render(partial: Tableficate::Utils::template_path(t.template, 'table_for', t.theme), locals: {table: t})
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def tableficate_table_tag(table)
|
|
10
|
+
render partial: Tableficate::Utils::template_path(table.template, 'table', table.theme), locals: {table: table}
|
|
7
11
|
end
|
|
8
12
|
|
|
9
13
|
def tableficate_header_tag(column)
|
|
10
|
-
|
|
14
|
+
table = column.table
|
|
15
|
+
render partial: Tableficate::Utils::template_path(table.template, 'header', table.theme), locals: {column: column}
|
|
11
16
|
end
|
|
12
17
|
|
|
13
18
|
def tableficate_data_tag(row, column)
|
|
14
|
-
|
|
19
|
+
table = column.table
|
|
20
|
+
render partial: Tableficate::Utils::template_path(table.template, 'data', table.theme), locals: {row: row, column: column}
|
|
15
21
|
end
|
|
16
22
|
|
|
17
23
|
def tableficate_row_tag(row, columns)
|
|
18
|
-
|
|
24
|
+
table = columns.first.table
|
|
25
|
+
render partial: Tableficate::Utils::template_path(table.template, 'row', table.theme), locals: {row: row, columns: columns}
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def tableficate_filter_form_tag(table)
|
|
29
|
+
render partial: Tableficate::Utils::template_path(table.template, 'filters/form', table.theme), locals: {table: table}
|
|
19
30
|
end
|
|
20
31
|
|
|
21
32
|
def tableficate_filter_tag(filter)
|
|
22
|
-
|
|
33
|
+
table = filter.table
|
|
34
|
+
render partial: Tableficate::Utils::template_path(table.template, filter.template, table.theme), locals: {filter: filter}
|
|
23
35
|
end
|
|
24
36
|
|
|
25
37
|
def tableficate_label_tag(filter)
|
|
26
|
-
label_tag(filter.field_name, filter.label, filter.
|
|
38
|
+
label_tag(filter.field_name, filter.label, filter.label_options)
|
|
27
39
|
end
|
|
28
40
|
|
|
29
41
|
def tableficate_text_field_tag(filter)
|
|
30
|
-
text_field_tag(filter.field_name, filter.field_value(params[filter.table.as]), filter.
|
|
42
|
+
text_field_tag(filter.field_name, filter.field_value(params[filter.table.as]), filter.attrs)
|
|
31
43
|
end
|
|
32
44
|
|
|
33
45
|
def tableficate_select_tag(filter)
|
|
34
46
|
field_value = filter.field_value(params[filter.table.as])
|
|
35
47
|
|
|
36
|
-
|
|
48
|
+
collection = filter.collection
|
|
49
|
+
|
|
50
|
+
if field_value.present? and collection.is_a?(String)
|
|
37
51
|
Array.wrap(field_value).each do |fv|
|
|
38
|
-
if
|
|
39
|
-
|
|
52
|
+
if collection.match(/<option[^>]*value\s*=/)
|
|
53
|
+
collection.gsub!(/(<option[^>]*value\s*=\s*['"]?#{fv}[^>]*)/, '\1 selected="selected"')
|
|
40
54
|
else
|
|
41
|
-
|
|
55
|
+
collection.gsub!(/>#{fv}</, " selected=\"selected\">#{fv}<")
|
|
42
56
|
end
|
|
43
57
|
end
|
|
44
|
-
elsif not
|
|
45
|
-
|
|
46
|
-
html_attributes = choice.
|
|
58
|
+
elsif not collection.is_a?(String)
|
|
59
|
+
collection = Tableficate::Filter::Collection.new(collection, selected: field_value).map {|choice|
|
|
60
|
+
html_attributes = choice.attrs.length > 0 ? ' ' + choice.attrs.map {|k, v| %(#{k.to_s}="#{v}")}.join(' ') : ''
|
|
47
61
|
selected_attribute = choice.selected? ? ' selected="selected"' : ''
|
|
48
62
|
|
|
49
63
|
%(<option value="#{ERB::Util.html_escape(choice.value)}"#{selected_attribute}#{html_attributes}>#{ERB::Util.html_escape(choice.name)}</option>)
|
|
50
64
|
}.join("\n")
|
|
51
65
|
end
|
|
52
66
|
|
|
53
|
-
|
|
67
|
+
collection = collection.html_safe
|
|
54
68
|
|
|
55
|
-
select_tag(filter.field_name,
|
|
69
|
+
select_tag(filter.field_name, collection, filter.attrs)
|
|
56
70
|
end
|
|
57
71
|
|
|
58
|
-
def tableficate_radio_tags(filter
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
collection = Tableficate::Filter::Collection.new(filter.options[:collection], selected: filter.field_value(params[filter.table.as]))
|
|
72
|
+
def tableficate_radio_tags(filter)
|
|
73
|
+
tableficate_collection_of_tags(filter)
|
|
74
|
+
end
|
|
62
75
|
|
|
63
|
-
|
|
64
|
-
if
|
|
65
|
-
|
|
76
|
+
def tableficate_check_box_tags(filter)
|
|
77
|
+
if filter.collection.empty?
|
|
78
|
+
check_box_tag(filter.field_name, true, filter.field_value(params[filter.table.as]) == 'true', filter.attrs)
|
|
66
79
|
else
|
|
67
|
-
|
|
68
|
-
html.push(
|
|
69
|
-
radio_button_tag(filter.field_name, choice.value, choice.checked?, choice.options),
|
|
70
|
-
label_tag("#{filter.field_name}[#{choice.value}]", choice.name),
|
|
71
|
-
'<br/>'
|
|
72
|
-
)
|
|
73
|
-
end
|
|
80
|
+
tableficate_collection_of_tags(filter)
|
|
74
81
|
end
|
|
75
|
-
|
|
76
|
-
html.join("\n").html_safe
|
|
77
82
|
end
|
|
78
83
|
|
|
79
|
-
def
|
|
84
|
+
def tableficate_collection_of_tags(filter)
|
|
85
|
+
table = filter.table
|
|
80
86
|
field_value = filter.field_value(params[filter.table.as])
|
|
81
87
|
|
|
82
|
-
collection = Tableficate::Filter::Collection.new(filter.options[:collection], selected: filter.field_value(params[filter.table.as]))
|
|
83
|
-
|
|
84
88
|
html = []
|
|
85
|
-
|
|
86
|
-
html
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
html.push(
|
|
90
|
-
check_box_tag(
|
|
91
|
-
"#{filter.field_name}[#{choice.value}]", choice.value, choice.checked?, choice.options.reverse_merge(name: "#{filter.field_name}[]")
|
|
92
|
-
),
|
|
93
|
-
label_tag("#{filter.field_name}[#{choice.value}]", choice.name),
|
|
94
|
-
'<br/>'
|
|
95
|
-
)
|
|
96
|
-
end
|
|
89
|
+
Tableficate::Filter::Collection.new(filter.collection, selected: field_value).each do |choice|
|
|
90
|
+
html.push(
|
|
91
|
+
render(partial: Tableficate::Utils::template_path(table.template, filter.template + '_choice', table.theme), locals: {filter: filter, choice: choice})
|
|
92
|
+
)
|
|
97
93
|
end
|
|
98
94
|
|
|
99
95
|
html.join("\n").html_safe
|
|
100
96
|
end
|
|
97
|
+
private :tableficate_collection_of_tags
|
|
101
98
|
end
|
|
102
99
|
end
|
data/lib/tableficate/table.rb
CHANGED
|
@@ -1,32 +1,45 @@
|
|
|
1
1
|
module Tableficate
|
|
2
2
|
class Table
|
|
3
|
-
attr_reader :columns, :rows, :current_sort, :filters, :
|
|
3
|
+
attr_reader :columns, :rows, :current_sort, :filters, :attrs, :as, :template, :theme
|
|
4
4
|
|
|
5
5
|
def initialize(template, rows, options, data)
|
|
6
6
|
@template = template
|
|
7
7
|
@rows = rows
|
|
8
|
-
@columns = []
|
|
9
|
-
@filters = []
|
|
10
|
-
@as = options[:as] || rows.table_name
|
|
11
8
|
|
|
12
|
-
@options
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
9
|
+
@as = options.delete(:as) || rows.table_name
|
|
10
|
+
@theme = options.delete(:theme) || ''
|
|
11
|
+
@show_sorts = options.delete(:show_sorts) || false
|
|
12
|
+
@attrs = options
|
|
13
|
+
|
|
14
|
+
@columns = []
|
|
15
|
+
@filters = []
|
|
16
16
|
|
|
17
17
|
@current_sort = data[:current_sort]
|
|
18
|
+
@field_map = data[:field_map] || {}
|
|
18
19
|
end
|
|
19
20
|
|
|
20
|
-
def
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
def empty(*args, &block)
|
|
22
|
+
if args.empty? and not block_given?
|
|
23
|
+
@empty
|
|
24
|
+
else
|
|
25
|
+
@empty = Empty.new(self, *args, &block)
|
|
26
|
+
end
|
|
27
|
+
end
|
|
24
28
|
|
|
25
|
-
|
|
29
|
+
def caption(*args, &block)
|
|
30
|
+
if args.empty? and not block_given?
|
|
31
|
+
@caption
|
|
32
|
+
else
|
|
33
|
+
@caption = Caption.new(*args, &block)
|
|
34
|
+
end
|
|
26
35
|
end
|
|
27
36
|
|
|
28
|
-
def
|
|
29
|
-
@columns.push(
|
|
37
|
+
def column(name, options = {}, &block)
|
|
38
|
+
@columns.push(Column.new(self, name, options.reverse_merge(show_sort: @show_sorts), &block))
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def actions(options = {}, &block)
|
|
42
|
+
@columns.push(ActionColumn.new(self, options, &block))
|
|
30
43
|
end
|
|
31
44
|
|
|
32
45
|
def show_sort?
|
|
@@ -54,7 +67,7 @@ module Tableficate
|
|
|
54
67
|
checkbox: Filter::CheckBox
|
|
55
68
|
}
|
|
56
69
|
|
|
57
|
-
as = options.delete(:as) || (options
|
|
70
|
+
as = options.delete(:as) || find_as(name, options.has_key?(:collection))
|
|
58
71
|
|
|
59
72
|
raise Filter::UnknownInputType if as_map[as].nil?
|
|
60
73
|
|
|
@@ -82,7 +95,7 @@ module Tableficate
|
|
|
82
95
|
select: Filter::SelectRange
|
|
83
96
|
}
|
|
84
97
|
|
|
85
|
-
as = options.delete(:as) || (options
|
|
98
|
+
as = options.delete(:as) || find_as(name, options.has_key?(:collection))
|
|
86
99
|
|
|
87
100
|
raise Filter::UnknownInputType if as_map[as].nil?
|
|
88
101
|
|
|
@@ -91,13 +104,40 @@ module Tableficate
|
|
|
91
104
|
@filters.push(as_map[as].new(self, name, options))
|
|
92
105
|
end
|
|
93
106
|
|
|
94
|
-
def
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
107
|
+
def find_as(name, has_collection)
|
|
108
|
+
field_name = (@field_map[name] || name).to_s
|
|
109
|
+
as = :text
|
|
110
|
+
|
|
111
|
+
if has_collection
|
|
112
|
+
as = :select
|
|
113
|
+
else
|
|
114
|
+
case Tableficate::Utils::find_column_type(@rows, field_name)
|
|
115
|
+
when :integer, :float, :decimal
|
|
116
|
+
as = :number
|
|
117
|
+
when :date
|
|
118
|
+
as = :date
|
|
119
|
+
when :time
|
|
120
|
+
as = :time
|
|
121
|
+
when :datetime, :timestamp
|
|
122
|
+
as = :datetime
|
|
123
|
+
when :boolean
|
|
124
|
+
as = :checkbox
|
|
125
|
+
end
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
if as == :text
|
|
129
|
+
case name
|
|
130
|
+
when /email/
|
|
131
|
+
as = :email
|
|
132
|
+
when /url/
|
|
133
|
+
as = :url
|
|
134
|
+
when /phone/
|
|
135
|
+
as = :tel
|
|
136
|
+
end
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
as
|
|
101
140
|
end
|
|
141
|
+
private :find_as
|
|
102
142
|
end
|
|
103
143
|
end
|
data/lib/tableficate/utils.rb
CHANGED
|
@@ -1,7 +1,32 @@
|
|
|
1
1
|
module Tableficate
|
|
2
2
|
module Utils
|
|
3
|
-
def self.template_path(template, theme = '')
|
|
4
|
-
File.join(['tableficate', theme,
|
|
3
|
+
def self.template_path(template, partial, theme = '')
|
|
4
|
+
file = File.join(['tableficate', theme, partial].delete_if(&:blank?))
|
|
5
|
+
|
|
6
|
+
file = File.join(['tableficate', partial]) if not theme.blank? and not template.lookup_context.exists?(file, [], true)
|
|
7
|
+
|
|
8
|
+
file
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def self.find_column_type(scope, name)
|
|
12
|
+
name = name.to_s
|
|
13
|
+
column = scope.columns.detect{|column| column.name == name} ||
|
|
14
|
+
(
|
|
15
|
+
(scope.respond_to?(:joins_values) ? scope.joins_values : []) +
|
|
16
|
+
(scope.respond_to?(:includes_values) ? scope.includes_values : [])
|
|
17
|
+
).uniq.map{|join|
|
|
18
|
+
# convert string joins to table names
|
|
19
|
+
if join.is_a?(String)
|
|
20
|
+
join.scan(/(?:(?:,|\bjoin\s*)\s*(\w+))/i)
|
|
21
|
+
else
|
|
22
|
+
join
|
|
23
|
+
end
|
|
24
|
+
}.flatten.map{|table_name|
|
|
25
|
+
ActiveRecord::Base::connection_pool.columns[table_name.to_s.tableize]
|
|
26
|
+
}.flatten.detect{|column|
|
|
27
|
+
column.name == name
|
|
28
|
+
}
|
|
29
|
+
column.try(:type)
|
|
5
30
|
end
|
|
6
31
|
end
|
|
7
32
|
end
|
data/lib/tableficate/version.rb
CHANGED
data/spec/action_column_spec.rb
CHANGED
|
@@ -3,7 +3,7 @@ require 'spec_helper'
|
|
|
3
3
|
describe Tableficate::ActionColumn do
|
|
4
4
|
before(:all) do
|
|
5
5
|
@action_column = Tableficate::ActionColumn.new(nil) do
|
|
6
|
-
Actions!
|
|
6
|
+
'Actions Here!'
|
|
7
7
|
end
|
|
8
8
|
end
|
|
9
9
|
|
|
@@ -18,4 +18,12 @@ describe Tableficate::ActionColumn do
|
|
|
18
18
|
it 'should have a blank name' do
|
|
19
19
|
@action_column.name.should == ''
|
|
20
20
|
end
|
|
21
|
+
|
|
22
|
+
it 'should accept options' do
|
|
23
|
+
action_column = Tableficate::ActionColumn.new(nil, header: 'Actions') do
|
|
24
|
+
'Actions Here!'
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
action_column.header.should == 'Actions'
|
|
28
|
+
end
|
|
21
29
|
end
|
data/spec/base_spec.rb
CHANGED
|
@@ -18,6 +18,16 @@ describe Tableficate::Base do
|
|
|
18
18
|
lambda {NoScope.tableficate({})}.should raise_error(Tableficate::MissingScope)
|
|
19
19
|
end
|
|
20
20
|
|
|
21
|
+
it 'should allow for custom column sorting' do
|
|
22
|
+
class ColumnOrder < Tableficate::Base
|
|
23
|
+
scope(:nobel_prize_winner)
|
|
24
|
+
|
|
25
|
+
column(:full_name, sort: 'first_name ASC, last_name ASC')
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
ColumnOrder.send(:instance_variable_get, '@sort')[:full_name].should == 'first_name ASC, last_name ASC'
|
|
29
|
+
end
|
|
30
|
+
|
|
21
31
|
it 'should allow for a default order' do
|
|
22
32
|
class DefaultOrder < Tableficate::Base
|
|
23
33
|
scope(:nobel_prize_winner)
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe Tableficate::Caption do
|
|
4
|
+
it 'should accept plain text in the arguments' do
|
|
5
|
+
caption = Tableficate::Caption.new('Foo', {class: 'title'})
|
|
6
|
+
|
|
7
|
+
caption.attrs[:class].should == 'title'
|
|
8
|
+
caption.value.should == 'Foo'
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
it 'should take a block in place of the plain text argument' do
|
|
12
|
+
caption = Tableficate::Caption.new({class: 'title'}) do
|
|
13
|
+
'Foo'
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
caption.attrs[:class].should == 'title'
|
|
17
|
+
caption.value.should == 'Foo'
|
|
18
|
+
end
|
|
19
|
+
it 'should not escape html in block outputs' do
|
|
20
|
+
caption = Tableficate::Caption.new do
|
|
21
|
+
'<b>Foo</b>'
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
ERB::Util::html_escape(caption.value).should == '<b>Foo</b>'
|
|
25
|
+
end
|
|
26
|
+
it 'should allow ERB tags in block outputs' do
|
|
27
|
+
caption = Tableficate::Caption.new do
|
|
28
|
+
ERB.new("<%= 'Foo'.upcase %>").result(binding)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
caption.value.should == 'FOO'
|
|
32
|
+
end
|
|
33
|
+
end
|
data/spec/column_spec.rb
CHANGED
|
@@ -9,6 +9,27 @@ describe Tableficate::Column do
|
|
|
9
9
|
column.header.should == 'Given Name'
|
|
10
10
|
end
|
|
11
11
|
|
|
12
|
+
it 'should take all non-specialized options as attrs on the `col` tag' do
|
|
13
|
+
column = Tableficate::Column.new(nil, :first_name, class: 'attrs')
|
|
14
|
+
column.attrs.should == {class: 'attrs'}
|
|
15
|
+
|
|
16
|
+
column = Tableficate::Column.new(nil, :first_name)
|
|
17
|
+
column.attrs.should == {}
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
it 'should accept :header_attrs as an option' do
|
|
21
|
+
column = Tableficate::Column.new(nil, :first_name, header_attrs: {class: 'header'})
|
|
22
|
+
column.header_attrs.should == {class: 'header'}
|
|
23
|
+
|
|
24
|
+
column = Tableficate::Column.new(nil, :first_name)
|
|
25
|
+
column.header_attrs.should == {}
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
it 'should accept :cell_attrs as an option' do
|
|
29
|
+
column = Tableficate::Column.new(nil, :first_name, cell_attrs: {class: 'cell'})
|
|
30
|
+
column.cell_attrs.should == {class: 'cell'}
|
|
31
|
+
end
|
|
32
|
+
|
|
12
33
|
it 'should show the value from the database field if no alternative is provided' do
|
|
13
34
|
row = NobelPrizeWinner.find_by_first_name('Norman')
|
|
14
35
|
column = Tableficate::Column.new(nil, :first_name)
|
|
@@ -31,6 +52,14 @@ describe Tableficate::Column do
|
|
|
31
52
|
|
|
32
53
|
ERB::Util::html_escape(column.value(row)).should == 'Norman<br/>Borlaug'
|
|
33
54
|
end
|
|
55
|
+
it 'should allow ERB tags in block outputs' do
|
|
56
|
+
row = NobelPrizeWinner.find_by_first_name_and_last_name('Norman', 'Borlaug')
|
|
57
|
+
column = Tableficate::Column.new(nil, :first_name) do |row|
|
|
58
|
+
ERB.new("<%= row.first_name.upcase %>").result(binding)
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
column.value(row).should == 'NORMAN'
|
|
62
|
+
end
|
|
34
63
|
|
|
35
64
|
it 'should allow sorting to be turned on and off' do
|
|
36
65
|
column = Tableficate::Column.new(nil, :first_name, show_sort: false)
|
data/spec/empty_spec.rb
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe Tableficate::Empty do
|
|
4
|
+
before(:each) do
|
|
5
|
+
@table = Tableficate::Table.new(nil, NobelPrizeWinner.limit(1), {}, {})
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
it 'should add a `colspan` attribute' do
|
|
9
|
+
@table.column(:first_name)
|
|
10
|
+
@table.column(:last_name)
|
|
11
|
+
empty = Tableficate::Empty.new(@table, 'Foo')
|
|
12
|
+
|
|
13
|
+
empty.attrs[:colspan].should == 2
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
it 'should accept plain text in the arguments' do
|
|
17
|
+
empty = Tableficate::Empty.new(@table, 'Foo', {class: 'title'})
|
|
18
|
+
|
|
19
|
+
empty.attrs[:class].should == 'title'
|
|
20
|
+
empty.value.should == 'Foo'
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
it 'should take a block in place of the plain text argument' do
|
|
24
|
+
empty = Tableficate::Empty.new(@table, {class: 'title'}) do
|
|
25
|
+
'Foo'
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
empty.attrs[:class].should == 'title'
|
|
29
|
+
empty.value.should == 'Foo'
|
|
30
|
+
end
|
|
31
|
+
it 'should not escape html in block outputs' do
|
|
32
|
+
empty = Tableficate::Empty.new(@table) do
|
|
33
|
+
'<b>Foo</b>'
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
ERB::Util::html_escape(empty.value).should == '<b>Foo</b>'
|
|
37
|
+
end
|
|
38
|
+
it 'should allow ERB tags in block outputs' do
|
|
39
|
+
empty = Tableficate::Empty.new(@table) do
|
|
40
|
+
ERB.new("<%= 'Foo'.upcase %>").result(binding)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
empty.value.should == 'FOO'
|
|
44
|
+
end
|
|
45
|
+
end
|