Permalink
Browse files

Fix bug to render template in context of caller

  • Loading branch information...
1 parent 767effd commit 2883ffe3442310dc6a9f19f9efe877219e0b6a20 Joe Fiorini committed Feb 6, 2010
Showing with 22 additions and 1 deletion.
  1. +2 −1 lib/totally_tabular/table_view.rb
  2. +20 −0 spec/lib/totally_tabular/table_view_spec.rb
@@ -8,6 +8,7 @@ class TableView
def initialize(collection, options={}, &block)
@collection = collection
+ @calling_object = options.delete(:self)
@options = options
@column_definition = block
@helper = HtmlHelper.new
@@ -41,7 +42,7 @@ def build_rows(collection, columns)
row.render(columns.map do |column|
column.instance_exec(item, &column.definition)
row.attributes!(column.row_attributes)
- @helper.content_tag(:td, column.template.call(item, row), column.cell_attributes)
+ @helper.content_tag(:td, @calling_object.instance_exec(item, row, &column.template), column.cell_attributes)
end.join)
end
end
@@ -177,4 +177,24 @@ def selector(string, selector)
end
end
+
+ it "should allow me to call other methods in the same class" do
+ class TableHelper
+ def embolden_text(text)
+ "<strong>%s</strong>" % text
+ end
+ def render_table
+ TableView.new(["Teamicil"], :self => self) do
+ define_column("Drugs") do |item|
+ template! do
+ embolden_text(item)
+ end
+ end
+ end.render
+ end
+ end
+ t = ""
+ lambda { t = TableHelper.new.render_table }.should_not raise_error
+ selector(t, "table tr td strong").inner_html.should == "Teamicil"
+ end
end

0 comments on commit 2883ffe

Please sign in to comment.