Permalink
Browse files

Define class on row

  • Loading branch information...
1 parent 4a8b984 commit 5d0805c3a294a5d9e2a82753706f51d2984b4f78 Joe Fiorini committed Jan 16, 2010
@@ -1,10 +1,11 @@
module TotallyTabular
class Column
- attr_accessor :name, :template, :header_attributes
+ attr_accessor :name, :template, :header_attributes, :row_attributes
def initialize(name)
@name = name
@header_attributes = {}
+ @row_attributes = {}
end
def template!(&block)
@@ -15,5 +16,9 @@ def header_attributes!(attributes={})
@header_attributes = attributes
end
+ def row_attributes!(attributes={})
+ @row_attributes = attributes
+ end
+
end
end
@@ -37,7 +37,9 @@ def options
def build_rows(collection, columns)
collection.map do |item|
row = Row.new
+ row_attributes = nil
row.render(columns.map do |column|
+ row.attributes!(column.row_attributes)
@helper.content_tag(:td, column.template.call(item, row))
end.join)
end
@@ -104,6 +104,18 @@ def selector(string, selector)
selector(t.render, "table th.blahdiddy").length.should == 1
end
+ it "allows defining a class on row" do
+ t = TableView.new([1]) do
+ define_column("Blah") do
+ row_attributes!(:class => 'diddy')
+ template! do |o, row|
+ end
+ end
+ end
+
+ selector(t.render, "table tr.diddy").length.should == 1
+ end
+
it "should take a block and give a table class" do
table = TableView::Table.new
TableView::Table.stub!(:new).and_return(table)

0 comments on commit 5d0805c

Please sign in to comment.