Skip to content

Commit

Permalink
Using row_class outside of data block makes more sense [jgdavey#21, j…
Browse files Browse the repository at this point in the history
  • Loading branch information
jesjos committed Mar 21, 2013
1 parent 964a7fd commit 94740f7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 18 deletions.
19 changes: 13 additions & 6 deletions README.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -238,21 +238,28 @@ will product html like:
</tbody>
</table>

For that last extra squeeze of micro-management, you can use the data block to customize row classes with a block:
For that last extra squeeze of micro-management, you can pass in a block to customize row classes with a block:
<%= table_for(@posts) do |t|
t.data do
t.row_class { |post| post.title }
end
t.row_class { |post| post.title }
end %>

Or with a string
Or with a string:

<%= table_for(@posts) do |t|
t.row_class("foobar")
t.data do
t.row_class("foobar")
t.cell(:title)
end
end %>

You can also choose to omit the odd and even classes:

<%= table_for(@posts) do |t|
t.row_class(odd_even: false) { |post| post.title }
t.data do
t.cell(:title)
end
end %>


If it _still_ isn't flexible enough for your needs, it might be time to return to static html/erb.
Expand Down
20 changes: 8 additions & 12 deletions spec/tabletastic/table_builder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -260,9 +260,8 @@
context "and string" do
before do
concat(table_for(@posts) do |t|
t.data do
t.row_class("foo")
end
t.row_class("foo")
t.data
end)
end

Expand All @@ -273,9 +272,8 @@
context "and a block" do
before do
concat(table_for(@posts) do |t|
t.data do
t.row_class { |post| post.foo }
end
t.row_class { |post| post.foo }
t.data
end)
end

Expand All @@ -289,9 +287,8 @@
context "and a block" do
before do
concat(table_for(@posts) do |t|
t.data do
t.row_class(odd_even: false) { |post| post.foo }
end
t.row_class(odd_even: false) { |post| post.foo }
t.data
end)
end

Expand All @@ -303,9 +300,8 @@
context "and string" do
before do
concat(table_for(@posts) do |t|
t.data do
t.row_class("foo", odd_even: false)
end
t.row_class("foo", odd_even: false)
t.data
end)
end

Expand Down

0 comments on commit 94740f7

Please sign in to comment.