public this repo is viewable by everyone
Description: Ruby on Rails
Homepage: http://rubyonrails.org
Clone URL: git://github.com/rails/rails.git
Provide a helper proxy to access helper methods from outside views. Closes 
#10839 [Josh Peek]


git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@9234 
5ecf4fe2-1ee6-0310-87b1-e25e094e27de
josh (author)
about 1 month ago
commit  917423d664038d6791738a73ad1446437dbb71df
tree    bda3e8810f16831767e69102db409152695ea523
parent  5b822aca4b6524c9147224764ec0f20a728ba2a1
...
1
2
 
 
 
3
4
5
...
1
2
3
4
5
6
7
8
0
@@ -1,5 +1,8 @@
0
 *SVN*
0
 
0
+* Provide a helper proxy to access helper methods from outside views. Closes #10839 [Josh Peek]
0
+ e.g. ApplicationController.helpers.simple_format(text)
0
+
0
 * Improve documentation. [Xavier Noria, leethal, jerome]
0
 
0
 * Ensure RJS redirect_to doesn't html-escapes string argument. Closes #8546 [josh, eventualbuddha, Pratik]
...
167
168
169
 
 
 
 
 
 
 
 
 
170
171
172
...
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
0
@@ -167,6 +167,15 @@ module ActionController #:nodoc:
0
         attrs.flatten.each { |attr| helper_method(attr, "#{attr}=") }
0
       end
0
 
0
+ # Provides a proxy to access helpers methods from outside the view.
0
+ def helpers
0
+ unless @helper_proxy
0
+ @helper_proxy = ActionView::Base.new
0
+ @helper_proxy.extend master_helper_module
0
+ else
0
+ @helper_proxy
0
+ end
0
+ end
0
 
0
       private
0
         def default_helper_module!
...
130
131
132
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
133
134
135
...
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
0
@@ -130,6 +130,22 @@ class HelperTest < Test::Unit::TestCase
0
     assert methods.include?('foobar')
0
   end
0
 
0
+ def test_helper_proxy
0
+ methods = ApplicationController.helpers.methods.map(&:to_s)
0
+
0
+ # ActionView
0
+ assert methods.include?('pluralize')
0
+
0
+ # abc_helper.rb
0
+ assert methods.include?('bare_a')
0
+
0
+ # fun/games_helper.rb
0
+ assert methods.include?('stratego')
0
+
0
+ # fun/pdf_helper.rb
0
+ assert methods.include?('foobar')
0
+ end
0
+
0
   private
0
     def expected_helper_methods
0
       TestHelper.instance_methods.map(&:to_s)

Comments

    No one has commented yet.