Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 663 lines (602 sloc) 22.885 kb
b17e358 José Valim Move configuration to subfolders.
josevalim authored
1 require 'rails/railtie'
812136a Jeremy Kemper Fix unstated usage of Pathname
jeremy authored
2 require 'active_support/core_ext/module/delegation'
3 require 'pathname'
53c13f1 Anil Wadghule Use Config::CONFIG['host_os'] instead of RUBY_PLATFORM [#4477 state:reso...
anildigital authored
4 require 'rbconfig'
c787bfd Piotr Sarnacki Engine can now load its own plugins
drogus authored
5 require 'rails/engine/railties'
7fcf859 José Valim Massive cleanup in Railties and load stack.
josevalim authored
6
7 module Rails
38310ab Xavier Noria 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 Matt Jankowski 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 José Valim Add docs for Railtie, Engine, Plugin and Application.
josevalim authored
12 #
2f30fb0 Matt Jankowski 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 José Valim Add docs for Railtie, Engine, Plugin and Application.
josevalim authored
16 #
17 # == Creating an Engine
18 #
2373eed Matt Buck 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 José Valim 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 Matt Buck 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 José Valim 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 Matt Buck 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 Matt Buck 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 Matt Buck Copy-edit and format Rails::Engine docs.
techpeace authored
33 # <tt>config/locales/*</tt>, and load tasks at <tt>lib/tasks/*</tt>.
781d0a9 José Valim Add docs for Railtie, Engine, Plugin and Application.
josevalim authored
34 #
35 # == Configuration
36 #
2373eed Matt Buck Make all references to engines lowercase in docs.
techpeace authored
37 # Besides the +Railtie+ configuration which is shared across the application, in a
5f5e3b7 Matt Buck 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 Matt Buck Make all references to engines lowercase in docs.
techpeace authored
40 # the current engine.
781d0a9 José Valim 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 Xavier Noria 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 José Valim Update the documentation for Engine and Railtie.
josevalim authored
47 #
48 # initializer "my_engine.add_middleware" do |app|
20f0e9f Jeremy Kemper Fix docs typo: app.middlewares -> app.middleware
jeremy authored
49 # app.middleware.use MyEngine::Middleware
4bacc2a José Valim Update the documentation for Engine and Railtie.
josevalim authored
50 # end
781d0a9 José Valim Add docs for Railtie, Engine, Plugin and Application.
josevalim authored
51 # end
9cfeefb Yehuda Katz Reorganized initializers a bit to enable better hooks for common cases w...
wycats authored
52 #
adfd43a Piotr Sarnacki Add documentation on app_generators
drogus authored
53 # == Generators
54 #
2373eed Matt Buck 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 Piotr Sarnacki 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 Matt Buck 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 Piotr Sarnacki 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 José Valim Add docs for Railtie, Engine, Plugin and Application.
josevalim authored
73 # == Paths
74 #
2f30fb0 Matt Jankowski 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 Vijay Dev spacing fix
vijaydev authored
76 # opposed to the previous hardcoded path configuration). This means that you are not
2f30fb0 Matt Jankowski 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 José Valim Add docs for Railtie, Engine, Plugin and Application.
josevalim authored
79 #
2373eed Matt Buck 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 Matt Jankowski misc grammar and clarity changes for rails/engine docs
mjankowski authored
81 # You can set that as an option:
781d0a9 José Valim Add docs for Railtie, Engine, Plugin and Application.
josevalim authored
82 #
83 # class MyEngine < Rails::Engine
a8b1780 José Valim Updated DOCS for engines and added a couple TODOs. Also, commented inter...
josevalim authored
84 # paths["app/controllers"] = "lib/controllers"
781d0a9 José Valim Add docs for Railtie, Engine, Plugin and Application.
josevalim authored
85 # end
86 #
5f5e3b7 Matt Buck 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 José Valim Add docs for Railtie, Engine, Plugin and Application.
josevalim authored
89 #
90 # class MyEngine < Rails::Engine
a8b1780 José Valim Updated DOCS for engines and added a couple TODOs. Also, commented inter...
josevalim authored
91 # paths["app/controllers"] << "lib/controllers"
781d0a9 José Valim Add docs for Railtie, Engine, Plugin and Application.
josevalim authored
92 # end
93 #
2373eed Matt Buck Make all references to engines lowercase in docs.
techpeace authored
94 # The available paths in an engine are:
781d0a9 José Valim Add docs for Railtie, Engine, Plugin and Application.
josevalim authored
95 #
96 # class MyEngine < Rails::Engine
3e7a8cc Vijay Dev 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 José Valim Add docs for Railtie, Engine, Plugin and Application.
josevalim authored
108 # end
109 #
2f30fb0 Matt Jankowski 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 José Valim Add docs for Railtie, Engine, Plugin and Application.
josevalim authored
113 #
153df92 Piotr Sarnacki Added documentation on endpoint, middeware stack and routes for Engine
drogus authored
114 # == Endpoint
115 #
2373eed Matt Buck 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 Piotr Sarnacki Added documentation on endpoint, middeware stack and routes for Engine
drogus authored
118 #
2373eed Matt Buck Make all references to engines lowercase in docs.
techpeace authored
119 # To do that, use the +endpoint+ method:
5f5e3b7 Matt Buck Copy-edit and format Rails::Engine docs.
techpeace authored
120 #
153df92 Piotr Sarnacki 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 Matt Buck 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 Piotr Sarnacki Added documentation on endpoint, middeware stack and routes for Engine
drogus authored
128 #
5f5e3b7 Matt Buck Copy-edit and format Rails::Engine docs.
techpeace authored
129 # MyRailsApp::Application.routes.draw do
130 # mount MyEngine::Engine => "/engine"
131 # end
153df92 Piotr Sarnacki Added documentation on endpoint, middeware stack and routes for Engine
drogus authored
132 #
133 # == Middleware stack
134 #
2f30fb0 Matt Jankowski 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 Piotr Sarnacki 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 Matt Jankowski 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 Piotr Sarnacki Added documentation on endpoint, middeware stack and routes for Engine
drogus authored
148 #
6f194bb José Valim Small tidy up on Rails::Engine.
josevalim authored
149 # # ENGINE/config/routes.rb
150 # MyEngine::Engine.routes.draw do
151 # match "/" => "posts#index"
152 # end
153df92 Piotr Sarnacki Added documentation on endpoint, middeware stack and routes for Engine
drogus authored
153 #
154 # == Mount priority
155 #
5f5e3b7 Matt Buck 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 Piotr Sarnacki Added documentation on endpoint, middeware stack and routes for Engine
drogus authored
158 #
6f194bb José Valim Small tidy up on Rails::Engine.
josevalim authored
159 # MyRailsApp::Application.routes.draw do
160 # mount MyEngine::Engine => "/blog"
161 # match "/blog/omg" => "main#omg"
162 # end
153df92 Piotr Sarnacki Added documentation on endpoint, middeware stack and routes for Engine
drogus authored
163 #
2373eed Matt Buck 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 Matt Buck Copy-edit and format Rails::Engine docs.
techpeace authored
167 # It's much better to swap that:
153df92 Piotr Sarnacki Added documentation on endpoint, middeware stack and routes for Engine
drogus authored
168 #
6f194bb José Valim Small tidy up on Rails::Engine.
josevalim authored
169 # MyRailsApp::Application.routes.draw do
170 # match "/blog/omg" => "main#omg"
171 # mount MyEngine::Engine => "/blog"
172 # end
153df92 Piotr Sarnacki Added documentation on endpoint, middeware stack and routes for Engine
drogus authored
173 #
2373eed Matt Buck Make all references to engines lowercase in docs.
techpeace authored
174 # Now, +Engine+ will get only requests that were not handled by +Application+.
153df92 Piotr Sarnacki Added documentation on endpoint, middeware stack and routes for Engine
drogus authored
175 #
1a161c7 Piotr Sarnacki Document engine_name
drogus authored
176 # == Engine name
177 #
5f5e3b7 Matt Buck Copy-edit and format Rails::Engine docs.
techpeace authored
178 # There are some places where an Engine's name is used:
38310ab Xavier Noria little details seen while doing a pass through what's new in docrails
fxn authored
179 #
5f5e3b7 Matt Buck 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 Piotr Sarnacki Document engine_name
drogus authored
184 #
5f5e3b7 Matt Buck 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 Uģis Ozols Remove duplicate words.
ugisozols authored
186 # <tt>my_engine_engine</tt>. You can change it manually using the <tt>engine_name</tt> method:
1a161c7 Piotr Sarnacki Document engine_name
drogus authored
187 #
6f194bb José Valim Small tidy up on Rails::Engine.
josevalim authored
188 # module MyEngine
189 # class Engine < Rails::Engine
190 # engine_name "my_engine"
191 # end
1a161c7 Piotr Sarnacki Document engine_name
drogus authored
192 # end
193 #
8e955c5 Piotr Sarnacki Should be isolated engine instead of namespaced engine
drogus authored
194 # == Isolated Engine
2e4e1e7 Piotr Sarnacki Added documentation for namespaced Engine
drogus authored
195 #
5f5e3b7 Matt Buck 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 Matt Jankowski 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 José Valim Updated DOCS for engines and added a couple TODOs. Also, commented inter...
josevalim authored
199 #
5f5e3b7 Matt Buck 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 José Valim 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 Piotr Sarnacki Added documentation for namespaced Engine
drogus authored
203 #
6f194bb José Valim Small tidy up on Rails::Engine.
josevalim authored
204 # module MyEngine
205 # class Engine < Rails::Engine
5d5eb2b Piotr Sarnacki Rename namespace method to isolate_namespace.
drogus authored
206 # isolate_namespace MyEngine
6f194bb José Valim Small tidy up on Rails::Engine.
josevalim authored
207 # end
2e4e1e7 Piotr Sarnacki Added documentation for namespaced Engine
drogus authored
208 # end
209 #
2373eed Matt Buck 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 Matt Buck Copy-edit and format Rails::Engine docs.
techpeace authored
211 # the application.
2e4e1e7 Piotr Sarnacki Added documentation for namespaced Engine
drogus authored
212 #
213 # Consider such controller:
214 #
6f194bb José Valim Small tidy up on Rails::Engine.
josevalim authored
215 # module MyEngine
216 # class FooController < ActionController::Base
217 # end
2e4e1e7 Piotr Sarnacki Added documentation for namespaced Engine
drogus authored
218 # end
219 #
2373eed Matt Buck 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 Matt Buck Copy-edit and format Rails::Engine docs.
techpeace authored
221 # <tt>url_helpers</tt> from <tt>MyEngine::Engine.routes</tt>.
2e4e1e7 Piotr Sarnacki Added documentation for namespaced Engine
drogus authored
222 #
71d18ce Ömür Özkir 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 Matt Buck 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 José Valim 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 Matt Buck Copy-edit and format Rails::Engine docs.
techpeace authored
230 #
4baf145 Rafael Valverde Fixed small typo in the Rails::Engine documentation.
rafacv authored
231 # The routes above will automatically point to <tt>MyEngine::ApplicationController</tt>. Furthermore, you don't
737abe4 R.T. Lechow Railties typos.
rtlechow authored
232 # need to use longer url helpers like <tt>my_engine_articles_path</tt>. Instead, you should simply use
5f5e3b7 Matt Buck Copy-edit and format Rails::Engine docs.
techpeace authored
233 # <tt>articles_path</tt> as you would do with your application.
234 #
71d18ce Ömür Özkir 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 Matt Buck 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 R.T. Lechow Railties typos.
rtlechow authored
237 # use the prefix "my_engine". In an isolated engine, the prefix will be omitted in url helpers and
a8b1780 José Valim Updated DOCS for engines and added a couple TODOs. Also, commented inter...
josevalim authored
238 # form fields for convenience.
07411ca Piotr Sarnacki List all of isolated engine changes
drogus authored
239 #
3e7a8cc Vijay Dev formatting results in comments
vijaydev authored
240 # polymorphic_url(MyEngine::Article.new) # => "articles_path"
07411ca Piotr Sarnacki List all of isolated engine changes
drogus authored
241 #
242 # form_for(MyEngine::Article.new) do
3e7a8cc Vijay Dev formatting results in comments
vijaydev authored
243 # text_field :title # => <input type="text" name="article[title]" id="article_title" />
07411ca Piotr Sarnacki List all of isolated engine changes
drogus authored
244 # end
245 #
2f30fb0 Matt Jankowski 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 Vijay Dev formatting results in comments
vijaydev authored
247 # MyEngine::Engine.engine_name will be "my_engine". It will also set MyEngine.table_name_prefix
22a8433 Caius Durling 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 Piotr Sarnacki Added documentation for namespaced Engine
drogus authored
249 #
434139f Piotr Sarnacki Documented mounted helpers
drogus authored
250 # == Using Engine's routes outside Engine
251 #
2373eed Matt Buck 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 Matt Buck Copy-edit and format Rails::Engine docs.
techpeace authored
254 # created to allow you to do that. Consider such a scenario:
434139f Piotr Sarnacki Documented mounted helpers
drogus authored
255 #
3e7a8cc Vijay Dev formatting results in comments
vijaydev authored
256 # # config/routes.rb
6f194bb José Valim Small tidy up on Rails::Engine.
josevalim authored
257 # MyApplication::Application.routes.draw do
258 # mount MyEngine::Engine => "/my_engine", :as => "my_engine"
259 # match "/foo" => "foo#index"
260 # end
434139f Piotr Sarnacki Documented mounted helpers
drogus authored
261 #
5f5e3b7 Matt Buck Copy-edit and format Rails::Engine docs.
techpeace authored
262 # Now, you can use the <tt>my_engine</tt> helper inside your application:
434139f Piotr Sarnacki Documented mounted helpers
drogus authored
263 #
6f194bb José Valim 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 Piotr Sarnacki Documented mounted helpers
drogus authored
268 # end
269 #
5f5e3b7 Matt Buck 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 Piotr Sarnacki Documented mounted helpers
drogus authored
271 #
6f194bb José Valim Small tidy up on Rails::Engine.
josevalim authored
272 # module MyEngine
273 # class BarController
a8b1780 José Valim 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 José Valim Small tidy up on Rails::Engine.
josevalim authored
277 # end
434139f Piotr Sarnacki Documented mounted helpers
drogus authored
278 # end
279 #
2f30fb0 Matt Jankowski 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 Matt Buck Copy-edit and format Rails::Engine docs.
techpeace authored
281 # you can simply omit it.
34cd8a6 Piotr Sarnacki Add some more docs on polymorphic_url with routes proxy
drogus authored
282 #
2f30fb0 Matt Jankowski 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 José Valim Updated DOCS for engines and added a couple TODOs. Also, commented inter...
josevalim authored
287 # attributes for url:
34cd8a6 Piotr Sarnacki Add some more docs on polymorphic_url with routes proxy
drogus authored
288 #
5f5e3b7 Matt Buck Copy-edit and format Rails::Engine docs.
techpeace authored
289 # form_for([my_engine, @user])
34cd8a6 Piotr Sarnacki Add some more docs on polymorphic_url with routes proxy
drogus authored
290 #
5f5e3b7 Matt Buck 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 Piotr Sarnacki Add some more docs on polymorphic_url with routes proxy
drogus authored
292 #
e38b443 Piotr Sarnacki 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 Wojciech Wnętrzak fixed example code indentation
morgoth authored
299 # class ApplicationController < ActionController::Base
300 # helper MyEngine::SharedEngineHelper
301 # end
e38b443 Piotr Sarnacki Add Engine#helpers method which loads all the engine's helpers
drogus authored
302 #
cb76771 Matthew Daubert Minor typo describing engine helpers
MDaubs authored
303 # If you want to include all of the engine's helpers, you can use #helpers method on an engine's
e38b443 Piotr Sarnacki Add Engine#helpers method which loads all the engine's helpers
drogus authored
304 # instance:
305 #
9ce5d51 Wojciech Wnętrzak fixed example code indentation
morgoth authored
306 # class ApplicationController < ActionController::Base
307 # helper MyEngine::Engine.helpers
308 # end
e38b443 Piotr Sarnacki 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 Matthew Daubert Minor typo describing engine helpers
MDaubs authored
312 # only helpers defined in the helpers directory will be included.
e38b443 Piotr Sarnacki Add Engine#helpers method which loads all the engine's helpers
drogus authored
313 #
dfac9b1 Piotr Sarnacki Strengthen documantation on engine's migrations and seed data
drogus authored
314 # == Migrations & seed data
315 #
5f5e3b7 Matt Buck 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 Piotr Sarnacki 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 José Valim Updated DOCS for engines and added a couple TODOs. Also, commented inter...
josevalim authored
322 # rake ENGINE_NAME:install:migrations
dfac9b1 Piotr Sarnacki Strengthen documantation on engine's migrations and seed data
drogus authored
323 #
5f5e3b7 Matt Buck 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 Matt Jankowski misc grammar and clarity changes for rails/engine docs
mjankowski authored
326 # migration in the application and rerun copying migrations.
a2c52f1 Piotr Sarnacki Update documentation for new tasks
drogus authored
327 #
dfac9b1 Piotr Sarnacki 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
5f5e3b7 Matt Buck Copy-edit and format Rails::Engine docs.
techpeace authored
329 # the <tt>seeds.rb</tt> file. You can load that data using the <tt>load_seed</tt> method, e.g.
dfac9b1 Piotr Sarnacki Strengthen documantation on engine's migrations and seed data
drogus authored
330 #
331 # MyEngine::Engine.load_seed
332 #
40b19e0 Piotr Sarnacki Allow to change engine's loading priority with config.railties_order=
drogus authored
333 # == Loading priority
334 #
335 # In order to change engine's priority you can use config.railties_order in main application.
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 José Valim Massive cleanup in Railties and load stack.
josevalim authored
344 class Engine < Railtie
b17e358 José Valim Move configuration to subfolders.
josevalim authored
345 autoload :Configuration, "rails/engine/configuration"
37d3266 José Valim Add missing autoload.
josevalim authored
346 autoload :Railties, "rails/engine/railties"
788fce2 José Valim Create configurable modules and ensure that they are added only on direc...
josevalim authored
347
60281af Stefan Sprenger 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 José Valim Massive cleanup in Railties and load stack.
josevalim authored
356 class << self
5d5eb2b Piotr Sarnacki Rename namespace method to isolate_namespace.
drogus authored
357 attr_accessor :called_from, :isolated
ef4afed Piotr Sarnacki There is no need to make isolated? method with bang-bang, just alias iso...
drogus authored
358 alias :isolated? :isolated
2068b8c Piotr Sarnacki Added tests for railtie_name and aliased it in engine as engine_name
drogus authored
359 alias :engine_name :railtie_name
7fcf859 José Valim Massive cleanup in Railties and load stack.
josevalim authored
360
361 def inherited(base)
f5ee855 José Valim Improve heuristic for railties default name, otherwise railties may be n...
josevalim authored
362 unless base.abstract_railtie?
788fce2 José Valim Create configurable modules and ensure that they are added only on direc...
josevalim authored
363 base.called_from = begin
a5684df José Valim 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 Santiago Pastorino delete from :number until the end
spastorino authored
365 call_stack = caller.map { |p| p.sub(/:\d+.*/, '') }
21ff884 Xavier Noria 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 José Valim Create configurable modules and ensure that they are added only on direc...
josevalim authored
367 end
7fcf859 José Valim Massive cleanup in Railties and load stack.
josevalim authored
368 end
788fce2 José Valim Create configurable modules and ensure that they are added only on direc...
josevalim authored
369
7fcf859 José Valim Massive cleanup in Railties and load stack.
josevalim authored
370 super
371 end
372
3939d6b Piotr Sarnacki Removed ActionDispatch::Static, but left empty MiddlewareStack to unify ...
drogus authored
373 def endpoint(endpoint = nil)
44f0709 Aaron Patterson dealing with some -w warnings on startup
tenderlove authored
374 @endpoint ||= nil
3939d6b Piotr Sarnacki Removed ActionDispatch::Static, but left empty MiddlewareStack to unify ...
drogus authored
375 @endpoint = endpoint if endpoint
376 @endpoint
377 end
c7664d1 Piotr Sarnacki Include application's helpers and router helpers by default, but include...
drogus authored
378
5d5eb2b Piotr Sarnacki Rename namespace method to isolate_namespace.
drogus authored
379 def isolate_namespace(mod)
db8a864 Piotr Sarnacki 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 Piotr Sarnacki Rename namespace method to isolate_namespace.
drogus authored
383 self.isolated = true
74598fe Piotr Sarnacki Do not overwrite _railtie method on namespace while creating isolated en...
drogus authored
384
fd86a1b José Valim 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 Piotr Sarnacki Do not overwrite _railtie method on namespace while creating isolated en...
drogus authored
388 mod.singleton_class.instance_eval do
fd86a1b José Valim Rely on a public contract between railties instead of accessing railtie ...
josevalim authored
389 define_method(:railtie_namespace) { railtie }
74598fe Piotr Sarnacki Do not overwrite _railtie method on namespace while creating isolated en...
drogus authored
390
f821055 Piotr Sarnacki Do not create table_name_prefix method on isolated module if the method ...
drogus authored
391 unless mod.respond_to?(:table_name_prefix)
fd86a1b José Valim 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 Piotr Sarnacki Do not overwrite _railtie method on namespace while creating isolated en...
drogus authored
405 end
fd86a1b José Valim Rely on a public contract between railties instead of accessing railtie ...
josevalim authored
406 end
74598fe Piotr Sarnacki Do not overwrite _railtie method on namespace while creating isolated en...
drogus authored
407 end
e35c204 Piotr Sarnacki Include all helpers from non-namespaced engines
drogus authored
408 end
051127d Piotr Sarnacki Rails::Engine.find(path) - method to find engine by path
drogus authored
409
410 # Finds engine with given path
411 def find(path)
c7cfdd0 Diego Carrion 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 Aaron Patterson only compute path.to_s once
tenderlove authored
415 }
051127d Piotr Sarnacki Rails::Engine.find(path) - method to find engine by path
drogus authored
416 end
7fcf859 José Valim Massive cleanup in Railties and load stack.
josevalim authored
417 end
418
32a5b49 Piotr Sarnacki Move singleton pattern to Railtie and remove Engine::Configurable and Ap...
drogus authored
419 delegate :middleware, :root, :paths, :to => :config
5d5eb2b Piotr Sarnacki Rename namespace method to isolate_namespace.
drogus authored
420 delegate :engine_name, :isolated?, :to => "self.class"
2b75b94 José Valim Plugin is now an Engine.
josevalim authored
421
245dba0 Joseph Wong 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 Joshua Peek Remove implicit controller namespacing from new dsl
josh authored
424 super
d649bf1 José Valim 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 José Valim Plugin is now an Engine.
josevalim authored
426 end
71d18ce Ömür Özkir Changed a few instances of of words in the API docs written in British E...
oem authored
427
245dba0 Joseph Wong 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 Ömür Özkir Changed a few instances of of words in the API docs written in British E...
oem authored
432
38af354 Toshinori Kajihara backport runner fixes to 3-2-stable
kennyj authored
433 def load_runner(app=self)
434 railties.all { |r| r.load_runner(app) }
435 super
436 end
437
351816f José Valim Ensure that eager_load actually takes place just after the middleware st...
josevalim authored
438 def eager_load!
245dba0 Joseph Wong Cherry-picking patch for https://github.com/rails/rails/issues/1460
jhtwong authored
439 railties.all(&:eager_load!)
71d18ce Ömür Özkir Changed a few instances of of words in the API docs written in British E...
oem authored
440
351816f José Valim Ensure that eager_load actually takes place just after the middleware st...
josevalim authored
441 config.eager_load_paths.each do |load_path|
442 matcher = /\A#{Regexp.escape(load_path)}\/(.*)\.rb\Z/
443 Dir.glob("#{load_path}/**/*.rb").sort.each do |file|
444 require_dependency file.sub(matcher, '\1')
445 end
446 end
447 end
448
c787bfd Piotr Sarnacki Engine can now load its own plugins
drogus authored
449 def railties
32a5b49 Piotr Sarnacki Move singleton pattern to Railtie and remove Engine::Configurable and Ap...
drogus authored
450 @railties ||= self.class::Railties.new(config)
c787bfd Piotr Sarnacki Engine can now load its own plugins
drogus authored
451 end
452
e38b443 Piotr Sarnacki Add Engine#helpers method which loads all the engine's helpers
drogus authored
453 def helpers
454 @helpers ||= begin
455 helpers = Module.new
d4bea35 Piotr Sarnacki Make ActionController::Base.modules_for_helpers and ActionController::Ba...
drogus authored
456 all = ActionController::Base.all_helpers_from_path(helpers_paths)
457 ActionController::Base.modules_for_helpers(all).each do |mod|
e38b443 Piotr Sarnacki Add Engine#helpers method which loads all the engine's helpers
drogus authored
458 helpers.send(:include, mod)
459 end
460 helpers
461 end
462 end
463
fd86a1b José Valim Rely on a public contract between railties instead of accessing railtie ...
josevalim authored
464 def helpers_paths
465 paths["app/helpers"].existent
466 end
467
468 def routes_url_helpers
469 routes.url_helpers
470 end
471
ad6be08 Piotr Sarnacki Made Engine valid rack app with its own middleware stack
drogus authored
472 def app
092b148 Piotr Sarnacki Engine can now serve files with ActionDispatch::Static
drogus authored
473 @app ||= begin
474 config.middleware = config.middleware.merge_into(default_middleware_stack)
475 config.middleware.build(endpoint)
476 end
ad6be08 Piotr Sarnacki Made Engine valid rack app with its own middleware stack
drogus authored
477 end
478
479 def endpoint
c989d1a Piotr Sarnacki Engine sets routes as default rack endpoint if no endpoint was given
drogus authored
480 self.class.endpoint || routes
ad6be08 Piotr Sarnacki Made Engine valid rack app with its own middleware stack
drogus authored
481 end
482
483 def call(env)
a132229 Piotr Sarnacki Added ability to set asset_path for engines
drogus authored
484 app.call(env.merge!(env_config))
485 end
486
487 def env_config
488 @env_config ||= {
afc8288 José Valim Remove the ability for engines to serve assets from the public directory...
josevalim authored
489 'action_dispatch.routes' => routes
a132229 Piotr Sarnacki Added ability to set asset_path for engines
drogus authored
490 }
ad6be08 Piotr Sarnacki Made Engine valid rack app with its own middleware stack
drogus authored
491 end
492
08f4713 Piotr Sarnacki Refactored routes reloading to use RouteSet#append instead keeping block...
drogus authored
493 def routes
c989d1a Piotr Sarnacki Engine sets routes as default rack endpoint if no endpoint was given
drogus authored
494 @routes ||= ActionDispatch::Routing::RouteSet.new
08f4713 Piotr Sarnacki Refactored routes reloading to use RouteSet#append instead keeping block...
drogus authored
495 @routes.append(&Proc.new) if block_given?
ec5d846 Piotr Sarnacki Properly reload routes defined in class definition
drogus authored
496 @routes
c989d1a Piotr Sarnacki Engine sets routes as default rack endpoint if no endpoint was given
drogus authored
497 end
498
40b19e0 Piotr Sarnacki Allow to change engine's loading priority with config.railties_order=
drogus authored
499 def ordered_railties
500 railties.all + [self]
501 end
502
675f3ea Piotr Sarnacki Gather initializers from railties in engines to get rid of additional lo...
drogus authored
503 def initializers
504 initializers = []
40b19e0 Piotr Sarnacki Allow to change engine's loading priority with config.railties_order=
drogus authored
505 ordered_railties.each do |r|
506 if r == self
507 initializers += super
508 else
509 initializers += r.initializers
510 end
511 end
675f3ea Piotr Sarnacki Gather initializers from railties in engines to get rid of additional lo...
drogus authored
512 initializers
513 end
514
32a5b49 Piotr Sarnacki Move singleton pattern to Railtie and remove Engine::Configurable and Ap...
drogus authored
515 def config
937f419 Piotr Sarnacki Engine's assets are now served with ActionDispatch::Static
drogus authored
516 @config ||= Engine::Configuration.new(find_root_with_flag("lib"))
32a5b49 Piotr Sarnacki Move singleton pattern to Railtie and remove Engine::Configurable and Ap...
drogus authored
517 end
518
d475de7 Piotr Sarnacki Add helper for loading seed data for engine and application
drogus authored
519 # Load data from db/seeds.rb file. It can be used in to load engines'
520 # seeds, e.g.:
521 #
522 # Blog::Engine.load_seed
523 def load_seed
d649bf1 José Valim Provide a cleaner syntax for paths configuration that does not rely on m...
josevalim authored
524 seed_file = paths["db/seeds"].existent.first
e938247 Aaron Patterson seed file was already tested for existence. ಠ_ಠ
tenderlove authored
525 load(seed_file) if seed_file
d475de7 Piotr Sarnacki Add helper for loading seed data for engine and application
drogus authored
526 end
527
7fcf859 José Valim Massive cleanup in Railties and load stack.
josevalim authored
528 # Add configured load paths to ruby load paths and remove duplicates.
9cfeefb Yehuda Katz Reorganized initializers a bit to enable better hooks for common cases w...
wycats authored
529 initializer :set_load_path, :before => :bootstrap_hook do
9b19a6f José Valim A few changes were done in this commit:
josevalim authored
530 _all_load_paths.reverse_each do |path|
4ae7936 José Valim Got tests working once again.
josevalim authored
531 $LOAD_PATH.unshift(path) if File.directory?(path)
532 end
7fcf859 José Valim Massive cleanup in Railties and load stack.
josevalim authored
533 $LOAD_PATH.uniq!
534 end
535
536 # Set the paths from which Rails will automatically load source files,
537 # and the load_once paths.
9cfeefb Yehuda Katz Reorganized initializers a bit to enable better hooks for common cases w...
wycats authored
538 #
539 # This needs to be an initializer, since it needs to run once
540 # per engine and get the engine as a block parameter
541 initializer :set_autoload_paths, :before => :bootstrap_hook do |app|
9b19a6f José Valim A few changes were done in this commit:
josevalim authored
542 ActiveSupport::Dependencies.autoload_paths.unshift(*_all_autoload_paths)
6f194bb José Valim Small tidy up on Rails::Engine.
josevalim authored
543 ActiveSupport::Dependencies.autoload_once_paths.unshift(*_all_autoload_once_paths)
7fcf859 José Valim Massive cleanup in Railties and load stack.
josevalim authored
544
98240c4 José Valim Get rid of initializers global and create i18n railtie.
josevalim authored
545 # Freeze so future modifications will fail rather than do nothing mysteriously
6f83a50 Xavier Noria renames load_(once_)paths to autoload_(once_)paths in dependencies and c...
fxn authored
546 config.autoload_paths.freeze
9b19a6f José Valim A few changes were done in this commit:
josevalim authored
547 config.eager_load_paths.freeze
6f83a50 Xavier Noria renames load_(once_)paths to autoload_(once_)paths in dependencies and c...
fxn authored
548 config.autoload_once_paths.freeze
7fcf859 José Valim Massive cleanup in Railties and load stack.
josevalim authored
549 end
550
226d8e7 José Valim Refactor MetalLoader and RoutesReloader to rely less on class configurat...
josevalim authored
551 initializer :add_routing_paths do |app|
d649bf1 José Valim Provide a cleaner syntax for paths configuration that does not rely on m...
josevalim authored
552 paths = self.paths["config/routes"].existent
553
554 if routes? || paths.any?
555 app.routes_reloader.paths.unshift(*paths)
08f4713 Piotr Sarnacki Refactored routes reloading to use RouteSet#append instead keeping block...
drogus authored
556 app.routes_reloader.route_sets << routes
98240c4 José Valim Get rid of initializers global and create i18n railtie.
josevalim authored
557 end
558 end
559
1177a40 José Valim 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 José Valim Get rid of initializers global and create i18n railtie.
josevalim authored
562 initializer :add_locales do
d649bf1 José Valim 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 José Valim Massive cleanup in Railties and load stack.
josevalim authored
564 end
565
02c5137 José Valim Add view paths to Engine setup.
josevalim authored
566 initializer :add_view_paths do
d649bf1 José Valim Provide a cleaner syntax for paths configuration that does not rely on m...
josevalim authored
567 views = paths["app/views"].existent
6f194bb José Valim Small tidy up on Rails::Engine.
josevalim authored
568 unless views.empty?
569 ActiveSupport.on_load(:action_controller){ prepend_view_path(views) }
570 ActiveSupport.on_load(:action_mailer){ prepend_view_path(views) }
4aded43 Yehuda Katz Replace the placeholder base_hook API with on_load. To specify some code...
wycats authored
571 end
02c5137 José Valim Add view paths to Engine setup.
josevalim authored
572 end
573
eb367af José Valim `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 José Valim Provide a cleaner syntax for paths configuration that does not rely on m...
josevalim authored
575 environment = paths["config/environments"].existent.first
7cccfed Piotr Sarnacki Allow Engines loading its own environment file from config/environments
drogus authored
576 require environment if environment
577 end
578
d68884f José Valim :group => :assets should only run in the assets environment.
josevalim authored
579 initializer :append_assets_path, :group => :all do |app|
6dda216 Santiago Pastorino 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 José Valim Booya, sprockets now works from Engines.
josevalim authored
583 end
584
d649bf1 José Valim Provide a cleaner syntax for paths configuration that does not rely on m...
josevalim authored
585 initializer :prepend_helpers_path do |app|
5d5eb2b Piotr Sarnacki Rename namespace method to isolate_namespace.
drogus authored
586 if !isolated? || (app == self)
d649bf1 José Valim 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 Piotr Sarnacki Include all helpers from non-namespaced engines
drogus authored
588 end
589 end
590
11aa167 José Valim 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 Piotr Sarnacki I've changed that test along the way, it should actually stay without ch...
drogus authored
595 end
596
b43b686 Piotr Sarnacki 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 Piotr Sarnacki 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 José Valim Remove the ability for engines to serve assets from the public directory...
josevalim authored
604 next unless has_migrations?
a9bf91e Piotr Sarnacki Add 'foo:install:migrations' task to copy migrations from foo engine
drogus authored
605
606 namespace railtie_name do
607 namespace :install do
afc8288 José Valim 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
611 Rake::Task["railties:install:migrations"].invoke
959f857 Piotr Sarnacki Added foo:install:assets task that copies assets from plugins public dir...
drogus authored
612 end
f07cbec Piotr Sarnacki Do not treat information about skipped migrations as WARNINGs but as a N...
drogus authored
613 end
a9bf91e Piotr Sarnacki Add 'foo:install:migrations' task to copy migrations from foo engine
drogus authored
614 end
615 end
616
788fce2 José Valim Create configurable modules and ensure that they are added only on direc...
josevalim authored
617 protected
1860d87 José Valim Ensure asset_path defaults to nil for application
josevalim authored
618
60281af Stefan Sprenger Move load_generators from Rails::Application to Rails::Engine
flippingbits authored
619 def initialize_generators
620 require "rails/generators"
621 end
622
d649bf1 José Valim Provide a cleaner syntax for paths configuration that does not rely on m...
josevalim authored
623 def routes?
624 defined?(@routes)
625 end
626
d84b2f3 José Valim Fix tests.
josevalim authored
627 def has_migrations?
a7a58af Sam Pohlenz Fix has_migrations? check in Rails::Engine
spohlenz authored
628 paths["db/migrate"].existent.any?
d84b2f3 José Valim Fix tests.
josevalim authored
629 end
630
32a5b49 Piotr Sarnacki Move singleton pattern to Railtie and remove Engine::Configurable and Ap...
drogus authored
631 def find_root_with_flag(flag, default=nil)
632 root_path = self.class.called_from
633
634 while root_path && File.directory?(root_path) && !File.exist?("#{root_path}/#{flag}")
635 parent = File.dirname(root_path)
636 root_path = parent != root_path && parent
637 end
638
639 root = File.exist?("#{root_path}/#{flag}") ? root_path : default
640 raise "Could not find root path for #{self}" unless root
641
4a4ff14 José Valim Use RbConfig instead of Config for 1.9.3 compatibility.
josevalim authored
642 RbConfig::CONFIG['host_os'] =~ /mswin|mingw/ ?
32a5b49 Piotr Sarnacki Move singleton pattern to Railtie and remove Engine::Configurable and Ap...
drogus authored
643 Pathname.new(root).expand_path : Pathname.new(root).realpath
644 end
645
3939d6b Piotr Sarnacki Removed ActionDispatch::Static, but left empty MiddlewareStack to unify ...
drogus authored
646 def default_middleware_stack
647 ActionDispatch::MiddlewareStack.new
648 end
788fce2 José Valim Create configurable modules and ensure that they are added only on direc...
josevalim authored
649
6f194bb José Valim Small tidy up on Rails::Engine.
josevalim authored
650 def _all_autoload_once_paths
651 config.autoload_once_paths
652 end
653
9b19a6f José Valim A few changes were done in this commit:
josevalim authored
654 def _all_autoload_paths
655 @_all_autoload_paths ||= (config.autoload_paths + config.eager_load_paths + config.autoload_once_paths).uniq
656 end
657
658 def _all_load_paths
659 @_all_load_paths ||= (config.paths.load_paths + _all_autoload_paths).uniq
788fce2 José Valim Create configurable modules and ensure that they are added only on direc...
josevalim authored
660 end
7fcf859 José Valim Massive cleanup in Railties and load stack.
josevalim authored
661 end
6324eee Jeremy Kemper plugin rails/init.rb deprecation message
jeremy authored
662 end
Something went wrong with that request. Please try again.