Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 668 lines (606 sloc) 23.222 kb
b17e358 @josevalim Move configuration to subfolders.
josevalim authored
1 require 'rails/railtie'
812136a @jeremy Fix unstated usage of Pathname
jeremy authored
2 require 'active_support/core_ext/module/delegation'
3 require 'pathname'
53c13f1 @anildigital Use Config::CONFIG['host_os'] instead of RUBY_PLATFORM [#4477 state:reso...
anildigital authored
4 require 'rbconfig'
c787bfd @drogus Engine can now load its own plugins
drogus authored
5 require 'rails/engine/railties'
7fcf859 @josevalim Massive cleanup in Railties and load stack.
josevalim authored
6
7 module Rails
38310ab @fxn little details seen while doing a pass through what's new in docrails
fxn authored
8 # <tt>Rails::Engine</tt> allows you to wrap a specific Rails application or subset of
2f30fb0 @mjankowski misc grammar and clarity changes for rails/engine docs
mjankowski authored
9 # functionality and share it with other applications. Since Rails 3.0, every
10 # <tt>Rails::Application</tt> is just an engine, which allows for simple
11 # feature and application sharing.
781d0a9 @josevalim Add docs for Railtie, Engine, Plugin and Application.
josevalim authored
12 #
2f30fb0 @mjankowski misc grammar and clarity changes for rails/engine docs
mjankowski authored
13 # Any <tt>Rails::Engine</tt> is also a <tt>Rails::Railtie</tt>, so the same
14 # methods (like <tt>rake_tasks</tt> and +generators+) and configuration
15 # options that are available in railties can also be used in engines.
781d0a9 @josevalim Add docs for Railtie, Engine, Plugin and Application.
josevalim authored
16 #
17 # == Creating an Engine
18 #
2373eed @techpeace Make all references to engines lowercase in docs.
techpeace authored
19 # In Rails versions prior to 3.0, your gems automatically behaved as engines, however,
781d0a9 @josevalim Add docs for Railtie, Engine, Plugin and Application.
josevalim authored
20 # this coupled Rails to Rubygems. Since Rails 3.0, if you want a gem to automatically
2373eed @techpeace Make all references to engines lowercase in docs.
techpeace authored
21 # behave as an engine, you have to specify an +Engine+ for it somewhere inside
22 # your plugin's +lib+ folder (similar to how we specify a +Railtie+):
781d0a9 @josevalim Add docs for Railtie, Engine, Plugin and Application.
josevalim authored
23 #
24 # # lib/my_engine.rb
25 # module MyEngine
26 # class Engine < Rails::Engine
27 # end
28 # end
29 #
5f5e3b7 @techpeace Copy-edit and format Rails::Engine docs.
techpeace authored
30 # Then ensure that this file is loaded at the top of your <tt>config/application.rb</tt>
2373eed @techpeace Make all references to engines lowercase in docs.
techpeace authored
31 # (or in your +Gemfile+) and it will automatically load models, controllers and helpers
32 # inside +app+, load routes at <tt>config/routes.rb</tt>, load locales at
5f5e3b7 @techpeace Copy-edit and format Rails::Engine docs.
techpeace authored
33 # <tt>config/locales/*</tt>, and load tasks at <tt>lib/tasks/*</tt>.
781d0a9 @josevalim Add docs for Railtie, Engine, Plugin and Application.
josevalim authored
34 #
35 # == Configuration
36 #
2373eed @techpeace Make all references to engines lowercase in docs.
techpeace authored
37 # Besides the +Railtie+ configuration which is shared across the application, in a
5f5e3b7 @techpeace Copy-edit and format Rails::Engine docs.
techpeace authored
38 # <tt>Rails::Engine</tt> you can access <tt>autoload_paths</tt>, <tt>eager_load_paths</tt>
39 # and <tt>autoload_once_paths</tt>, which, differently from a <tt>Railtie</tt>, are scoped to
2373eed @techpeace Make all references to engines lowercase in docs.
techpeace authored
40 # the current engine.
781d0a9 @josevalim Add docs for Railtie, Engine, Plugin and Application.
josevalim authored
41 #
42 # Example:
43 #
44 # class MyEngine < Rails::Engine
45 # # Add a load path for this specific Engine
6f83a50 @fxn renames load_(once_)paths to autoload_(once_)paths in dependencies and c...
fxn authored
46 # config.autoload_paths << File.expand_path("../lib/some/path", __FILE__)
4bacc2a @josevalim Update the documentation for Engine and Railtie.
josevalim authored
47 #
48 # initializer "my_engine.add_middleware" do |app|
20f0e9f @jeremy Fix docs typo: app.middlewares -> app.middleware
jeremy authored
49 # app.middleware.use MyEngine::Middleware
4bacc2a @josevalim Update the documentation for Engine and Railtie.
josevalim authored
50 # end
781d0a9 @josevalim Add docs for Railtie, Engine, Plugin and Application.
josevalim authored
51 # end
9cfeefb @wycats Reorganized initializers a bit to enable better hooks for common cases w...
wycats authored
52 #
adfd43a @drogus Add documentation on app_generators
drogus authored
53 # == Generators
54 #
2373eed @techpeace Make all references to engines lowercase in docs.
techpeace authored
55 # You can set up generators for engines with <tt>config.generators</tt> method:
adfd43a @drogus Add documentation on app_generators
drogus authored
56 #
57 # class MyEngine < Rails::Engine
58 # config.generators do |g|
59 # g.orm :active_record
60 # g.template_engine :erb
61 # g.test_framework :test_unit
62 # end
63 # end
64 #
2373eed @techpeace Make all references to engines lowercase in docs.
techpeace authored
65 # You can also set generators for an application by using <tt>config.app_generators</tt>:
adfd43a @drogus Add documentation on app_generators
drogus authored
66 #
67 # class MyEngine < Rails::Engine
68 # # note that you can also pass block to app_generators in the same way you
69 # # can pass it to generators method
70 # config.app_generators.orm :datamapper
71 # end
72 #
781d0a9 @josevalim Add docs for Railtie, Engine, Plugin and Application.
josevalim authored
73 # == Paths
74 #
2f30fb0 @mjankowski misc grammar and clarity changes for rails/engine docs
mjankowski authored
75 # Since Rails 3.0, applications and engines have more flexible path configuration (as
46be69a @vijaydev spacing fix
vijaydev authored
76 # opposed to the previous hardcoded path configuration). This means that you are not
2f30fb0 @mjankowski misc grammar and clarity changes for rails/engine docs
mjankowski authored
77 # required to place your controllers at <tt>app/controllers</tt>, but in any place
78 # which you find convenient.
781d0a9 @josevalim Add docs for Railtie, Engine, Plugin and Application.
josevalim authored
79 #
2373eed @techpeace Make all references to engines lowercase in docs.
techpeace authored
80 # For example, let's suppose you want to place your controllers in <tt>lib/controllers</tt>.
2f30fb0 @mjankowski misc grammar and clarity changes for rails/engine docs
mjankowski authored
81 # You can set that as an option:
781d0a9 @josevalim Add docs for Railtie, Engine, Plugin and Application.
josevalim authored
82 #
83 # class MyEngine < Rails::Engine
a8b1780 @josevalim Updated DOCS for engines and added a couple TODOs. Also, commented inter...
josevalim authored
84 # paths["app/controllers"] = "lib/controllers"
781d0a9 @josevalim Add docs for Railtie, Engine, Plugin and Application.
josevalim authored
85 # end
86 #
5f5e3b7 @techpeace Copy-edit and format Rails::Engine docs.
techpeace authored
87 # You can also have your controllers loaded from both <tt>app/controllers</tt> and
88 # <tt>lib/controllers</tt>:
781d0a9 @josevalim Add docs for Railtie, Engine, Plugin and Application.
josevalim authored
89 #
90 # class MyEngine < Rails::Engine
a8b1780 @josevalim Updated DOCS for engines and added a couple TODOs. Also, commented inter...
josevalim authored
91 # paths["app/controllers"] << "lib/controllers"
781d0a9 @josevalim Add docs for Railtie, Engine, Plugin and Application.
josevalim authored
92 # end
93 #
2373eed @techpeace Make all references to engines lowercase in docs.
techpeace authored
94 # The available paths in an engine are:
781d0a9 @josevalim Add docs for Railtie, Engine, Plugin and Application.
josevalim authored
95 #
96 # class MyEngine < Rails::Engine
3e7a8cc @vijaydev formatting results in comments
vijaydev authored
97 # paths["app"] # => ["app"]
98 # paths["app/controllers"] # => ["app/controllers"]
99 # paths["app/helpers"] # => ["app/helpers"]
100 # paths["app/models"] # => ["app/models"]
101 # paths["app/views"] # => ["app/views"]
102 # paths["lib"] # => ["lib"]
103 # paths["lib/tasks"] # => ["lib/tasks"]
104 # paths["config"] # => ["config"]
105 # paths["config/initializers"] # => ["config/initializers"]
106 # paths["config/locales"] # => ["config/locales"]
107 # paths["config/routes"] # => ["config/routes.rb"]
781d0a9 @josevalim Add docs for Railtie, Engine, Plugin and Application.
josevalim authored
108 # end
109 #
2f30fb0 @mjankowski misc grammar and clarity changes for rails/engine docs
mjankowski authored
110 # The <tt>Application</tt> class adds a couple more paths to this set. And as in your
111 # <tt>Application</tt>, all folders under +app+ are automatically added to the load path.
112 # If you have an <tt>app/observers</tt> folder for example, it will be added by default.
781d0a9 @josevalim Add docs for Railtie, Engine, Plugin and Application.
josevalim authored
113 #
153df92 @drogus Added documentation on endpoint, middeware stack and routes for Engine
drogus authored
114 # == Endpoint
115 #
2373eed @techpeace Make all references to engines lowercase in docs.
techpeace authored
116 # An engine can be also a rack application. It can be useful if you have a rack application that
117 # you would like to wrap with +Engine+ and provide some of the +Engine+'s features.
153df92 @drogus Added documentation on endpoint, middeware stack and routes for Engine
drogus authored
118 #
2373eed @techpeace Make all references to engines lowercase in docs.
techpeace authored
119 # To do that, use the +endpoint+ method:
5f5e3b7 @techpeace Copy-edit and format Rails::Engine docs.
techpeace authored
120 #
153df92 @drogus Added documentation on endpoint, middeware stack and routes for Engine
drogus authored
121 # module MyEngine
122 # class Engine < Rails::Engine
123 # endpoint MyRackApplication
124 # end
125 # end
126 #
2373eed @techpeace Make all references to engines lowercase in docs.
techpeace authored
127 # Now you can mount your engine in application's routes just like that:
153df92 @drogus Added documentation on endpoint, middeware stack and routes for Engine
drogus authored
128 #
5f5e3b7 @techpeace Copy-edit and format Rails::Engine docs.
techpeace authored
129 # MyRailsApp::Application.routes.draw do
130 # mount MyEngine::Engine => "/engine"
131 # end
153df92 @drogus Added documentation on endpoint, middeware stack and routes for Engine
drogus authored
132 #
133 # == Middleware stack
134 #
2f30fb0 @mjankowski misc grammar and clarity changes for rails/engine docs
mjankowski authored
135 # As an engine can now be a rack endpoint, it can also have a middleware
136 # stack. The usage is exactly the same as in <tt>Application</tt>:
153df92 @drogus Added documentation on endpoint, middeware stack and routes for Engine
drogus authored
137 #
138 # module MyEngine
139 # class Engine < Rails::Engine
140 # middleware.use SomeMiddleware
141 # end
142 # end
143 #
144 # == Routes
145 #
2f30fb0 @mjankowski misc grammar and clarity changes for rails/engine docs
mjankowski authored
146 # If you don't specify an endpoint, routes will be used as the default
147 # endpoint. You can use them just like you use an application's routes:
153df92 @drogus Added documentation on endpoint, middeware stack and routes for Engine
drogus authored
148 #
6f194bb @josevalim Small tidy up on Rails::Engine.
josevalim authored
149 # # ENGINE/config/routes.rb
150 # MyEngine::Engine.routes.draw do
56cdc81 @wycats Remove default match without specified method
wycats authored
151 # get "/" => "posts#index"
6f194bb @josevalim Small tidy up on Rails::Engine.
josevalim authored
152 # end
153df92 @drogus Added documentation on endpoint, middeware stack and routes for Engine
drogus authored
153 #
154 # == Mount priority
155 #
5f5e3b7 @techpeace Copy-edit and format Rails::Engine docs.
techpeace authored
156 # Note that now there can be more than one router in your application, and it's better to avoid
157 # passing requests through many routers. Consider this situation:
153df92 @drogus Added documentation on endpoint, middeware stack and routes for Engine
drogus authored
158 #
6f194bb @josevalim Small tidy up on Rails::Engine.
josevalim authored
159 # MyRailsApp::Application.routes.draw do
160 # mount MyEngine::Engine => "/blog"
56cdc81 @wycats Remove default match without specified method
wycats authored
161 # get "/blog/omg" => "main#omg"
6f194bb @josevalim Small tidy up on Rails::Engine.
josevalim authored
162 # end
153df92 @drogus Added documentation on endpoint, middeware stack and routes for Engine
drogus authored
163 #
2373eed @techpeace Make all references to engines lowercase in docs.
techpeace authored
164 # +MyEngine+ is mounted at <tt>/blog</tt>, and <tt>/blog/omg</tt> points to application's
165 # controller. In such a situation, requests to <tt>/blog/omg</tt> will go through +MyEngine+,
166 # and if there is no such route in +Engine+'s routes, it will be dispatched to <tt>main#omg</tt>.
5f5e3b7 @techpeace Copy-edit and format Rails::Engine docs.
techpeace authored
167 # It's much better to swap that:
153df92 @drogus Added documentation on endpoint, middeware stack and routes for Engine
drogus authored
168 #
6f194bb @josevalim Small tidy up on Rails::Engine.
josevalim authored
169 # MyRailsApp::Application.routes.draw do
56cdc81 @wycats Remove default match without specified method
wycats authored
170 # get "/blog/omg" => "main#omg"
6f194bb @josevalim Small tidy up on Rails::Engine.
josevalim authored
171 # mount MyEngine::Engine => "/blog"
172 # end
153df92 @drogus Added documentation on endpoint, middeware stack and routes for Engine
drogus authored
173 #
2373eed @techpeace Make all references to engines lowercase in docs.
techpeace authored
174 # Now, +Engine+ will get only requests that were not handled by +Application+.
153df92 @drogus Added documentation on endpoint, middeware stack and routes for Engine
drogus authored
175 #
1a161c7 @drogus Document engine_name
drogus authored
176 # == Engine name
177 #
5f5e3b7 @techpeace Copy-edit and format Rails::Engine docs.
techpeace authored
178 # There are some places where an Engine's name is used:
38310ab @fxn little details seen while doing a pass through what's new in docrails
fxn authored
179 #
5f5e3b7 @techpeace Copy-edit and format Rails::Engine docs.
techpeace authored
180 # * routes: when you mount an Engine with <tt>mount(MyEngine::Engine => '/my_engine')</tt>,
181 # it's used as default :as option
182 # * some of the rake tasks are based on engine name, e.g. <tt>my_engine:install:migrations</tt>,
183 # <tt>my_engine:install:assets</tt>
1a161c7 @drogus Document engine_name
drogus authored
184 #
5f5e3b7 @techpeace Copy-edit and format Rails::Engine docs.
techpeace authored
185 # Engine name is set by default based on class name. For <tt>MyEngine::Engine</tt> it will be
ad3e057 @ugisozols Remove duplicate words.
ugisozols authored
186 # <tt>my_engine_engine</tt>. You can change it manually using the <tt>engine_name</tt> method:
1a161c7 @drogus Document engine_name
drogus authored
187 #
6f194bb @josevalim Small tidy up on Rails::Engine.
josevalim authored
188 # module MyEngine
189 # class Engine < Rails::Engine
190 # engine_name "my_engine"
191 # end
1a161c7 @drogus Document engine_name
drogus authored
192 # end
193 #
8e955c5 @drogus Should be isolated engine instead of namespaced engine
drogus authored
194 # == Isolated Engine
2e4e1e7 @drogus Added documentation for namespaced Engine
drogus authored
195 #
5f5e3b7 @techpeace Copy-edit and format Rails::Engine docs.
techpeace authored
196 # Normally when you create controllers, helpers and models inside an engine, they are treated
2f30fb0 @mjankowski misc grammar and clarity changes for rails/engine docs
mjankowski authored
197 # as if they were created inside the application itself. This means that all helpers and
198 # named routes from the application will be available to your engine's controllers as well.
a8b1780 @josevalim Updated DOCS for engines and added a couple TODOs. Also, commented inter...
josevalim authored
199 #
5f5e3b7 @techpeace Copy-edit and format Rails::Engine docs.
techpeace authored
200 # However, sometimes you want to isolate your engine from the application, especially if your engine
201 # has its own router. To do that, you simply need to call +isolate_namespace+. This method requires
a8b1780 @josevalim Updated DOCS for engines and added a couple TODOs. Also, commented inter...
josevalim authored
202 # you to pass a module where all your controllers, helpers and models should be nested to:
2e4e1e7 @drogus Added documentation for namespaced Engine
drogus authored
203 #
6f194bb @josevalim Small tidy up on Rails::Engine.
josevalim authored
204 # module MyEngine
205 # class Engine < Rails::Engine
5d5eb2b @drogus Rename namespace method to isolate_namespace.
drogus authored
206 # isolate_namespace MyEngine
6f194bb @josevalim Small tidy up on Rails::Engine.
josevalim authored
207 # end
2e4e1e7 @drogus Added documentation for namespaced Engine
drogus authored
208 # end
209 #
2373eed @techpeace Make all references to engines lowercase in docs.
techpeace authored
210 # With such an engine, everything that is inside the +MyEngine+ module will be isolated from
5f5e3b7 @techpeace Copy-edit and format Rails::Engine docs.
techpeace authored
211 # the application.
2e4e1e7 @drogus Added documentation for namespaced Engine
drogus authored
212 #
213 # Consider such controller:
214 #
6f194bb @josevalim Small tidy up on Rails::Engine.
josevalim authored
215 # module MyEngine
216 # class FooController < ActionController::Base
217 # end
2e4e1e7 @drogus Added documentation for namespaced Engine
drogus authored
218 # end
219 #
2373eed @techpeace Make all references to engines lowercase in docs.
techpeace authored
220 # If an engine is marked as isolated, +FooController+ has access only to helpers from +Engine+ and
5f5e3b7 @techpeace Copy-edit and format Rails::Engine docs.
techpeace authored
221 # <tt>url_helpers</tt> from <tt>MyEngine::Engine.routes</tt>.
2e4e1e7 @drogus Added documentation for namespaced Engine
drogus authored
222 #
71d18ce @oem Changed a few instances of of words in the API docs written in British E...
oem authored
223 # The next thing that changes in isolated engines is the behavior of routes. Normally, when you namespace
5f5e3b7 @techpeace Copy-edit and format Rails::Engine docs.
techpeace authored
224 # your controllers, you also need to do namespace all your routes. With an isolated engine,
a8b1780 @josevalim Updated DOCS for engines and added a couple TODOs. Also, commented inter...
josevalim authored
225 # the namespace is applied by default, so you can ignore it in routes:
226 #
227 # MyEngine::Engine.routes.draw do
228 # resources :articles
229 # end
5f5e3b7 @techpeace Copy-edit and format Rails::Engine docs.
techpeace authored
230 #
7b03120 @trotter Fix documentation bug in Rails::Engine
trotter authored
231 # The routes above will automatically point to <tt>MyEngine::ArticlesController</tt>. Furthermore, you don't
737abe4 @rtlechow Railties typos.
rtlechow authored
232 # need to use longer url helpers like <tt>my_engine_articles_path</tt>. Instead, you should simply use
5f5e3b7 @techpeace Copy-edit and format Rails::Engine docs.
techpeace authored
233 # <tt>articles_path</tt> as you would do with your application.
234 #
71d18ce @oem Changed a few instances of of words in the API docs written in British E...
oem authored
235 # To make that behavior consistent with other parts of the framework, an isolated engine also has influence on
5f5e3b7 @techpeace Copy-edit and format Rails::Engine docs.
techpeace authored
236 # <tt>ActiveModel::Naming</tt>. When you use a namespaced model, like <tt>MyEngine::Article</tt>, it will normally
737abe4 @rtlechow Railties typos.
rtlechow authored
237 # use the prefix "my_engine". In an isolated engine, the prefix will be omitted in url helpers and
a8b1780 @josevalim Updated DOCS for engines and added a couple TODOs. Also, commented inter...
josevalim authored
238 # form fields for convenience.
07411ca @drogus List all of isolated engine changes
drogus authored
239 #
3e7a8cc @vijaydev formatting results in comments
vijaydev authored
240 # polymorphic_url(MyEngine::Article.new) # => "articles_path"
07411ca @drogus List all of isolated engine changes
drogus authored
241 #
242 # form_for(MyEngine::Article.new) do
3e7a8cc @vijaydev formatting results in comments
vijaydev authored
243 # text_field :title # => <input type="text" name="article[title]" id="article_title" />
07411ca @drogus List all of isolated engine changes
drogus authored
244 # end
245 #
2f30fb0 @mjankowski misc grammar and clarity changes for rails/engine docs
mjankowski authored
246 # Additionally, an isolated engine will set its name according to namespace, so
3e7a8cc @vijaydev formatting results in comments
vijaydev authored
247 # MyEngine::Engine.engine_name will be "my_engine". It will also set MyEngine.table_name_prefix
45b4ebc @caius Fix typo in isolated engine docs
caius authored
248 # to "my_engine_", changing the MyEngine::Article model to use the my_engine_articles table.
2e4e1e7 @drogus Added documentation for namespaced Engine
drogus authored
249 #
434139f @drogus Documented mounted helpers
drogus authored
250 # == Using Engine's routes outside Engine
251 #
2373eed @techpeace Make all references to engines lowercase in docs.
techpeace authored
252 # Since you can now mount an engine inside application's routes, you do not have direct access to +Engine+'s
253 # <tt>url_helpers</tt> inside +Application+. When you mount an engine in an application's routes, a special helper is
5f5e3b7 @techpeace Copy-edit and format Rails::Engine docs.
techpeace authored
254 # created to allow you to do that. Consider such a scenario:
434139f @drogus Documented mounted helpers
drogus authored
255 #
3e7a8cc @vijaydev formatting results in comments
vijaydev authored
256 # # config/routes.rb
6f194bb @josevalim Small tidy up on Rails::Engine.
josevalim authored
257 # MyApplication::Application.routes.draw do
258 # mount MyEngine::Engine => "/my_engine", :as => "my_engine"
56cdc81 @wycats Remove default match without specified method
wycats authored
259 # get "/foo" => "foo#index"
6f194bb @josevalim Small tidy up on Rails::Engine.
josevalim authored
260 # end
434139f @drogus Documented mounted helpers
drogus authored
261 #
5f5e3b7 @techpeace Copy-edit and format Rails::Engine docs.
techpeace authored
262 # Now, you can use the <tt>my_engine</tt> helper inside your application:
434139f @drogus Documented mounted helpers
drogus authored
263 #
6f194bb @josevalim Small tidy up on Rails::Engine.
josevalim authored
264 # class FooController < ApplicationController
265 # def index
266 # my_engine.root_url #=> /my_engine/
267 # end
434139f @drogus Documented mounted helpers
drogus authored
268 # end
269 #
5f5e3b7 @techpeace Copy-edit and format Rails::Engine docs.
techpeace authored
270 # There is also a <tt>main_app</tt> helper that gives you access to application's routes inside Engine:
434139f @drogus Documented mounted helpers
drogus authored
271 #
6f194bb @josevalim Small tidy up on Rails::Engine.
josevalim authored
272 # module MyEngine
273 # class BarController
a8b1780 @josevalim Updated DOCS for engines and added a couple TODOs. Also, commented inter...
josevalim authored
274 # def index
275 # main_app.foo_path #=> /foo
276 # end
6f194bb @josevalim Small tidy up on Rails::Engine.
josevalim authored
277 # end
434139f @drogus Documented mounted helpers
drogus authored
278 # end
279 #
2f30fb0 @mjankowski misc grammar and clarity changes for rails/engine docs
mjankowski authored
280 # Note that the <tt>:as</tt> option given to mount takes the <tt>engine_name</tt> as default, so most of the time
5f5e3b7 @techpeace Copy-edit and format Rails::Engine docs.
techpeace authored
281 # you can simply omit it.
34cd8a6 @drogus Add some more docs on polymorphic_url with routes proxy
drogus authored
282 #
2f30fb0 @mjankowski misc grammar and clarity changes for rails/engine docs
mjankowski authored
283 # Finally, if you want to generate a url to an engine's route using
284 # <tt>polymorphic_url</tt>, you also need to pass the engine helper. Let's
285 # say that you want to create a form pointing to one of the engine's routes.
286 # All you need to do is pass the helper as the first element in array with
a8b1780 @josevalim Updated DOCS for engines and added a couple TODOs. Also, commented inter...
josevalim authored
287 # attributes for url:
34cd8a6 @drogus Add some more docs on polymorphic_url with routes proxy
drogus authored
288 #
5f5e3b7 @techpeace Copy-edit and format Rails::Engine docs.
techpeace authored
289 # form_for([my_engine, @user])
34cd8a6 @drogus Add some more docs on polymorphic_url with routes proxy
drogus authored
290 #
5f5e3b7 @techpeace Copy-edit and format Rails::Engine docs.
techpeace authored
291 # This code will use <tt>my_engine.user_path(@user)</tt> to generate the proper route.
34cd8a6 @drogus Add some more docs on polymorphic_url with routes proxy
drogus authored
292 #
e38b443 @drogus Add Engine#helpers method which loads all the engine's helpers
drogus authored
293 # == Isolated engine's helpers
294 #
295 # Sometimes you may want to isolate engine, but use helpers that are defined for it.
296 # If you want to share just a few specific helpers you can add them to application's
297 # helpers in ApplicationController:
298 #
9ce5d51 @morgoth fixed example code indentation
morgoth authored
299 # class ApplicationController < ActionController::Base
300 # helper MyEngine::SharedEngineHelper
301 # end
e38b443 @drogus Add Engine#helpers method which loads all the engine's helpers
drogus authored
302 #
46b4a26 @radar Rails::Engine docs should use helper method, not helpers
radar authored
303 # If you want to include all of the engine's helpers, you can use #helper method on an engine's
e38b443 @drogus Add Engine#helpers method which loads all the engine's helpers
drogus authored
304 # instance:
305 #
9ce5d51 @morgoth fixed example code indentation
morgoth authored
306 # class ApplicationController < ActionController::Base
307 # helper MyEngine::Engine.helpers
308 # end
e38b443 @drogus Add Engine#helpers method which loads all the engine's helpers
drogus authored
309 #
310 # It will include all of the helpers from engine's directory. Take into account that this does
311 # not include helpers defined in controllers with helper_method or other similar solutions,
cb76771 @MDaubs Minor typo describing engine helpers
MDaubs authored
312 # only helpers defined in the helpers directory will be included.
e38b443 @drogus Add Engine#helpers method which loads all the engine's helpers
drogus authored
313 #
dfac9b1 @drogus Strengthen documantation on engine's migrations and seed data
drogus authored
314 # == Migrations & seed data
315 #
5f5e3b7 @techpeace Copy-edit and format Rails::Engine docs.
techpeace authored
316 # Engines can have their own migrations. The default path for migrations is exactly the same
317 # as in application: <tt>db/migrate</tt>
dfac9b1 @drogus Strengthen documantation on engine's migrations and seed data
drogus authored
318 #
319 # To use engine's migrations in application you can use rake task, which copies them to
320 # application's dir:
321 #
a8b1780 @josevalim Updated DOCS for engines and added a couple TODOs. Also, commented inter...
josevalim authored
322 # rake ENGINE_NAME:install:migrations
dfac9b1 @drogus Strengthen documantation on engine's migrations and seed data
drogus authored
323 #
5f5e3b7 @techpeace Copy-edit and format Rails::Engine docs.
techpeace authored
324 # Note that some of the migrations may be skipped if a migration with the same name already exists
325 # in application. In such a situation you must decide whether to leave that migration or rename the
2f30fb0 @mjankowski misc grammar and clarity changes for rails/engine docs
mjankowski authored
326 # migration in the application and rerun copying migrations.
a2c52f1 @drogus Update documentation for new tasks
drogus authored
327 #
dfac9b1 @drogus Strengthen documantation on engine's migrations and seed data
drogus authored
328 # If your engine has migrations, you may also want to prepare data for the database in
6a2cf4c @radar update engines guide to explicitly reference relative-to-engine-root-pat...
radar authored
329 # the <tt>db/seeds.rb</tt> file. You can load that data using the <tt>load_seed</tt> method, e.g.
dfac9b1 @drogus Strengthen documantation on engine's migrations and seed data
drogus authored
330 #
331 # MyEngine::Engine.load_seed
332 #
40b19e0 @drogus Allow to change engine's loading priority with config.railties_order=
drogus authored
333 # == Loading priority
334 #
72795d7 @mark-rushakoff Code-format references to config settings
mark-rushakoff authored
335 # In order to change engine's priority you can use +config.railties_order+ in main application.
40b19e0 @drogus Allow to change engine's loading priority with config.railties_order=
drogus authored
336 # It will affect the priority of loading views, helpers, assets and all the other files
337 # related to engine or application.
338 #
339 # Example:
340 #
341 # # load Blog::Engine with highest priority, followed by application and other railties
342 # config.railties_order = [Blog::Engine, :main_app, :all]
343 #
7fcf859 @josevalim Massive cleanup in Railties and load stack.
josevalim authored
344 class Engine < Railtie
b17e358 @josevalim Move configuration to subfolders.
josevalim authored
345 autoload :Configuration, "rails/engine/configuration"
37d3266 @josevalim Add missing autoload.
josevalim authored
346 autoload :Railties, "rails/engine/railties"
788fce2 @josevalim Create configurable modules and ensure that they are added only on direc...
josevalim authored
347
60281af @flippingbits Move load_generators from Rails::Application to Rails::Engine
flippingbits authored
348 def load_generators(app=self)
349 initialize_generators
350 railties.all { |r| r.load_generators(app) }
351 Rails::Generators.configure!(app.config.generators)
352 super
353 self
354 end
355
7fcf859 @josevalim Massive cleanup in Railties and load stack.
josevalim authored
356 class << self
5d5eb2b @drogus Rename namespace method to isolate_namespace.
drogus authored
357 attr_accessor :called_from, :isolated
ef4afed @drogus There is no need to make isolated? method with bang-bang, just alias iso...
drogus authored
358 alias :isolated? :isolated
2068b8c @drogus Added tests for railtie_name and aliased it in engine as engine_name
drogus authored
359 alias :engine_name :railtie_name
7fcf859 @josevalim Massive cleanup in Railties and load stack.
josevalim authored
360
361 def inherited(base)
f5ee855 @josevalim Improve heuristic for railties default name, otherwise railties may be n...
josevalim authored
362 unless base.abstract_railtie?
788fce2 @josevalim Create configurable modules and ensure that they are added only on direc...
josevalim authored
363 base.called_from = begin
a5684df @josevalim Ensure config.after_initializer is executed before building the middlewa...
josevalim authored
364 # Remove the line number from backtraces making sure we don't leave anything behind
4bfe30c @spastorino delete from :number until the end
spastorino authored
365 call_stack = caller.map { |p| p.sub(/:\d+.*/, '') }
21ff884 @fxn in regexps, the dot in a character class is not a metacharacter
fxn authored
366 File.dirname(call_stack.detect { |p| p !~ %r[railties[\w.-]*/lib/rails|rack[\w.-]*/lib/rack] })
788fce2 @josevalim Create configurable modules and ensure that they are added only on direc...
josevalim authored
367 end
7fcf859 @josevalim Massive cleanup in Railties and load stack.
josevalim authored
368 end
788fce2 @josevalim Create configurable modules and ensure that they are added only on direc...
josevalim authored
369
7fcf859 @josevalim Massive cleanup in Railties and load stack.
josevalim authored
370 super
371 end
372
3939d6b @drogus Removed ActionDispatch::Static, but left empty MiddlewareStack to unify ...
drogus authored
373 def endpoint(endpoint = nil)
44f0709 @tenderlove dealing with some -w warnings on startup
tenderlove authored
374 @endpoint ||= nil
3939d6b @drogus Removed ActionDispatch::Static, but left empty MiddlewareStack to unify ...
drogus authored
375 @endpoint = endpoint if endpoint
376 @endpoint
377 end
c7664d1 @drogus Include application's helpers and router helpers by default, but include...
drogus authored
378
5d5eb2b @drogus Rename namespace method to isolate_namespace.
drogus authored
379 def isolate_namespace(mod)
db8a864 @drogus Add table_name_prefix to Engine's namespace automatically
drogus authored
380 engine_name(generate_railtie_name(mod))
381
0a28073 Engines that use isolate_namespace with nested modules should set correc...
Rolf Timmermans authored
382 self.routes.default_scope = { :module => ActiveSupport::Inflector.underscore(mod.name) }
5d5eb2b @drogus Rename namespace method to isolate_namespace.
drogus authored
383 self.isolated = true
74598fe @drogus Do not overwrite _railtie method on namespace while creating isolated en...
drogus authored
384
fd86a1b @josevalim Rely on a public contract between railties instead of accessing railtie ...
josevalim authored
385 unless mod.respond_to?(:railtie_namespace)
386 name, railtie = engine_name, self
387
74598fe @drogus Do not overwrite _railtie method on namespace while creating isolated en...
drogus authored
388 mod.singleton_class.instance_eval do
fd86a1b @josevalim Rely on a public contract between railties instead of accessing railtie ...
josevalim authored
389 define_method(:railtie_namespace) { railtie }
74598fe @drogus Do not overwrite _railtie method on namespace while creating isolated en...
drogus authored
390
f821055 @drogus Do not create table_name_prefix method on isolated module if the method ...
drogus authored
391 unless mod.respond_to?(:table_name_prefix)
fd86a1b @josevalim Rely on a public contract between railties instead of accessing railtie ...
josevalim authored
392 define_method(:table_name_prefix) { "#{name}_" }
393 end
394
395 unless mod.respond_to?(:use_relative_model_naming?)
396 class_eval "def use_relative_model_naming?; true; end", __FILE__, __LINE__
397 end
398
399 unless mod.respond_to?(:railtie_helpers_paths)
400 define_method(:railtie_helpers_paths) { railtie.helpers_paths }
401 end
402
403 unless mod.respond_to?(:railtie_routes_url_helpers)
404 define_method(:railtie_routes_url_helpers) { railtie.routes_url_helpers }
74598fe @drogus Do not overwrite _railtie method on namespace while creating isolated en...
drogus authored
405 end
fd86a1b @josevalim Rely on a public contract between railties instead of accessing railtie ...
josevalim authored
406 end
74598fe @drogus Do not overwrite _railtie method on namespace while creating isolated en...
drogus authored
407 end
e35c204 @drogus Include all helpers from non-namespaced engines
drogus authored
408 end
051127d @drogus Rails::Engine.find(path) - method to find engine by path
drogus authored
409
410 # Finds engine with given path
411 def find(path)
c7cfdd0 @dcrec1 refactored Engine.#find by giving an explicit name to a variable and red...
dcrec1 authored
412 expanded_path = File.expand_path path.to_s
413 Rails::Engine::Railties.engines.find { |engine|
414 File.expand_path(engine.root.to_s) == expanded_path
1db4969 @tenderlove only compute path.to_s once
tenderlove authored
415 }
051127d @drogus Rails::Engine.find(path) - method to find engine by path
drogus authored
416 end
7fcf859 @josevalim Massive cleanup in Railties and load stack.
josevalim authored
417 end
418
32a5b49 @drogus Move singleton pattern to Railtie and remove Engine::Configurable and Ap...
drogus authored
419 delegate :middleware, :root, :paths, :to => :config
5d5eb2b @drogus Rename namespace method to isolate_namespace.
drogus authored
420 delegate :engine_name, :isolated?, :to => "self.class"
2b75b94 @josevalim Plugin is now an Engine.
josevalim authored
421
245dba0 @jhtwong Cherry-picking patch for https://github.com/rails/rails/issues/1460
jhtwong authored
422 def load_tasks(app=self)
423 railties.all { |r| r.load_tasks(app) }
7317d9e @josh Remove implicit controller namespacing from new dsl
josh authored
424 super
d649bf1 @josevalim Provide a cleaner syntax for paths configuration that does not rely on m...
josevalim authored
425 paths["lib/tasks"].existent.sort.each { |ext| load(ext) }
2b75b94 @josevalim Plugin is now an Engine.
josevalim authored
426 end
71d18ce @oem Changed a few instances of of words in the API docs written in British E...
oem authored
427
245dba0 @jhtwong Cherry-picking patch for https://github.com/rails/rails/issues/1460
jhtwong authored
428 def load_console(app=self)
429 railties.all { |r| r.load_console(app) }
430 super
431 end
71d18ce @oem Changed a few instances of of words in the API docs written in British E...
oem authored
432
351816f @josevalim Ensure that eager_load actually takes place just after the middleware st...
josevalim authored
433 def eager_load!
245dba0 @jhtwong Cherry-picking patch for https://github.com/rails/rails/issues/1460
jhtwong authored
434 railties.all(&:eager_load!)
71d18ce @oem Changed a few instances of of words in the API docs written in British E...
oem authored
435
351816f @josevalim Ensure that eager_load actually takes place just after the middleware st...
josevalim authored
436 config.eager_load_paths.each do |load_path|
437 matcher = /\A#{Regexp.escape(load_path)}\/(.*)\.rb\Z/
438 Dir.glob("#{load_path}/**/*.rb").sort.each do |file|
439 require_dependency file.sub(matcher, '\1')
440 end
441 end
442 end
443
c787bfd @drogus Engine can now load its own plugins
drogus authored
444 def railties
32a5b49 @drogus Move singleton pattern to Railtie and remove Engine::Configurable and Ap...
drogus authored
445 @railties ||= self.class::Railties.new(config)
c787bfd @drogus Engine can now load its own plugins
drogus authored
446 end
447
e38b443 @drogus Add Engine#helpers method which loads all the engine's helpers
drogus authored
448 def helpers
449 @helpers ||= begin
450 helpers = Module.new
d4bea35 @drogus Make ActionController::Base.modules_for_helpers and ActionController::Ba...
drogus authored
451 all = ActionController::Base.all_helpers_from_path(helpers_paths)
452 ActionController::Base.modules_for_helpers(all).each do |mod|
e38b443 @drogus Add Engine#helpers method which loads all the engine's helpers
drogus authored
453 helpers.send(:include, mod)
454 end
455 helpers
456 end
457 end
458
fd86a1b @josevalim Rely on a public contract between railties instead of accessing railtie ...
josevalim authored
459 def helpers_paths
460 paths["app/helpers"].existent
461 end
462
463 def routes_url_helpers
464 routes.url_helpers
465 end
466
ad6be08 @drogus Made Engine valid rack app with its own middleware stack
drogus authored
467 def app
092b148 @drogus Engine can now serve files with ActionDispatch::Static
drogus authored
468 @app ||= begin
469 config.middleware = config.middleware.merge_into(default_middleware_stack)
470 config.middleware.build(endpoint)
471 end
ad6be08 @drogus Made Engine valid rack app with its own middleware stack
drogus authored
472 end
473
474 def endpoint
c989d1a @drogus Engine sets routes as default rack endpoint if no endpoint was given
drogus authored
475 self.class.endpoint || routes
ad6be08 @drogus Made Engine valid rack app with its own middleware stack
drogus authored
476 end
477
478 def call(env)
a132229 @drogus Added ability to set asset_path for engines
drogus authored
479 app.call(env.merge!(env_config))
480 end
481
482 def env_config
483 @env_config ||= {
afc8288 @josevalim Remove the ability for engines to serve assets from the public directory...
josevalim authored
484 'action_dispatch.routes' => routes
a132229 @drogus Added ability to set asset_path for engines
drogus authored
485 }
ad6be08 @drogus Made Engine valid rack app with its own middleware stack
drogus authored
486 end
487
08f4713 @drogus Refactored routes reloading to use RouteSet#append instead keeping block...
drogus authored
488 def routes
5a2fdaa @drogus Fix Engine#routes to not call draw_paths multiple times
drogus authored
489 @routes ||= ActionDispatch::Routing::RouteSet.new.tap do |routes|
490 routes.draw_paths.concat paths["config/routes"].paths
491 end
492
08f4713 @drogus Refactored routes reloading to use RouteSet#append instead keeping block...
drogus authored
493 @routes.append(&Proc.new) if block_given?
ec5d846 @drogus Properly reload routes defined in class definition
drogus authored
494 @routes
c989d1a @drogus Engine sets routes as default rack endpoint if no endpoint was given
drogus authored
495 end
496
40b19e0 @drogus Allow to change engine's loading priority with config.railties_order=
drogus authored
497 def ordered_railties
498 railties.all + [self]
499 end
500
675f3ea @drogus Gather initializers from railties in engines to get rid of additional lo...
drogus authored
501 def initializers
502 initializers = []
40b19e0 @drogus Allow to change engine's loading priority with config.railties_order=
drogus authored
503 ordered_railties.each do |r|
504 if r == self
505 initializers += super
506 else
507 initializers += r.initializers
508 end
509 end
675f3ea @drogus Gather initializers from railties in engines to get rid of additional lo...
drogus authored
510 initializers
511 end
512
32a5b49 @drogus Move singleton pattern to Railtie and remove Engine::Configurable and Ap...
drogus authored
513 def config
937f419 @drogus Engine's assets are now served with ActionDispatch::Static
drogus authored
514 @config ||= Engine::Configuration.new(find_root_with_flag("lib"))
32a5b49 @drogus Move singleton pattern to Railtie and remove Engine::Configurable and Ap...
drogus authored
515 end
516
d475de7 @drogus Add helper for loading seed data for engine and application
drogus authored
517 # Load data from db/seeds.rb file. It can be used in to load engines'
518 # seeds, e.g.:
519 #
520 # Blog::Engine.load_seed
521 def load_seed
47be2f1 @wycats Fix the build
wycats authored
522 seed_file = paths["db/seeds.rb"].existent.first
e938247 @tenderlove seed file was already tested for existence. ಠ_ಠ
tenderlove authored
523 load(seed_file) if seed_file
d475de7 @drogus Add helper for loading seed data for engine and application
drogus authored
524 end
525
7fcf859 @josevalim Massive cleanup in Railties and load stack.
josevalim authored
526 # Add configured load paths to ruby load paths and remove duplicates.
9cfeefb @wycats Reorganized initializers a bit to enable better hooks for common cases w...
wycats authored
527 initializer :set_load_path, :before => :bootstrap_hook do
9b19a6f @josevalim A few changes were done in this commit:
josevalim authored
528 _all_load_paths.reverse_each do |path|
4ae7936 @josevalim Got tests working once again.
josevalim authored
529 $LOAD_PATH.unshift(path) if File.directory?(path)
530 end
7fcf859 @josevalim Massive cleanup in Railties and load stack.
josevalim authored
531 $LOAD_PATH.uniq!
532 end
533
534 # Set the paths from which Rails will automatically load source files,
535 # and the load_once paths.
9cfeefb @wycats Reorganized initializers a bit to enable better hooks for common cases w...
wycats authored
536 #
537 # This needs to be an initializer, since it needs to run once
538 # per engine and get the engine as a block parameter
539 initializer :set_autoload_paths, :before => :bootstrap_hook do |app|
9b19a6f @josevalim A few changes were done in this commit:
josevalim authored
540 ActiveSupport::Dependencies.autoload_paths.unshift(*_all_autoload_paths)
6f194bb @josevalim Small tidy up on Rails::Engine.
josevalim authored
541 ActiveSupport::Dependencies.autoload_once_paths.unshift(*_all_autoload_once_paths)
7fcf859 @josevalim Massive cleanup in Railties and load stack.
josevalim authored
542
98240c4 @josevalim Get rid of initializers global and create i18n railtie.
josevalim authored
543 # Freeze so future modifications will fail rather than do nothing mysteriously
6f83a50 @fxn renames load_(once_)paths to autoload_(once_)paths in dependencies and c...
fxn authored
544 config.autoload_paths.freeze
9b19a6f @josevalim A few changes were done in this commit:
josevalim authored
545 config.eager_load_paths.freeze
6f83a50 @fxn renames load_(once_)paths to autoload_(once_)paths in dependencies and c...
fxn authored
546 config.autoload_once_paths.freeze
7fcf859 @josevalim Massive cleanup in Railties and load stack.
josevalim authored
547 end
548
226d8e7 @josevalim Refactor MetalLoader and RoutesReloader to rely less on class configurat...
josevalim authored
549 initializer :add_routing_paths do |app|
6acebb3 @wycats Allow loading external route files from the router
wycats authored
550 paths = self.paths["config/routes.rb"].existent
363a06f @wycats Routes reloader knows how to reload external files
wycats authored
551 external_paths = self.paths["config/routes"].paths
d649bf1 @josevalim Provide a cleaner syntax for paths configuration that does not rely on m...
josevalim authored
552
553 if routes? || paths.any?
554 app.routes_reloader.paths.unshift(*paths)
08f4713 @drogus Refactored routes reloading to use RouteSet#append instead keeping block...
drogus authored
555 app.routes_reloader.route_sets << routes
363a06f @wycats Routes reloader knows how to reload external files
wycats authored
556 app.routes_reloader.external_routes.unshift(*external_paths)
98240c4 @josevalim Get rid of initializers global and create i18n railtie.
josevalim authored
557 end
558 end
559
1177a40 @josevalim Fix i18n locales order test.
josevalim authored
560 # I18n load paths are a special case since the ones added
561 # later have higher priority.
98240c4 @josevalim Get rid of initializers global and create i18n railtie.
josevalim authored
562 initializer :add_locales do
d649bf1 @josevalim Provide a cleaner syntax for paths configuration that does not rely on m...
josevalim authored
563 config.i18n.railties_load_path.concat(paths["config/locales"].existent)
7fcf859 @josevalim Massive cleanup in Railties and load stack.
josevalim authored
564 end
565
02c5137 @josevalim Add view paths to Engine setup.
josevalim authored
566 initializer :add_view_paths do
d649bf1 @josevalim Provide a cleaner syntax for paths configuration that does not rely on m...
josevalim authored
567 views = paths["app/views"].existent
6f194bb @josevalim Small tidy up on Rails::Engine.
josevalim authored
568 unless views.empty?
fbc9d0f @josevalim Simplify helpers handling. Ensure Metal can run AC hooks.
josevalim authored
569 ActiveSupport.on_load(:action_controller){ prepend_view_path(views) if respond_to?(:prepend_view_path) }
6f194bb @josevalim Small tidy up on Rails::Engine.
josevalim authored
570 ActiveSupport.on_load(:action_mailer){ prepend_view_path(views) }
4aded43 @wycats Replace the placeholder base_hook API with on_load. To specify some code...
wycats authored
571 end
02c5137 @josevalim Add view paths to Engine setup.
josevalim authored
572 end
573
eb367af @josevalim `rake assets:precompile` loads the application but does not initialize i...
josevalim authored
574 initializer :load_environment_config, :before => :load_environment_hook, :group => :all do
d649bf1 @josevalim Provide a cleaner syntax for paths configuration that does not rely on m...
josevalim authored
575 environment = paths["config/environments"].existent.first
7cccfed @drogus Allow Engines loading its own environment file from config/environments
drogus authored
576 require environment if environment
577 end
578
d68884f @josevalim :group => :assets should only run in the assets environment.
josevalim authored
579 initializer :append_assets_path, :group => :all do |app|
6dda216 @spastorino Merge pull request #2324 from zenapsis/3-1-stable
spastorino authored
580 app.config.assets.paths.unshift(*paths["vendor/assets"].existent_directories)
581 app.config.assets.paths.unshift(*paths["lib/assets"].existent_directories)
582 app.config.assets.paths.unshift(*paths["app/assets"].existent_directories)
2fe70c1 @josevalim Booya, sprockets now works from Engines.
josevalim authored
583 end
584
d649bf1 @josevalim Provide a cleaner syntax for paths configuration that does not rely on m...
josevalim authored
585 initializer :prepend_helpers_path do |app|
5d5eb2b @drogus Rename namespace method to isolate_namespace.
drogus authored
586 if !isolated? || (app == self)
d649bf1 @josevalim Provide a cleaner syntax for paths configuration that does not rely on m...
josevalim authored
587 app.config.helpers_paths.unshift(*paths["app/helpers"].existent)
e35c204 @drogus Include all helpers from non-namespaced engines
drogus authored
588 end
589 end
590
11aa167 @josevalim Revert "Provide a unique point for running initializers."
josevalim authored
591 initializer :load_config_initializers do
592 config.paths["config/initializers"].existent.sort.each do |initializer|
593 load(initializer)
594 end
9af189a @drogus I've changed that test along the way, it should actually stay without ch...
drogus authored
595 end
596
b43b686 @drogus engines_blank_point should always be the last initializer in Engine
drogus authored
597 initializer :engines_blank_point do
598 # We need this initializer so all extra initializers added in engines are
599 # consistently executed after all the initializers above across all engines.
600 end
601
a9bf91e @drogus Add 'foo:install:migrations' task to copy migrations from foo engine
drogus authored
602 rake_tasks do
603 next if self.is_a?(Rails::Application)
afc8288 @josevalim Remove the ability for engines to serve assets from the public directory...
josevalim authored
604 next unless has_migrations?
a9bf91e @drogus Add 'foo:install:migrations' task to copy migrations from foo engine
drogus authored
605
606 namespace railtie_name do
607 namespace :install do
afc8288 @josevalim Remove the ability for engines to serve assets from the public directory...
josevalim authored
608 desc "Copy migrations from #{railtie_name} to application"
609 task :migrations do
610 ENV["FROM"] = railtie_name
0e49ef4 @Deradon Provided fix for calling rake tasks within mountable engines
Deradon authored
611 if Rake::Task.task_defined?("railties:install:migrations")
612 Rake::Task["railties:install:migrations"].invoke
613 else
614 Rake::Task["app:railties:install:migrations"].invoke
615 end
616
959f857 @drogus Added foo:install:assets task that copies assets from plugins public dir...
drogus authored
617 end
f07cbec @drogus Do not treat information about skipped migrations as WARNINGs but as a N...
drogus authored
618 end
a9bf91e @drogus Add 'foo:install:migrations' task to copy migrations from foo engine
drogus authored
619 end
620 end
621
788fce2 @josevalim Create configurable modules and ensure that they are added only on direc...
josevalim authored
622 protected
1860d87 @josevalim Ensure asset_path defaults to nil for application
josevalim authored
623
60281af @flippingbits Move load_generators from Rails::Application to Rails::Engine
flippingbits authored
624 def initialize_generators
625 require "rails/generators"
626 end
627
d649bf1 @josevalim Provide a cleaner syntax for paths configuration that does not rely on m...
josevalim authored
628 def routes?
d9239fd @romanvbabenko Engine#routes? method has been fixed
romanvbabenko authored
629 defined?(@routes) && @routes
d649bf1 @josevalim Provide a cleaner syntax for paths configuration that does not rely on m...
josevalim authored
630 end
631
d84b2f3 @josevalim Fix tests.
josevalim authored
632 def has_migrations?
a7a58af @spohlenz Fix has_migrations? check in Rails::Engine
spohlenz authored
633 paths["db/migrate"].existent.any?
d84b2f3 @josevalim Fix tests.
josevalim authored
634 end
635
32a5b49 @drogus Move singleton pattern to Railtie and remove Engine::Configurable and Ap...
drogus authored
636 def find_root_with_flag(flag, default=nil)
637 root_path = self.class.called_from
638
639 while root_path && File.directory?(root_path) && !File.exist?("#{root_path}/#{flag}")
640 parent = File.dirname(root_path)
641 root_path = parent != root_path && parent
642 end
643
644 root = File.exist?("#{root_path}/#{flag}") ? root_path : default
645 raise "Could not find root path for #{self}" unless root
646
4a4ff14 @josevalim Use RbConfig instead of Config for 1.9.3 compatibility.
josevalim authored
647 RbConfig::CONFIG['host_os'] =~ /mswin|mingw/ ?
32a5b49 @drogus Move singleton pattern to Railtie and remove Engine::Configurable and Ap...
drogus authored
648 Pathname.new(root).expand_path : Pathname.new(root).realpath
649 end
650
3939d6b @drogus Removed ActionDispatch::Static, but left empty MiddlewareStack to unify ...
drogus authored
651 def default_middleware_stack
652 ActionDispatch::MiddlewareStack.new
653 end
788fce2 @josevalim Create configurable modules and ensure that they are added only on direc...
josevalim authored
654
6f194bb @josevalim Small tidy up on Rails::Engine.
josevalim authored
655 def _all_autoload_once_paths
656 config.autoload_once_paths
657 end
658
9b19a6f @josevalim A few changes were done in this commit:
josevalim authored
659 def _all_autoload_paths
660 @_all_autoload_paths ||= (config.autoload_paths + config.eager_load_paths + config.autoload_once_paths).uniq
661 end
662
663 def _all_load_paths
664 @_all_load_paths ||= (config.paths.load_paths + _all_autoload_paths).uniq
788fce2 @josevalim Create configurable modules and ensure that they are added only on direc...
josevalim authored
665 end
7fcf859 @josevalim Massive cleanup in Railties and load stack.
josevalim authored
666 end
6324eee @jeremy plugin rails/init.rb deprecation message
jeremy authored
667 end
Something went wrong with that request. Please try again.