@@ -123,11 +123,6 @@ def length
123
123
routes . length
124
124
end
125
125
126
- def install ( destinations = [ ActionController ::Base , ActionView ::Base ] )
127
- helper = @module
128
- destinations . each { |d | d . module_eval { include helper } }
129
- end
130
-
131
126
private
132
127
def url_helper_name ( name , kind = :url )
133
128
:"#{ name } _#{ kind } "
@@ -276,14 +271,15 @@ def clear!
276
271
@prepend . each { |blk | eval_block ( blk ) }
277
272
end
278
273
279
- def install_helpers ( destinations )
280
- destinations . each { |d | d . module_eval { include Helpers } }
281
- named_routes . install ( destinations )
282
- end
283
-
284
- module MountedHelpers
274
+ module MountedHelpers #:nodoc:
275
+ extend ActiveSupport ::Concern
276
+ include UrlFor
285
277
end
286
278
279
+ # Contains all the mounted helpers accross different
280
+ # engines and the `main_app` helper for the application.
281
+ # You can include this in your classes if you want to
282
+ # access routes for other engines.
287
283
def mounted_helpers
288
284
MountedHelpers
289
285
end
@@ -294,7 +290,7 @@ def define_mounted_helper(name)
294
290
routes = self
295
291
MountedHelpers . class_eval do
296
292
define_method "_#{ name } " do
297
- RoutesProxy . new ( routes , self . _routes_context )
293
+ RoutesProxy . new ( routes , _routes_context )
298
294
end
299
295
end
300
296
@@ -306,29 +302,40 @@ def #{name}
306
302
end
307
303
308
304
def url_helpers
309
- routes = self
305
+ @url_helpers ||= begin
306
+ routes = self
307
+
308
+ Module . new do
309
+ extend ActiveSupport ::Concern
310
+ include UrlFor
311
+
312
+ # Define url_for in the singleton level so one can do:
313
+ # Rails.application.routes.url_helpers.url_for(args)
314
+ @_routes = routes
315
+ class << self
316
+ delegate :url_for , :to => '@_routes'
317
+ end
310
318
311
- @url_helpers ||= Module . new {
312
- extend ActiveSupport ::Concern
313
- include UrlFor
319
+ # Make named_routes available in the module singleton
320
+ # as well, so one can do:
321
+ # Rails.application.routes.url_helpers.posts_path
322
+ extend routes . named_routes . module
314
323
315
- @_routes = routes
316
- def self . url_for ( options )
317
- @_routes . url_for options
318
- end
324
+ # Any class that includes this module will get all
325
+ # named routes...
326
+ include routes . named_routes . module
319
327
320
- extend routes . named_routes . module
328
+ # plus a singleton class method called _routes ...
329
+ included do
330
+ singleton_class . send ( :redefine_method , :_routes ) { routes }
331
+ end
321
332
322
- # ROUTES TODO: install_helpers isn't great... can we make a module with the stuff that
323
- # we can include?
324
- # Yes plz - JP
325
- included do
326
- routes . install_helpers ( [ self ] )
327
- singleton_class . send ( :redefine_method , :_routes ) { routes }
333
+ # And an instance method _routes. Note that
334
+ # UrlFor (included in this module) add extra
335
+ # conveniences for working with @_routes.
336
+ define_method ( :_routes ) { @_routes || routes }
328
337
end
329
-
330
- define_method ( :_routes ) { @_routes || routes }
331
- }
338
+ end
332
339
end
333
340
334
341
def empty?
0 commit comments