diff options
author | Gonçalo Silva <goncalossilva@gmail.com> | 2011-05-08 03:54:55 +0100 |
---|---|---|
committer | Gonçalo Silva <goncalossilva@gmail.com> | 2011-05-08 03:54:55 +0100 |
commit | aec7456f81985b88d6d604679d754636183b5b3a (patch) | |
tree | 798fcab8ae0c6e2c8c5a63e1f39308ff4bb5a20c /railties/lib/rails/engine.rb | |
parent | 1c2b2233c3a7ec76c0a0eddf5b8be45c489be133 (diff) | |
parent | 70f9558d0e4b8e605576693cbb489caa5cf6a2bc (diff) | |
download | rails-aec7456f81985b88d6d604679d754636183b5b3a.tar.gz rails-aec7456f81985b88d6d604679d754636183b5b3a.tar.bz2 rails-aec7456f81985b88d6d604679d754636183b5b3a.zip |
Merge branch 'master' of https://github.com/rails/rails into performance_test
Conflicts:
activesupport/lib/active_support/testing/performance.rb
Diffstat (limited to 'railties/lib/rails/engine.rb')
-rw-r--r-- | railties/lib/rails/engine.rb | 71 |
1 files changed, 55 insertions, 16 deletions
diff --git a/railties/lib/rails/engine.rb b/railties/lib/rails/engine.rb index 87385814f7..2015a944f0 100644 --- a/railties/lib/rails/engine.rb +++ b/railties/lib/rails/engine.rb @@ -92,17 +92,17 @@ module Rails # The available paths in an engine are: # # class MyEngine < Rails::Engine - # paths["app"] #=> ["app"] - # paths["app/controllers"] #=> ["app/controllers"] - # paths["app/helpers"] #=> ["app/helpers"] - # paths["app/models"] #=> ["app/models"] - # paths["app/views"] #=> ["app/views"] - # paths["lib"] #=> ["lib"] - # paths["lib/tasks"] #=> ["lib/tasks"] - # paths["config"] #=> ["config"] - # paths["config/initializers"] #=> ["config/initializers"] - # paths["config/locales"] #=> ["config/locales"] - # paths["config/routes"] #=> ["config/routes.rb"] + # paths["app"] # => ["app"] + # paths["app/controllers"] # => ["app/controllers"] + # paths["app/helpers"] # => ["app/helpers"] + # paths["app/models"] # => ["app/models"] + # paths["app/views"] # => ["app/views"] + # paths["lib"] # => ["lib"] + # paths["lib/tasks"] # => ["lib/tasks"] + # paths["config"] # => ["config"] + # paths["config/initializers"] # => ["config/initializers"] + # paths["config/locales"] # => ["config/locales"] + # paths["config/routes"] # => ["config/routes.rb"] # end # # Your <tt>Application</tt> class adds a couple more paths to this set. And as in your @@ -234,14 +234,14 @@ module Rails # use the prefix "my_engine". In an isolated engine, the prefix will be omitted in url helpers and # form fields for convenience. # - # polymorphic_url(MyEngine::Article.new) #=> "articles_path" + # polymorphic_url(MyEngine::Article.new) # => "articles_path" # # form_for(MyEngine::Article.new) do - # text_field :title #=> <input type="text" name="article[title]" id="article_title" /> + # text_field :title # => <input type="text" name="article[title]" id="article_title" /> # end # - # Additionally isolated engine will set its name according to namespace, so - # MyEngine::Engine.engine_name #=> "my_engine". It will also set MyEngine.table_name_prefix + # Additionally an isolated engine will set its name according to namespace, so + # MyEngine::Engine.engine_name will be "my_engine". It will also set MyEngine.table_name_prefix # to "my_engine_", changing MyEngine::Article model to use my_engine_article table. # # == Using Engine's routes outside Engine @@ -250,7 +250,7 @@ module Rails # <tt>url_helpers</tt> inside +Application+. When you mount an engine in an application's routes, a special helper is # created to allow you to do that. Consider such a scenario: # - # # APP/config/routes.rb + # # config/routes.rb # MyApplication::Application.routes.draw do # mount MyEngine::Engine => "/my_engine", :as => "my_engine" # match "/foo" => "foo#index" @@ -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.all_helpers_from_path(helpers_paths) + ActionController::Base.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) |