Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
6f194bb3
R
rails
项目概览
张重言
/
rails
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
rails
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
6f194bb3
编写于
9月 04, 2010
作者:
J
José Valim
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Small tidy up on Rails::Engine.
上级
23a94559
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
49 addition
and
48 deletion
+49
-48
railties/lib/rails/engine.rb
railties/lib/rails/engine.rb
+49
-48
未找到文件。
railties/lib/rails/engine.rb
浏览文件 @
6f194bb3
...
...
@@ -121,29 +121,29 @@ module Rails
# If you don't specify endpoint, routes will be used as default endpoint. You can use them
# just like you use application's routes:
#
# # ENGINE/config/routes.rb
# MyEngine::Engine.routes.draw do
# match "/" => "posts#index"
# end
#
# ENGINE/config/routes.rb
#
MyEngine::Engine.routes.draw do
#
match "/" => "posts#index"
#
end
#
# == Mount priority
#
# Note that now there can be more than one router in you application and it's better to avoid
# passing requests through many routers. Consider such situation:
#
# MyRailsApp::Application.routes.draw do
# mount MyEngine::Engine => "/blog"
# match "/blog/omg" => "main#omg"
# end
#
MyRailsApp::Application.routes.draw do
#
mount MyEngine::Engine => "/blog"
#
match "/blog/omg" => "main#omg"
#
end
#
# MyEngine is mounted at "/blog" path and additionaly "/blog/omg" points application's controller.
# In such situation request to "/blog/omg" will go through MyEngine and if there is no such route
# in Engine's routes, it will be dispatched to "main#omg". It's much better to swap that:
#
# MyRailsApp::Application.routes.draw do
# match "/blog/omg" => "main#omg"
# mount MyEngine::Engine => "/blog"
# end
#
MyRailsApp::Application.routes.draw do
#
match "/blog/omg" => "main#omg"
#
mount MyEngine::Engine => "/blog"
#
end
#
# Now, Engine will get only requests that were not handled by application.
#
...
...
@@ -153,11 +153,11 @@ module Rails
# to application's public directory. To simplify generating paths for assets, you can set asset_path
# for an Engine:
#
# module MyEngine
# class Engine < Rails::Engine
# config.asset_path = "/my_engine/%s"
# module MyEngine
# class Engine < Rails::Engine
# config.asset_path = "/my_engine/%s"
# end
# end
# end
#
# With such config, asset paths will be automatically modified inside Engine:
# image_path("foo.jpg") #=> "/my_engine/images/foo.jpg"
...
...
@@ -172,11 +172,11 @@ module Rails
# Engine name is set by default based on class name. For MyEngine::Engine it will be my_engine_engine.
# You can change it manually it manually using engine_name method:
#
# module MyEngine
# class Engine < Rails::Engine
# engine_name "my_engine"
# module MyEngine
# class Engine < Rails::Engine
# engine_name "my_engine"
# end
# end
# end
#
# == Namespaced Engine
#
...
...
@@ -186,20 +186,20 @@ module Rails
# engine provides its own routes, you don't want that. To isolate engine's stuff from application
# you can use namespace method:
#
# module MyEngine
# class Engine < Rails::Engine
# namespace MyEngine
# module MyEngine
# class Engine < Rails::Engine
# namespace MyEngine
# end
# end
# end
#
# With such Engine, everything that is inside MyEngine module, will be isolated from application.
#
# Consider such controller:
#
# module MyEngine
# class FooController < ActionController::Base
# module MyEngine
# class FooController < ActionController::Base
# end
# end
# end
#
# If engine is marked as namespaced, FooController has access only to helpers from engine and
# url_helpers from MyEngine::Engine.routes.
...
...
@@ -214,27 +214,27 @@ module Rails
# url_helpers inside application. When you mount Engine in application's routes special helper is
# created to allow doing that. Consider such scenario:
#
# # APP/config/routes.rb
# MyApplication::Application.routes.draw do
# mount MyEngine::Engine => "/my_engine", :as => "my_engine"
# match "/foo" => "foo#index"
# end
#
# APP/config/routes.rb
#
MyApplication::Application.routes.draw do
#
mount MyEngine::Engine => "/my_engine", :as => "my_engine"
#
match "/foo" => "foo#index"
#
end
#
# Now, you can use my_engine helper:
#
# class FooController < ApplicationController
# def index
# my_engine.root_url #=> /my_engine/
# class FooController < ApplicationController
# def index
# my_engine.root_url #=> /my_engine/
# end
# end
# end
#
# There is also 'app' helper that gives you access to application's routes inside Engine:
#
# module MyEngine
# class BarController
# app.foo_path #=> /foo
# module MyEngine
# class BarController
# app.foo_path #=> /foo
# end
# end
# end
#
# Note that :as option takes engine_name as default, so most of the time you can ommit it.
#
...
...
@@ -288,7 +288,6 @@ def endpoint(endpoint = nil)
end
def
namespace
(
mod
)
# TODO: extract that into a module
engine_name
(
generate_railtie_name
(
mod
))
_railtie
=
self
...
...
@@ -386,7 +385,7 @@ def config
# per engine and get the engine as a block parameter
initializer
:set_autoload_paths
,
:before
=>
:bootstrap_hook
do
|
app
|
ActiveSupport
::
Dependencies
.
autoload_paths
.
unshift
(
*
_all_autoload_paths
)
ActiveSupport
::
Dependencies
.
autoload_once_paths
.
unshift
(
*
config
.
autoload_once_paths
)
ActiveSupport
::
Dependencies
.
autoload_once_paths
.
unshift
(
*
_all_
autoload_once_paths
)
# Freeze so future modifications will fail rather than do nothing mysteriously
config
.
autoload_paths
.
freeze
...
...
@@ -419,11 +418,9 @@ def config
initializer
:add_view_paths
do
views
=
paths
.
app
.
views
.
to_a
ActiveSupport
.
on_load
(
:action_controller
)
do
prepend_view_path
(
views
)
end
ActiveSupport
.
on_load
(
:action_mailer
)
do
prepend_view_path
(
views
)
unless
views
.
empty?
ActiveSupport
.
on_load
(
:action_controller
){
prepend_view_path
(
views
)
}
ActiveSupport
.
on_load
(
:action_mailer
){
prepend_view_path
(
views
)
}
end
end
...
...
@@ -433,7 +430,7 @@ def config
end
initializer
:append_asset_paths
do
config
.
asset_path
=
"/
#{
engine_name
}
%s"
unless
config
.
asset_path
config
.
asset_path
||=
"/
#{
engine_name
}
%s"
public_path
=
config
.
paths
.
public
.
to_a
.
first
if
config
.
compiled_asset_path
&&
File
.
exist?
(
public_path
)
...
...
@@ -479,6 +476,10 @@ def default_middleware_stack
ActionDispatch
::
MiddlewareStack
.
new
end
def
_all_autoload_once_paths
config
.
autoload_once_paths
end
def
_all_autoload_paths
@_all_autoload_paths
||=
(
config
.
autoload_paths
+
config
.
eager_load_paths
+
config
.
autoload_once_paths
).
uniq
end
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录