tabletastic 0.2.0.pre5 → 0.2.0.pre6
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.rdoc +7 -5
- data/README.rdoc +1 -1
- data/lib/tabletastic/table_builder.rb +20 -8
- data/lib/tabletastic/table_field.rb +3 -3
- data/lib/tabletastic/version.rb +2 -2
- data/spec/spec_helper.rb +4 -4
- data/spec/tabletastic/table_builder_spec.rb +60 -42
- metadata +6 -12
data/CHANGELOG.rdoc
CHANGED
@@ -1,10 +1,12 @@
|
|
1
1
|
Git (for upcoming v0.2.0 release)
|
2
2
|
|
3
3
|
* [DEPRECATED] use of table.data method without = in erb or haml. See README for more information.
|
4
|
-
*
|
5
|
-
*
|
6
|
-
*
|
7
|
-
*
|
4
|
+
* Update to Rails 3 API and idioms
|
5
|
+
* Add default table html options
|
6
|
+
* Add default lambda (table block) so that table_for can be called without passing a block
|
7
|
+
* Add has_one associations
|
8
|
+
* Add heading html hook for <th> elements
|
9
|
+
* Super-basic mongoid support (2.x branch)
|
8
10
|
|
9
11
|
v0.1.3 (Dec 28, 2009)
|
10
12
|
|
@@ -26,4 +28,4 @@ v0.1.0 (Nov 17, 2009)
|
|
26
28
|
|
27
29
|
v0.0.1 (Nov 15, 2009)
|
28
30
|
|
29
|
-
* Beta release, proof-of-concept
|
31
|
+
* Beta release, proof-of-concept
|
data/README.rdoc
CHANGED
@@ -77,7 +77,7 @@ For more information about Rails 3 and Block helpers and the new conventions, ch
|
|
77
77
|
== Installation
|
78
78
|
|
79
79
|
In your Rails project, Gemfile:
|
80
|
-
gem "tabletastic"
|
80
|
+
gem "tabletastic", '~> 0.2.0.pre6'
|
81
81
|
|
82
82
|
Or, for if you're behind the times, as a plugin:
|
83
83
|
script/plugin install git://github.com/jgdavey/tabletastic.git
|
@@ -22,13 +22,12 @@ module Tabletastic
|
|
22
22
|
# * With a block, which assumes you will use +cell+ method to build up
|
23
23
|
# the table
|
24
24
|
#
|
25
|
-
#
|
26
25
|
def data(*args, &block) # :yields: tablebody
|
27
26
|
options = args.extract_options!
|
28
27
|
if block_given?
|
29
28
|
yield self
|
30
29
|
else
|
31
|
-
@table_fields = args.empty? ?
|
30
|
+
@table_fields = args.empty? ? orm_fields : args.collect {|f| TableField.new(f.to_sym)}
|
32
31
|
end
|
33
32
|
action_cells(options[:actions], options[:action_prefix])
|
34
33
|
["\n", head, "\n", body, "\n"].join("").html_safe
|
@@ -60,8 +59,8 @@ module Tabletastic
|
|
60
59
|
options.merge!(:klass => klass)
|
61
60
|
args << options
|
62
61
|
@table_fields << TableField.new(*args, &proc)
|
63
|
-
# Since this will likely be called with <%= %> (aka 'concat'), explicitly return an
|
64
|
-
#
|
62
|
+
# Since this will likely be called with <%= %> (aka 'concat'), explicitly return an
|
63
|
+
# empty string; this suppresses unwanted output
|
65
64
|
return ""
|
66
65
|
end
|
67
66
|
|
@@ -69,7 +68,7 @@ module Tabletastic
|
|
69
68
|
content_tag(:thead) do
|
70
69
|
content_tag(:tr) do
|
71
70
|
@table_fields.inject("") do |result,field|
|
72
|
-
result
|
71
|
+
result + content_tag(:th, field.heading, field.heading_html)
|
73
72
|
end
|
74
73
|
end
|
75
74
|
end
|
@@ -121,16 +120,29 @@ module Tabletastic
|
|
121
120
|
|
122
121
|
protected
|
123
122
|
|
124
|
-
def
|
123
|
+
def orm_fields
|
125
124
|
return [] if klass.blank?
|
126
|
-
fields = klass.content_columns
|
127
|
-
|
125
|
+
fields = if klass.respond_to?(:content_columns)
|
126
|
+
active_record_fields
|
127
|
+
elsif klass.respond_to?(:fields)
|
128
|
+
mongoid_fields
|
129
|
+
else
|
130
|
+
[]
|
131
|
+
end
|
128
132
|
fields -= @@default_hidden_columns
|
129
133
|
fields.collect {|f| TableField.new(f.to_sym)}
|
130
134
|
end
|
131
135
|
|
132
136
|
private
|
133
137
|
|
138
|
+
def mongoid_fields
|
139
|
+
klass.fields.keys
|
140
|
+
end
|
141
|
+
|
142
|
+
def active_record_fields
|
143
|
+
klass.content_columns.map(&:name) + active_record_association_reflections
|
144
|
+
end
|
145
|
+
|
134
146
|
def active_record_association_reflections
|
135
147
|
return [] unless klass.respond_to?(:reflect_on_all_associations)
|
136
148
|
associations = []
|
@@ -4,13 +4,13 @@ module Tabletastic
|
|
4
4
|
class TableField
|
5
5
|
@@association_methods = %w[to_label display_name full_name name title username login value to_str to_s]
|
6
6
|
|
7
|
-
attr_accessor :heading, :method_or_proc, :cell_html
|
7
|
+
attr_accessor :heading, :method_or_proc, :cell_html, :heading_html
|
8
8
|
|
9
9
|
def initialize(*args, &proc)
|
10
10
|
options = args.extract_options!
|
11
11
|
method = args.first.to_sym
|
12
12
|
@method_or_proc = block_given? ? proc : method
|
13
|
-
@cell_html = options[:cell_html]
|
13
|
+
@cell_html, @heading_html = options[:cell_html], options[:heading_html]
|
14
14
|
@klass = options.delete(:klass)
|
15
15
|
@heading = options.delete(:heading) || @klass.try(:human_attribute_name, method.to_s) || method.to_s.humanize
|
16
16
|
end
|
@@ -41,4 +41,4 @@ module Tabletastic
|
|
41
41
|
end
|
42
42
|
end
|
43
43
|
end
|
44
|
-
end
|
44
|
+
end
|
data/lib/tabletastic/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
1
|
module Tabletastic
|
2
|
-
VERSION = "0.2.0.
|
3
|
-
end
|
2
|
+
VERSION = "0.2.0.pre6"
|
3
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -21,7 +21,6 @@ Spork.prefork do
|
|
21
21
|
end
|
22
22
|
|
23
23
|
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
24
|
-
require 'tabletastic'
|
25
24
|
|
26
25
|
module TabletasticSpecHelper
|
27
26
|
include ActiveSupport
|
@@ -123,12 +122,13 @@ Spork.prefork do
|
|
123
122
|
end
|
124
123
|
end
|
125
124
|
|
126
|
-
include TabletasticSpecHelper
|
127
|
-
include Tabletastic
|
128
|
-
include Tabletastic::Helper
|
129
125
|
end
|
130
126
|
|
131
127
|
Spork.each_run do
|
132
128
|
# This code will be run each time you run your specs.
|
129
|
+
require 'tabletastic'
|
133
130
|
|
131
|
+
include TabletasticSpecHelper
|
132
|
+
include Tabletastic
|
133
|
+
include Tabletastic::Helper
|
134
134
|
end
|
@@ -19,30 +19,22 @@ describe Tabletastic::TableBuilder do
|
|
19
19
|
concat(table_for(@posts) { |t| t.data })
|
20
20
|
end
|
21
21
|
|
22
|
-
|
23
|
-
output_buffer.should have_tag("table#posts")
|
24
|
-
end
|
22
|
+
subject { output_buffer }
|
25
23
|
|
26
|
-
it
|
27
|
-
|
28
|
-
|
24
|
+
it { should have_tag("table#posts") }
|
25
|
+
|
26
|
+
it { output_buffer.should have_table_with_tag("thead") }
|
29
27
|
|
30
28
|
it "should have a <th> for each attribute" do
|
31
29
|
# title and body
|
32
30
|
output_buffer.should have_table_with_tag("th", :count => 2)
|
33
31
|
end
|
34
32
|
|
35
|
-
it
|
36
|
-
output_buffer.should have_table_with_tag("th", "Title")
|
37
|
-
end
|
33
|
+
it { output_buffer.should have_table_with_tag("th", "Title") }
|
38
34
|
|
39
|
-
it
|
40
|
-
output_buffer.should have_table_with_tag("th", "Body")
|
41
|
-
end
|
35
|
+
it { output_buffer.should have_table_with_tag("th", "Body") }
|
42
36
|
|
43
|
-
it
|
44
|
-
output_buffer.should have_table_with_tag("tbody")
|
45
|
-
end
|
37
|
+
it { output_buffer.should have_table_with_tag("tbody") }
|
46
38
|
|
47
39
|
it "should include a row for each record" do
|
48
40
|
output_buffer.should have_table_with_tag("tbody") do |tbody|
|
@@ -55,9 +47,7 @@ describe Tabletastic::TableBuilder do
|
|
55
47
|
output_buffer.should have_table_with_tag("td", "Lorem ipsum")
|
56
48
|
end
|
57
49
|
|
58
|
-
it
|
59
|
-
output_buffer.should have_table_with_tag("tr#post_#{@post.id}")
|
60
|
-
end
|
50
|
+
it { output_buffer.should have_table_with_tag("tr#post_#{@post.id}") }
|
61
51
|
|
62
52
|
it "should cycle row classes" do
|
63
53
|
reset_output_buffer!
|
@@ -70,6 +60,21 @@ describe Tabletastic::TableBuilder do
|
|
70
60
|
output_buffer.should have_table_with_tag("tr.even")
|
71
61
|
end
|
72
62
|
|
63
|
+
context "mongoid collection" do
|
64
|
+
before do
|
65
|
+
reset_output_buffer!
|
66
|
+
::Post.stub!(:respond_to?).with(:content_columns).and_return(false)
|
67
|
+
::Post.stub!(:respond_to?).with(:fields).and_return(true)
|
68
|
+
::Post.stub!(:fields).and_return({'title' => '', 'created_at' => ''})
|
69
|
+
concat(table_for(@posts) { |t| t.data })
|
70
|
+
end
|
71
|
+
|
72
|
+
it "should detect fields properly" do
|
73
|
+
output_buffer.should have_table_with_tag("td", "The title of the post")
|
74
|
+
output_buffer.should_not have_table_with_tag("td", "Lorem ipsum")
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
73
78
|
context "when collection has associations" do
|
74
79
|
it "should handle belongs_to associations" do
|
75
80
|
::Post.stub!(:reflect_on_all_associations).with(:belongs_to).and_return([@mock_reflection_belongs_to_author])
|
@@ -176,12 +181,11 @@ describe Tabletastic::TableBuilder do
|
|
176
181
|
t.data(:title, :created_at)
|
177
182
|
end)
|
178
183
|
end
|
184
|
+
subject { output_buffer }
|
179
185
|
|
180
|
-
it
|
181
|
-
|
182
|
-
|
183
|
-
output_buffer.should_not have_table_with_tag("th", "Body")
|
184
|
-
end
|
186
|
+
it { should have_table_with_tag("th", "Title") }
|
187
|
+
it { should have_table_with_tag("th", "Created at") }
|
188
|
+
it { should_not have_table_with_tag("th", "Body") }
|
185
189
|
end
|
186
190
|
|
187
191
|
context "with a list of attributes and options[:actions]" do
|
@@ -210,11 +214,11 @@ describe Tabletastic::TableBuilder do
|
|
210
214
|
end)
|
211
215
|
end
|
212
216
|
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
217
|
+
subject { output_buffer }
|
218
|
+
|
219
|
+
it { should have_table_with_tag("th", "Title") }
|
220
|
+
it { should have_tag("td", "The title of the post") }
|
221
|
+
it { should have_tag("td", "Lorem ipsum") }
|
218
222
|
end
|
219
223
|
|
220
224
|
context "with custom cell options" do
|
@@ -227,17 +231,17 @@ describe Tabletastic::TableBuilder do
|
|
227
231
|
end)
|
228
232
|
end
|
229
233
|
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
+
subject { output_buffer }
|
235
|
+
|
236
|
+
it { should have_table_with_tag("th", "FooBar") }
|
237
|
+
it { should have_table_with_tag("th", "Body") }
|
234
238
|
|
235
239
|
it "should pass :cell_html to the cell" do
|
236
240
|
output_buffer.should have_table_with_tag("td.batquux")
|
237
241
|
end
|
238
242
|
end
|
239
243
|
|
240
|
-
context "with custom
|
244
|
+
context "with custom heading option" do
|
241
245
|
before do
|
242
246
|
concat(table_for(@posts) do |t|
|
243
247
|
t.data do
|
@@ -247,29 +251,42 @@ describe Tabletastic::TableBuilder do
|
|
247
251
|
end)
|
248
252
|
end
|
249
253
|
|
254
|
+
subject { output_buffer }
|
255
|
+
|
256
|
+
it { should have_table_with_tag("th:nth-child(1)", "Title") }
|
257
|
+
it { should have_table_with_tag("th:nth-child(2)", "Content") }
|
258
|
+
it { should have_table_with_tag("td:nth-child(2)", "Lorem ipsum") }
|
259
|
+
|
250
260
|
it "accepts a block as a lazy attribute" do
|
251
|
-
output_buffer.should have_table_with_tag("th:nth-child(1)", "Title")
|
252
261
|
output_buffer.should have_table_with_tag("td:nth-child(1)") do |td|
|
253
262
|
td.should have_tag("a", "The title of the post")
|
254
263
|
end
|
255
264
|
end
|
265
|
+
end
|
256
266
|
|
257
|
-
|
258
|
-
|
259
|
-
|
267
|
+
context "with custom heading html option" do
|
268
|
+
before do
|
269
|
+
concat( table_for(@posts) do |t|
|
270
|
+
t.data do
|
271
|
+
t.cell(:title, :heading_html => {:class => 'hoja'})
|
272
|
+
end
|
273
|
+
end)
|
260
274
|
end
|
275
|
+
subject { output_buffer }
|
276
|
+
it { should have_table_with_tag("th.hoja") }
|
261
277
|
end
|
262
278
|
|
263
279
|
context "with options[:actions]" do
|
264
|
-
|
280
|
+
before do
|
265
281
|
concat(table_for(@posts) do |t|
|
266
282
|
t.data(:actions => :show) do
|
267
283
|
t.cell(:title)
|
268
284
|
t.cell(:body)
|
269
285
|
end
|
270
286
|
end)
|
271
|
-
output_buffer.should have_table_with_tag("td:nth-child(3) a[@href=\"/posts/#{@post.id}\"]")
|
272
287
|
end
|
288
|
+
subject { output_buffer }
|
289
|
+
it { should have_table_with_tag("td:nth-child(3) a[@href=\"/posts/#{@post.id}\"]") }
|
273
290
|
end
|
274
291
|
|
275
292
|
context "and normal/association columns" do
|
@@ -297,7 +314,7 @@ describe Tabletastic::TableBuilder do
|
|
297
314
|
end
|
298
315
|
|
299
316
|
context "using human_attribute_names" do
|
300
|
-
|
317
|
+
before do
|
301
318
|
::Post.stub!(:human_attribute_name).with('body').and_return("Blah blue")
|
302
319
|
|
303
320
|
concat(table_for(@posts) do |t|
|
@@ -306,9 +323,10 @@ describe Tabletastic::TableBuilder do
|
|
306
323
|
t.cell(:body)
|
307
324
|
end
|
308
325
|
end)
|
309
|
-
|
310
|
-
output_buffer.should have_table_with_tag("th", "Blah blue")
|
311
326
|
end
|
327
|
+
|
328
|
+
subject { output_buffer }
|
329
|
+
it { should have_table_with_tag("th", "Blah blue") }
|
312
330
|
end
|
313
331
|
|
314
332
|
context "when table_for is not passed a block" do
|
metadata
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tabletastic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash: -1876988180
|
5
4
|
prerelease: true
|
6
5
|
segments:
|
7
6
|
- 0
|
8
7
|
- 2
|
9
8
|
- 0
|
10
|
-
-
|
11
|
-
version: 0.2.0.
|
9
|
+
- pre6
|
10
|
+
version: 0.2.0.pre6
|
12
11
|
platform: ruby
|
13
12
|
authors:
|
14
13
|
- Joshua Davey
|
@@ -16,7 +15,7 @@ autorequire:
|
|
16
15
|
bindir: bin
|
17
16
|
cert_chain: []
|
18
17
|
|
19
|
-
date: 2010-
|
18
|
+
date: 2010-09-11 00:00:00 -04:00
|
20
19
|
default_executable:
|
21
20
|
dependencies:
|
22
21
|
- !ruby/object:Gem::Dependency
|
@@ -25,15 +24,13 @@ dependencies:
|
|
25
24
|
requirement: &id001 !ruby/object:Gem::Requirement
|
26
25
|
none: false
|
27
26
|
requirements:
|
28
|
-
- -
|
27
|
+
- - ~>
|
29
28
|
- !ruby/object:Gem::Version
|
30
|
-
hash: 7712042
|
31
29
|
segments:
|
32
30
|
- 3
|
33
31
|
- 0
|
34
32
|
- 0
|
35
|
-
|
36
|
-
version: 3.0.0.rc
|
33
|
+
version: 3.0.0
|
37
34
|
type: :runtime
|
38
35
|
version_requirements: *id001
|
39
36
|
- !ruby/object:Gem::Dependency
|
@@ -44,13 +41,12 @@ dependencies:
|
|
44
41
|
requirements:
|
45
42
|
- - ">="
|
46
43
|
- !ruby/object:Gem::Version
|
47
|
-
hash: 3
|
48
44
|
segments:
|
49
45
|
- 0
|
50
46
|
version: "0"
|
51
47
|
type: :development
|
52
48
|
version_requirements: *id002
|
53
|
-
description: A table builder for active record collections that
|
49
|
+
description: " A table builder for active record collections that\n produces semantically rich and accessible table markup\n"
|
54
50
|
email: josh@joshuadavey.com
|
55
51
|
executables: []
|
56
52
|
|
@@ -87,7 +83,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
87
83
|
requirements:
|
88
84
|
- - ">="
|
89
85
|
- !ruby/object:Gem::Version
|
90
|
-
hash: 3
|
91
86
|
segments:
|
92
87
|
- 0
|
93
88
|
version: "0"
|
@@ -96,7 +91,6 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
96
91
|
requirements:
|
97
92
|
- - ">="
|
98
93
|
- !ruby/object:Gem::Version
|
99
|
-
hash: 23
|
100
94
|
segments:
|
101
95
|
- 1
|
102
96
|
- 3
|