From 6c95e0f879aafa5921cd7898d5951b9a926d3c9a Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Sun, 18 Jul 2010 19:49:51 +0200 Subject: Add mounted_helpers to routes mounted_helpers are a bit similar to url_helpers. They're automatically included in controllers for Rails.application and each of mounted Engines. Mounted helper allows to call url_for and named helpers for given application. Given Blog::Engine mounted as blog_engine, there are 2 helpers defined: app and blog_engine. You can call routes for app and engine using those helpers: app.root_url app.url_for(:controller => "foo") blog_engine.posts_path blog_engine.url_for(@post) --- .../lib/action_controller/railties/url_helpers.rb | 26 ++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 actionpack/lib/action_controller/railties/url_helpers.rb (limited to 'actionpack/lib/action_controller/railties') diff --git a/actionpack/lib/action_controller/railties/url_helpers.rb b/actionpack/lib/action_controller/railties/url_helpers.rb new file mode 100644 index 0000000000..3e6f211cda --- /dev/null +++ b/actionpack/lib/action_controller/railties/url_helpers.rb @@ -0,0 +1,26 @@ +module ActionController + module Railties + + module UrlHelpers + def self.with(routes) + Module.new do + define_method(:inherited) do |klass| + super(klass) + klass.send(:include, routes.url_helpers) + end + end + end + end + + module MountedHelpers + def self.with(routes, name = nil) + Module.new do + define_method(:inherited) do |klass| + super(klass) + klass.send(:include, routes.mounted_helpers(name)) + end + end + end + end + end +end -- cgit v1.2.3 From 2734d3819f4621bf797ea436d267b102deae67f7 Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Thu, 29 Jul 2010 20:29:57 +0200 Subject: This is not needed --- .../lib/action_controller/railties/url_helpers.rb | 26 ---------------------- 1 file changed, 26 deletions(-) delete mode 100644 actionpack/lib/action_controller/railties/url_helpers.rb (limited to 'actionpack/lib/action_controller/railties') diff --git a/actionpack/lib/action_controller/railties/url_helpers.rb b/actionpack/lib/action_controller/railties/url_helpers.rb deleted file mode 100644 index 3e6f211cda..0000000000 --- a/actionpack/lib/action_controller/railties/url_helpers.rb +++ /dev/null @@ -1,26 +0,0 @@ -module ActionController - module Railties - - module UrlHelpers - def self.with(routes) - Module.new do - define_method(:inherited) do |klass| - super(klass) - klass.send(:include, routes.url_helpers) - end - end - end - end - - module MountedHelpers - def self.with(routes, name = nil) - Module.new do - define_method(:inherited) do |klass| - super(klass) - klass.send(:include, routes.mounted_helpers(name)) - end - end - end - end - end -end -- cgit v1.2.3 From c7664d112fadb313146da33f48d1da318f249927 Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Fri, 30 Jul 2010 07:14:48 +0200 Subject: Include application's helpers and router helpers by default, but include engine's ones for controllers inside isolated namespace --- .../lib/action_controller/railties/routes_helpers.rb | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 actionpack/lib/action_controller/railties/routes_helpers.rb (limited to 'actionpack/lib/action_controller/railties') diff --git a/actionpack/lib/action_controller/railties/routes_helpers.rb b/actionpack/lib/action_controller/railties/routes_helpers.rb new file mode 100644 index 0000000000..a23f703f0b --- /dev/null +++ b/actionpack/lib/action_controller/railties/routes_helpers.rb @@ -0,0 +1,17 @@ +module ActionController + module Railties + module RoutesHelpers + def self.with(routes) + Module.new do + define_method(:inherited) do |klass| + super(klass) + if namespace = klass.parents.detect {|m| m.respond_to?(:_railtie) } + routes = namespace._railtie.routes + end + klass.send(:include, routes.url_helpers) + end + end + end + end + end +end -- cgit v1.2.3 From 4131a2d804c54960ac70984e7453069fe8688365 Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Mon, 2 Aug 2010 17:38:44 +0200 Subject: Move ActionController::Railties::RoutesHelpers and ActionMailer::Railties::RoutesHelper to AbstractController::Railties::RoutesHelpers --- .../lib/action_controller/railties/routes_helpers.rb | 17 ----------------- 1 file changed, 17 deletions(-) delete mode 100644 actionpack/lib/action_controller/railties/routes_helpers.rb (limited to 'actionpack/lib/action_controller/railties') diff --git a/actionpack/lib/action_controller/railties/routes_helpers.rb b/actionpack/lib/action_controller/railties/routes_helpers.rb deleted file mode 100644 index a23f703f0b..0000000000 --- a/actionpack/lib/action_controller/railties/routes_helpers.rb +++ /dev/null @@ -1,17 +0,0 @@ -module ActionController - module Railties - module RoutesHelpers - def self.with(routes) - Module.new do - define_method(:inherited) do |klass| - super(klass) - if namespace = klass.parents.detect {|m| m.respond_to?(:_railtie) } - routes = namespace._railtie.routes - end - klass.send(:include, routes.url_helpers) - end - end - end - end - end -end -- cgit v1.2.3 From e5af8b7d85abb94f21f4e873c1c267e27be2aad8 Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Fri, 6 Aug 2010 16:34:48 +0200 Subject: Moved ActionMailer and ActionController railties options to inherited hook This change is needed, because we must take namespace into account and if controller's/mailer's class is namespaced, engine's paths should be set instead of application's ones. The nice side effect of this is removing unneeded logic in ActionController::Base.inherited - now the helpers_path should be set correctly even for engine's controllers, so helper(:all) will always include correct helpers. --- actionpack/lib/action_controller/railties/paths.rb | 28 ++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 actionpack/lib/action_controller/railties/paths.rb (limited to 'actionpack/lib/action_controller/railties') diff --git a/actionpack/lib/action_controller/railties/paths.rb b/actionpack/lib/action_controller/railties/paths.rb new file mode 100644 index 0000000000..095beb7a2f --- /dev/null +++ b/actionpack/lib/action_controller/railties/paths.rb @@ -0,0 +1,28 @@ +module ActionController + module Railties + module Paths + def self.with(_app) + Module.new do + define_method(:inherited) do |klass| + super(klass) + if namespace = klass.parents.detect {|m| m.respond_to?(:_railtie) } + app = namespace._railtie + else + app = _app + end + + paths = app.config.paths + options = app.config.action_controller + + options.assets_dir ||= paths.public.to_a.first + options.javascripts_dir ||= paths.public.javascripts.to_a.first + options.stylesheets_dir ||= paths.public.stylesheets.to_a.first + options.page_cache_directory ||= paths.public.to_a.first + options.helpers_path ||= paths.app.helpers.to_a + options.each { |k,v| klass.send("#{k}=", v) } + end + end + end + end + end +end -- cgit v1.2.3 From 98ab4ded376c3d04540bdbdfe6dbbf88c0738701 Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Mon, 23 Aug 2010 18:31:29 +0200 Subject: Set only helpers_path on inherited hook in action_controller/railtie.rb and use helper(:all) just after that --- actionpack/lib/action_controller/railties/paths.rb | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'actionpack/lib/action_controller/railties') diff --git a/actionpack/lib/action_controller/railties/paths.rb b/actionpack/lib/action_controller/railties/paths.rb index 095beb7a2f..81d03f5e73 100644 --- a/actionpack/lib/action_controller/railties/paths.rb +++ b/actionpack/lib/action_controller/railties/paths.rb @@ -14,12 +14,10 @@ module ActionController paths = app.config.paths options = app.config.action_controller - options.assets_dir ||= paths.public.to_a.first - options.javascripts_dir ||= paths.public.javascripts.to_a.first - options.stylesheets_dir ||= paths.public.stylesheets.to_a.first - options.page_cache_directory ||= paths.public.to_a.first options.helpers_path ||= paths.app.helpers.to_a options.each { |k,v| klass.send("#{k}=", v) } + + klass.helper :all end end end -- cgit v1.2.3 From e35c2043b135a95104e3eeb3e12cbcde541fa1b4 Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Mon, 23 Aug 2010 19:25:04 +0200 Subject: Include all helpers from non-namespaced engines --- actionpack/lib/action_controller/railties/paths.rb | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) (limited to 'actionpack/lib/action_controller/railties') diff --git a/actionpack/lib/action_controller/railties/paths.rb b/actionpack/lib/action_controller/railties/paths.rb index 81d03f5e73..e1b318b566 100644 --- a/actionpack/lib/action_controller/railties/paths.rb +++ b/actionpack/lib/action_controller/railties/paths.rb @@ -1,22 +1,16 @@ module ActionController module Railties module Paths - def self.with(_app) + def self.with(app) Module.new do define_method(:inherited) do |klass| super(klass) if namespace = klass.parents.detect {|m| m.respond_to?(:_railtie) } - app = namespace._railtie + klass.helpers_path = namespace._railtie.config.paths.app.helpers.to_a else - app = _app + klass.helpers_path = app.config.helpers_paths end - paths = app.config.paths - options = app.config.action_controller - - options.helpers_path ||= paths.app.helpers.to_a - options.each { |k,v| klass.send("#{k}=", v) } - klass.helper :all end end -- cgit v1.2.3 From 89bd715f6be4235ac7632de10349e9939be04e75 Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Fri, 3 Sep 2010 11:01:24 +0200 Subject: Forgot to move that line to railtie on rebase --- actionpack/lib/action_controller/railties/paths.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/lib/action_controller/railties') diff --git a/actionpack/lib/action_controller/railties/paths.rb b/actionpack/lib/action_controller/railties/paths.rb index e1b318b566..fa71d55946 100644 --- a/actionpack/lib/action_controller/railties/paths.rb +++ b/actionpack/lib/action_controller/railties/paths.rb @@ -11,7 +11,7 @@ module ActionController klass.helpers_path = app.config.helpers_paths end - klass.helper :all + klass.helper :all if klass.superclass == ActionController::Base end end end -- cgit v1.2.3