Adding in #localize.

Closes #132
This commit is contained in:
Steve Klabnik 2012-02-22 12:22:54 -05:00
parent 49952fff8c
commit de2d62c75a
2 changed files with 15 additions and 1 deletions

View File

@ -151,7 +151,7 @@ module Draper
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
@ -159,6 +159,14 @@ module Draper
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.
#

View File

@ -597,6 +597,12 @@ describe Draper::Base do
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