Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

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