Skip to content

Commit

Permalink
Adding in #localize.
Browse files Browse the repository at this point in the history
  • Loading branch information
steveklabnik committed Feb 22, 2012
1 parent 49952ff commit de2d62c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/draper/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -151,14 +151,22 @@ def self.last(options = {})
end

# Access the helpers proxy to call built-in and user-defined
# Rails helpers. Aliased to `.h` for convinience.
# Rails helpers. Aliased to `.h` for convenience.
#
# @return [Object] proxy
def helpers
self.class.helpers
end
alias :h :helpers

# Localize is something that's used quite often. Even though
# it's available through helpers, that's annoying. Aliased
# to `.l` for convenience.
def localize(str)
self.class.helpers.localize(str)
end
alias :l :localize

# Access the helpers proxy to call built-in and user-defined
# Rails helpers from a class context.
#
Expand Down
6 changes: 6 additions & 0 deletions spec/draper/base_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,12 @@ class DecoratorWithDeniesAndAllows < Draper::Base
it "should be able to use the pluralize helper" do
decorator.sample_truncate.should == "Once..."
end

it "should be able to use l rather than helpers.l" do
now = Time.now
decorator.helpers.should_receive(:localize).with(now)
decorator.l now
end
end

describe "#method_missing" do
Expand Down

0 comments on commit de2d62c

Please sign in to comment.