Permalink
Browse files

Adding in #localize.

Closes #132
  • Loading branch information...
steveklabnik committed Feb 22, 2012
1 parent 49952ff commit de2d62c75af1fcd0144d9f3e2566993b2a448b53
Showing with 15 additions and 1 deletion.
  1. +9 −1 lib/draper/base.rb
  2. +6 −0 spec/draper/base_spec.rb
View
@@ -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.
#
View
@@ -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

0 comments on commit de2d62c

Please sign in to comment.