diff options
author | Piotr Sarnacki <drogus@gmail.com> | 2011-04-25 13:12:07 +0200 |
---|---|---|
committer | Piotr Sarnacki <drogus@gmail.com> | 2011-04-25 13:44:27 +0200 |
commit | e38b4436a57c43d2db78a4c8a647a09fe0e5d2c5 (patch) | |
tree | ed59432bcdf0343a83b3c40364c13969c3d563ea /railties/lib | |
parent | 723a0f82c48e4aa7987c6ccf653b4e543a0d3715 (diff) | |
download | rails-e38b4436a57c43d2db78a4c8a647a09fe0e5d2c5.tar.gz rails-e38b4436a57c43d2db78a4c8a647a09fe0e5d2c5.tar.bz2 rails-e38b4436a57c43d2db78a4c8a647a09fe0e5d2c5.zip |
Add Engine#helpers method which loads all the engine's helpers
Diffstat (limited to 'railties/lib')
-rw-r--r-- | railties/lib/rails/engine.rb | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/railties/lib/rails/engine.rb b/railties/lib/rails/engine.rb index 87385814f7..fbd474fa1b 100644 --- a/railties/lib/rails/engine.rb +++ b/railties/lib/rails/engine.rb @@ -286,6 +286,27 @@ module Rails # # This code will use <tt>my_engine.user_path(@user)</tt> to generate the proper route. # + # == Isolated engine's helpers + # + # Sometimes you may want to isolate engine, but use helpers that are defined for it. + # If you want to share just a few specific helpers you can add them to application's + # helpers in ApplicationController: + # + # class ApplicationController < ActionController::Base + # helper MyEngine::SharedEngineHelper + # end + # + # If you want to include all of the engine's helpers, you can use #helpers method on egine's + # instance: + # + # class ApplicationController < ActionController::Base + # helper MyEngine::Engine.helpers + # end + # + # It will include all of the helpers from engine's directory. Take into account that this does + # not include helpers defined in controllers with helper_method or other similar solutions, + # only helpers defined in helpers directory will be included. + # # == Migrations & seed data # # Engines can have their own migrations. The default path for migrations is exactly the same @@ -384,6 +405,24 @@ module Rails @railties ||= self.class::Railties.new(config) end + def helpers + @helpers ||= begin + helpers = Module.new + + helpers_paths = if config.respond_to?(:helpers_paths) + config.helpers_paths + else + paths["app/helpers"].existent + end + + all = ActionController::Base.send(:all_helpers_from_path, helpers_paths) + ActionController::Base.send(:modules_for_helpers, all).each do |mod| + helpers.send(:include, mod) + end + helpers + end + end + def app @app ||= begin config.middleware = config.middleware.merge_into(default_middleware_stack) |