Skip to content

Commit

Permalink
Fix bug to render template in context of caller
Browse files Browse the repository at this point in the history
  • Loading branch information
Joe Fiorini committed Feb 6, 2010
1 parent 767effd commit 2883ffe
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/totally_tabular/table_view.rb
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
20 changes: 20 additions & 0 deletions spec/lib/totally_tabular/table_view_spec.rb
Expand Up @@ -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.