Permalink
Browse files

Push ability to use procs for labels.

  • Loading branch information...
1 parent 55a1cc7 commit f76decdcd10480498e2b43773ba7831dd0c6cde0 @bobbytables committed Jan 11, 2013
Showing with 14 additions and 5 deletions.
  1. +6 −2 lib/table_cloth/column.rb
  2. +1 −1 lib/table_cloth/presenter.rb
  3. +7 −2 spec/lib/column_spec.rb
@@ -15,8 +15,12 @@ def value(object, view, table=nil)
end
end
- def human_name
- options[:label] || name.to_s.humanize
+ def human_name(view)
+ if options[:label].kind_of? Proc
+ view.instance_exec(&options[:label])
+ else
+ options[:label] || name.to_s.humanize
+ end
end
end
end
@@ -36,7 +36,7 @@ def columns
def column_names
@column_names ||= columns.each_with_object([]) do |column, names|
- names << column.human_name
+ names << column.human_name(view_context)
end
end
View
@@ -25,12 +25,17 @@
context "human name" do
it "returns the label when set" do
column = FactoryGirl.build(:column, options: { label: "Whatever" })
- expect(column.human_name).to eq("Whatever")
+ expect(column.human_name(view_context)).to eq("Whatever")
end
it "humanizes the symbol if no label is set" do
column = FactoryGirl.build(:column, name: :email)
- expect(column.human_name).to eq("Email")
+ expect(column.human_name(view_context)).to eq("Email")
+ end
+
+ it "runs with a proc" do
+ column = FactoryGirl.build(:column, options: { label: Proc.new{ tag :span }} )
+ expect(column.human_name(view_context)).to eq("<span />")
end
end
end

0 comments on commit f76decd

Please sign in to comment.