Permalink
Browse files

instance_eval on column

  • Loading branch information...
1 parent 262718f commit 4a8b9843a18a55166a3a57eac368753972d5e436 Joe Fiorini committed Jan 16, 2010
Showing with 17 additions and 12 deletions.
  1. +5 −0 lib/totally_tabular/column.rb
  2. +1 −2 lib/totally_tabular/table.rb
  3. +11 −10 spec/lib/totally_tabular/table_view_spec.rb
@@ -4,11 +4,16 @@ class Column
def initialize(name)
@name = name
+ @header_attributes = {}
end
def template!(&block)
@template = block
end
+ def header_attributes!(attributes={})
+ @header_attributes = attributes
+ end
+
end
end
@@ -8,8 +8,7 @@ def initialize
def define_column(name, header_attributes={}, &block)
column = Column.new(name)
- block.call(column)
- column.header_attributes = header_attributes
+ column.instance_eval(&block)
@columns << column
end
@@ -63,13 +63,13 @@ def selector(string, selector)
o3 = OpenStruct.new(:name => "Gary", :coolness => "Eh.", :age => 26)
o4 = OpenStruct.new(:name => "Josh", :coolness => "Lame.", :age => 26)
@table_view = TableView.new([o, o2, o3, o4]) do |t|
- t.define_column("Name") do |column|
- column.template! do |o, row|
+ t.define_column("Name") do
+ template! do |o, row|
"%s is %s" % [o.name, o.coolness]
end
end
- t.define_column("Age") do |column|
- column.template! do |o, row|
+ t.define_column("Age") do
+ template! do |o, row|
o.age
end
end
@@ -94,8 +94,9 @@ def selector(string, selector)
it "allows defining class on header" do
t = TableView.new([1]) do
- define_column("Blah", :class => "blahdiddy") do |column|
- column.template! do |o, row|
+ define_column("Blah") do
+ header_attributes!(:class => 'blahdiddy')
+ template! do |o, row|
end
end
end
@@ -117,8 +118,8 @@ def selector(string, selector)
it "should allow me to define a column" do
column_definition = Proc.new do
- define_column("Joe") do |column|
- column.template! do
+ define_column("Joe") do
+ template! do
end
end
end
@@ -129,8 +130,8 @@ def selector(string, selector)
it "should allow defining the column body when defining the column" do
t = TableView.new(["Judge"]) do
- define_column("Name") do |column|
- column.template! do |item, row|
+ define_column("Name") do
+ template! do |item, row|
"My name is %s." % item
end
end

0 comments on commit 4a8b984

Please sign in to comment.