tabletastic 0.2.0.pre4 → 0.2.0.pre5

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.rdoc CHANGED
@@ -1,5 +1,6 @@
1
1
  Git (for upcoming v0.2.0 release)
2
2
 
3
+ * [DEPRECATED] use of table.data method without = in erb or haml. See README for more information.
3
4
  * Updating to Rails3 API and idioms
4
5
  * Adding default table html options
5
6
  * Adding default lambda (table block) so that table_for can be called without passing a block
data/README.rdoc CHANGED
@@ -34,11 +34,11 @@ goodness that tabular data should have, i.e. a +thead+ and +tbody+ element.
34
34
 
35
35
  == NOTICE: Rails 3 only!
36
36
 
37
- As of version 0.2.0, this project is <strong>no longer compatible with Rails 2</strong>.
38
- To use, make sure you're using the latest release of Rails 3 (beta 2 at this time).
37
+ As of version 0.2.0, this project is <b>no longer compatible with Rails 2</b>.
38
+ To use, make sure you're using the latest release of Rails 3.
39
39
 
40
- Also, the new Rails 3 idiom is for blocks in erb templates to be use <%= %>, so if you're
41
- upgrading, you MUST now use the <%= %> erb helpers when you call +table_for+.
40
+ Also, the new Rails 3 idiom is for blocks in erb templates to be use <code><%= %></code>, so if you're
41
+ upgrading, you MUST now use the <code><%= %></code> erb helpers when you call +table_for+.
42
42
 
43
43
  For example:
44
44
 
@@ -46,6 +46,33 @@ For example:
46
46
  t.data
47
47
  end %>
48
48
 
49
+ The following would also be valid:
50
+
51
+ <%= table_for(@people) do |t| %>
52
+ <%= t.data %>
53
+ <% end %>
54
+
55
+ Or in HAML:
56
+
57
+ = table_for(@people) do |t|
58
+ = t.data
59
+
60
+ But, following the block helper conventions, the following would NOT be okay
61
+
62
+ <!-- Don't do this! -->
63
+ <%= table_for(@people) do |t| %>
64
+ <% t.data %>
65
+ <% end %>
66
+
67
+ Or, in HAML:
68
+
69
+ -# Don't do this!
70
+ = table_for(@people) do |t|
71
+ - t.data
72
+
73
+ This is because the +data+ method has output, and can optionally be called with a block.
74
+
75
+ For more information about Rails 3 and Block helpers and the new conventions, check out {the Railscasts episode about ERB blocks}[http://railscasts.com/episodes/208-erb-blocks-in-rails-3]
49
76
 
50
77
  == Installation
51
78
 
@@ -55,6 +82,8 @@ In your Rails project, Gemfile:
55
82
  Or, for if you're behind the times, as a plugin:
56
83
  script/plugin install git://github.com/jgdavey/tabletastic.git
57
84
 
85
+ Optionally, you can create an initializer at config/initializers/tabletastic.rb with the following:
86
+ Tabletastic.default_table_block = lambda {|table| table.data :actions => :all }
58
87
 
59
88
  == Usage
60
89
 
@@ -230,7 +259,7 @@ of your tables have a specific html +class+ or +cellspacing+, or whatever.
230
259
  If <code>Tabletastic.default_table_html</code> is set to <code>{:cellspacing => 0, :class => 'yowza'}</code>,
231
260
  then all tabletastic tables will have this html by default, unless overridden:
232
261
 
233
- table_for(@posts) do |t|
262
+ table_for(@posts) do |t| # body of block removed for brevity
234
263
 
235
264
  will produce:
236
265
 
@@ -248,7 +277,8 @@ will be the same as
248
277
  t.data
249
278
  end %>
250
279
 
251
- However, just like +default_table_html+, you can set a different block in the initializer file for your block to default to.
280
+ However, just like +default_table_html+ , you can set a different block in the initializer file for your block to default to.
281
+
252
282
  For example:
253
283
 
254
284
  Tabletastic.default_table_block = lambda {|table| table.data :actions => :all }
@@ -272,7 +302,7 @@ And to omit those action links, you can just use +table_for+ the old-fashioned w
272
302
  * Fork the project.
273
303
  * Make your feature addition or bug fix.
274
304
  * Add tests for it. This is important so I don't break it in a future version unintentionally.
275
- * Commit, do not mess with rakefile, version, or history.
305
+ * Commit, do not mess with rakefile, version, or changelog.
276
306
  (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
277
307
  * Send me a pull request. Bonus points for topic branches.
278
308
 
@@ -6,8 +6,7 @@ module Tabletastic
6
6
  klass = default_class_for(collection)
7
7
  options = args.extract_options!
8
8
  initialize_html_options(options, klass)
9
- result = block.call(TableBuilder.new(collection, klass, self))
10
-
9
+ result = capture { block.call(TableBuilder.new(collection, klass, self)) }
11
10
  content_tag(:table, result, options[:html])
12
11
  end
13
12
 
@@ -1,3 +1,3 @@
1
1
  module Tabletastic
2
- VERSION = "0.2.0.pre4"
2
+ VERSION = "0.2.0.pre5"
3
3
  end
data/spec/spec_helper.rb CHANGED
@@ -30,11 +30,10 @@ Spork.prefork do
30
30
  include ActionView::Helpers::TagHelper
31
31
  include ActionView::Helpers::TextHelper
32
32
  include ActionView::Helpers::ActiveModelHelper
33
- include ActionView::Helpers::RecordIdentificationHelper
34
33
  include ActionView::Helpers::RecordTagHelper
35
34
  include ActionView::Helpers::CaptureHelper
36
35
  include ActionView::Helpers::RawOutputHelper
37
- include ActionController::PolymorphicRoutes
36
+ include ActionDispatch::Routing::PolymorphicRoutes
38
37
 
39
38
  def self.included(base)
40
39
  base.class_eval do
@@ -42,6 +41,10 @@ Spork.prefork do
42
41
  end
43
42
  end
44
43
 
44
+ def reset_output_buffer!
45
+ @output_buffer = ActionView::OutputBuffer.new
46
+ end
47
+
45
48
  module ::RspecTagMatchers
46
49
  def have_table_with_tag(selector, inner_text_or_options = nil, options = {}, &block)
47
50
  HaveTag.new("table", nil, {}) &&
@@ -3,8 +3,7 @@ require 'spec_helper'
3
3
  describe Tabletastic::TableBuilder do
4
4
 
5
5
  before do
6
- @output_buffer = ActiveSupport::SafeBuffer.new
7
-
6
+ reset_output_buffer!
8
7
  mock_everything
9
8
  ::Post.stub!(:content_columns).and_return([mock('column', :name => 'title'), mock('column', :name => 'body'), mock('column', :name => 'created_at')])
10
9
  @post.stub!(:title).and_return("The title of the post")
@@ -17,7 +16,7 @@ describe Tabletastic::TableBuilder do
17
16
  context "without a block" do
18
17
  context "with no other arguments" do
19
18
  before do
20
- concat table_for(@posts) { |t| t.data }
19
+ concat(table_for(@posts) { |t| t.data })
21
20
  end
22
21
 
23
22
  it "should output table with id of the class of the collection" do
@@ -61,19 +60,17 @@ describe Tabletastic::TableBuilder do
61
60
  end
62
61
 
63
62
  it "should cycle row classes" do
64
- @output_buffer = ""
63
+ reset_output_buffer!
65
64
  @posts = [@post, @post]
66
- table_for(@posts) do |t|
67
- concat(t.data)
68
- end
65
+ concat(
66
+ table_for(@posts) do |t|
67
+ concat(t.data)
68
+ end)
69
69
  output_buffer.should have_table_with_tag("tr.odd")
70
70
  output_buffer.should have_table_with_tag("tr.even")
71
71
  end
72
72
 
73
73
  context "when collection has associations" do
74
- before do
75
- @output_buffer = ActiveSupport::SafeBuffer.new
76
- end
77
74
  it "should handle belongs_to associations" do
78
75
  ::Post.stub!(:reflect_on_all_associations).with(:belongs_to).and_return([@mock_reflection_belongs_to_author])
79
76
  @posts = [@freds_post]
@@ -92,49 +89,49 @@ describe Tabletastic::TableBuilder do
92
89
 
93
90
  context "with options[:actions]" do
94
91
  it "includes path to post for :show" do
95
- table_for(@posts) do |t|
96
- concat(t.data(:actions => :show))
97
- end
92
+ concat(table_for(@posts) do |t|
93
+ t.data(:actions => :show)
94
+ end)
98
95
  output_buffer.should have_table_with_tag("a[@href=\"/posts/#{@post.id}\"]")
99
96
  output_buffer.should have_table_with_tag("th", "")
100
97
  end
101
98
 
102
99
  it "should have a cell with default class 'actions' and the action name" do
103
- table_for(@posts) do |t|
104
- concat(t.data(:actions => :show))
105
- end
100
+ concat(table_for(@posts) do |t|
101
+ t.data(:actions => :show)
102
+ end)
106
103
  output_buffer.should have_tag("td.actions.show_link") do |td|
107
104
  td.should have_tag("a")
108
105
  end
109
106
  end
110
107
 
111
108
  it "includes path to post for :edit" do
112
- table_for(@posts) do |t|
113
- concat(t.data(:actions => :edit))
114
- end
109
+ concat(table_for(@posts) do |t|
110
+ t.data(:actions => :edit)
111
+ end)
115
112
  output_buffer.should have_tag("a[@href=\"/posts/#{@post.id}/edit\"]", "Edit")
116
113
  end
117
114
 
118
115
  it "includes path to post for :destroy" do
119
- table_for(@posts) do |t|
120
- concat(t.data(:actions => :destroy))
121
- end
116
+ concat(table_for(@posts) do |t|
117
+ t.data(:actions => :destroy)
118
+ end)
122
119
  output_buffer.should have_table_with_tag("a[@href=\"/posts/#{@post.id}\"]")
123
120
  output_buffer.should have_table_with_tag("th", "")
124
121
  end
125
122
 
126
123
  it "includes path to post for :show and :edit" do
127
- table_for(@posts) do |t|
128
- concat(t.data(:actions => [:show, :edit]))
129
- end
124
+ concat(table_for(@posts) do |t|
125
+ t.data(:actions => [:show, :edit])
126
+ end)
130
127
  output_buffer.should have_tag("td:nth-child(3) a[@href=\"/posts/#{@post.id}\"]", "Show")
131
128
  output_buffer.should have_tag("td:nth-child(4) a[@href=\"/posts/#{@post.id}/edit\"]", "Edit")
132
129
  end
133
130
 
134
131
  it "includes path to post for :all" do
135
- table_for(@posts) do |t|
136
- concat(t.data(:actions => :all))
137
- end
132
+ concat(table_for(@posts) do |t|
133
+ t.data(:actions => :all)
134
+ end)
138
135
  output_buffer.should have_tag("td:nth-child(3) a[@href=\"/posts/#{@post.id}\"]", "Show")
139
136
  output_buffer.should have_tag("td:nth-child(4) a[@href=\"/posts/#{@post.id}/edit\"]", "Edit")
140
137
  output_buffer.should have_tag("td:nth-child(5) a[@href=\"/posts/#{@post.id}\"]", "Destroy")
@@ -142,30 +139,30 @@ describe Tabletastic::TableBuilder do
142
139
 
143
140
  context "with options[:actions_prefix]" do
144
141
  it "includes path to admin post for :show" do
145
- table_for(@posts) do |t|
146
- concat(t.data(:actions => :show, :action_prefix => :admin))
147
- end
142
+ concat(table_for(@posts) do |t|
143
+ t.data(:actions => :show, :action_prefix => :admin)
144
+ end)
148
145
  output_buffer.should have_tag("td:nth-child(3) a[@href=\"/admin/posts/#{@post.id}\"]", "Show")
149
146
  end
150
147
 
151
148
  it "includes path to admin post for :edit" do
152
- table_for(@posts) do |t|
153
- concat(t.data(:actions => :edit, :action_prefix => :admin))
154
- end
149
+ concat(table_for(@posts) do |t|
150
+ t.data(:actions => :edit, :action_prefix => :admin)
151
+ end)
155
152
  output_buffer.should have_tag("td:nth-child(3) a[@href=\"/admin/posts/#{@post.id}/edit\"]", "Edit")
156
153
  end
157
154
 
158
155
  it "includes path to admin post for :destroy" do
159
- table_for(@posts) do |t|
160
- concat(t.data(:actions => :destroy, :action_prefix => :admin))
161
- end
156
+ concat(table_for(@posts) do |t|
157
+ t.data(:actions => :destroy, :action_prefix => :admin)
158
+ end)
162
159
  output_buffer.should have_tag("td:nth-child(3) a[@href=\"/admin/posts/#{@post.id}\"]", "Destroy")
163
160
  end
164
161
 
165
162
  it "includes path to admin for all actions" do
166
- table_for(@posts) do |t|
163
+ concat(table_for(@posts) do |t|
167
164
  concat(t.data(:actions => :all, :action_prefix => :admin))
168
- end
165
+ end)
169
166
  output_buffer.should have_tag("td:nth-child(3) a[@href=\"/admin/posts/#{@post.id}\"]", "Show")
170
167
  output_buffer.should have_tag("td:nth-child(4) a[@href=\"/admin/posts/#{@post.id}/edit\"]", "Edit")
171
168
  output_buffer.should have_tag("td:nth-child(5) a[@href=\"/admin/posts/#{@post.id}\"]", "Destroy")
@@ -175,9 +172,9 @@ describe Tabletastic::TableBuilder do
175
172
 
176
173
  context "with a list of attributes" do
177
174
  before do
178
- table_for(@posts) do |t|
179
- concat(t.data(:title, :created_at))
180
- end
175
+ concat(table_for(@posts) do |t|
176
+ t.data(:title, :created_at)
177
+ end)
181
178
  end
182
179
 
183
180
  it "should call each method passed in, and only those methods" do
@@ -189,9 +186,9 @@ describe Tabletastic::TableBuilder do
189
186
 
190
187
  context "with a list of attributes and options[:actions]" do
191
188
  it "includes path to post for :show" do
192
- table_for(@posts) do |t|
189
+ concat(table_for(@posts) do |t|
193
190
  concat(t.data(:title, :created_at, :actions => :show))
194
- end
191
+ end)
195
192
  output_buffer.should have_tag("th:nth-child(1)", "Title")
196
193
  output_buffer.should have_tag("th:nth-child(2)", "Created at")
197
194
  output_buffer.should have_tag("th:nth-child(3)", "")
@@ -317,7 +314,7 @@ describe Tabletastic::TableBuilder do
317
314
  context "when table_for is not passed a block" do
318
315
  it "the data should use the default option" do
319
316
  Tabletastic.default_table_block = lambda {|table| table.data}
320
- concat table_for(@posts)
317
+ concat( table_for(@posts) )
321
318
  output_buffer.should have_table_with_tag("td", "The title of the post")
322
319
  end
323
320
  end
@@ -3,7 +3,7 @@ require 'spec_helper'
3
3
  describe "Tabletastic#table_for" do
4
4
 
5
5
  before do
6
- @output_buffer = ActiveSupport::SafeBuffer.new
6
+ reset_output_buffer!
7
7
  end
8
8
 
9
9
  describe "basics" do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tabletastic
3
3
  version: !ruby/object:Gem::Version
4
- hash: -1876988177
4
+ hash: -1876988180
5
5
  prerelease: true
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
9
  - 0
10
- - pre4
11
- version: 0.2.0.pre4
10
+ - pre5
11
+ version: 0.2.0.pre5
12
12
  platform: ruby
13
13
  authors:
14
14
  - Joshua Davey
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2010-07-18 00:00:00 -05:00
19
+ date: 2010-08-02 00:00:00 -05:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
@@ -27,13 +27,13 @@ dependencies:
27
27
  requirements:
28
28
  - - ">="
29
29
  - !ruby/object:Gem::Version
30
- hash: -1848230024
30
+ hash: 7712042
31
31
  segments:
32
32
  - 3
33
33
  - 0
34
34
  - 0
35
- - beta4
36
- version: 3.0.0.beta4
35
+ - rc
36
+ version: 3.0.0.rc
37
37
  type: :runtime
38
38
  version_requirements: *id001
39
39
  - !ruby/object:Gem::Dependency