Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
40b19e06
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,发现更多精彩内容 >>
提交
40b19e06
编写于
11月 22, 2011
作者:
P
Piotr Sarnacki
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Allow to change engine's loading priority with config.railties_order=
上级
8549f7a4
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
173 addition
and
4 deletion
+173
-4
railties/lib/rails/application.rb
railties/lib/rails/application.rb
+22
-0
railties/lib/rails/application/configuration.rb
railties/lib/rails/application/configuration.rb
+3
-2
railties/lib/rails/engine.rb
railties/lib/rails/engine.rb
+22
-2
railties/test/railties/engine_test.rb
railties/test/railties/engine_test.rb
+126
-0
未找到文件。
railties/lib/rails/application.rb
浏览文件 @
40b19e06
...
...
@@ -127,6 +127,28 @@ def env_config
})
end
def
ordered_railties
@ordered_railties
||=
begin
order
=
config
.
railties_order
.
map
do
|
railtie
|
if
railtie
==
:main_app
self
elsif
railtie
.
respond_to?
(
:instance
)
railtie
.
instance
else
railtie
end
end
all
=
(
railties
.
all
-
order
)
all
.
push
(
self
)
unless
all
.
include?
(
self
)
order
.
push
(
:all
)
unless
order
.
include?
(
:all
)
index
=
order
.
index
(
:all
)
order
[
index
]
=
all
order
.
reverse
.
flatten
end
end
def
initializers
Bootstrap
.
initializers_for
(
self
)
+
super
+
...
...
railties/lib/rails/application/configuration.rb
浏览文件 @
40b19e06
...
...
@@ -10,8 +10,8 @@ class Configuration < ::Rails::Engine::Configuration
:dependency_loading
,
:filter_parameters
,
:force_ssl
,
:helpers_paths
,
:logger
,
:log_tags
,
:preload_frameworks
,
:reload_plugins
,
:secret_token
,
:serve_static_assets
,
:ssl_options
,
:static_cache_control
,
:session_options
,
:time_zone
,
:whiny_nils
:ssl_options
,
:static_cache_control
,
:session_options
,
:time_zone
,
:whiny_nils
,
:railties_order
attr_writer
:log_level
attr_reader
:encoding
...
...
@@ -35,6 +35,7 @@ def initialize(*)
@middleware
=
app_middleware
@generators
=
app_generators
@cache_store
=
[
:file_store
,
"
#{
root
}
/tmp/cache/"
]
@railties_order
=
[
:all
]
@assets
=
ActiveSupport
::
OrderedOptions
.
new
@assets
.
enabled
=
false
...
...
railties/lib/rails/engine.rb
浏览文件 @
40b19e06
...
...
@@ -330,6 +330,17 @@ module Rails
#
# MyEngine::Engine.load_seed
#
# == Loading priority
#
# In order to change engine's priority you can use config.railties_order in main application.
# It will affect the priority of loading views, helpers, assets and all the other files
# related to engine or application.
#
# Example:
#
# # load Blog::Engine with highest priority, followed by application and other railties
# config.railties_order = [Blog::Engine, :main_app, :all]
#
class
Engine
<
Railtie
autoload
:Configuration
,
"rails/engine/configuration"
autoload
:Railties
,
"rails/engine/railties"
...
...
@@ -480,10 +491,19 @@ def routes
@routes
end
def
ordered_railties
railties
.
all
+
[
self
]
end
def
initializers
initializers
=
[]
railties
.
all
{
|
r
|
initializers
+=
r
.
initializers
}
initializers
+=
super
ordered_railties
.
each
do
|
r
|
if
r
==
self
initializers
+=
super
else
initializers
+=
r
.
initializers
end
end
initializers
end
...
...
railties/test/railties/engine_test.rb
浏览文件 @
40b19e06
...
...
@@ -667,6 +667,132 @@ def baz
assert_equal
expected
,
methods
end
test
"setting priority for engines with config.railties_order"
do
@blog
=
engine
"blog"
do
|
plugin
|
plugin
.
write
"lib/blog.rb"
,
<<-
RUBY
module Blog
class Engine < ::Rails::Engine
end
end
RUBY
end
@plugin
.
write
"lib/bukkits.rb"
,
<<-
RUBY
module Bukkits
class Engine < ::Rails::Engine
isolate_namespace Bukkits
end
end
RUBY
controller
"main"
,
<<-
RUBY
class MainController < ActionController::Base
def foo
render :inline => '<%= render :partial => "shared/foo" %>'
end
def bar
render :inline => '<%= render :partial => "shared/bar" %>'
end
end
RUBY
app_file
"config/routes.rb"
,
<<-
RUBY
Rails.application.routes.draw do
match "/foo" => "main#foo"
match "/bar" => "main#bar"
end
RUBY
@plugin
.
write
"app/views/shared/_foo.html.erb"
,
<<-
RUBY
Bukkit's foo partial
RUBY
app_file
"app/views/shared/_foo.html.erb"
,
<<-
RUBY
App's foo partial
RUBY
@blog
.
write
"app/views/shared/_bar.html.erb"
,
<<-
RUBY
Blog's bar partial
RUBY
app_file
"app/views/shared/_bar.html.erb"
,
<<-
RUBY
App's bar partial
RUBY
@plugin
.
write
"app/assets/javascripts/foo.js"
,
<<-
RUBY
// Bukkit's foo js
RUBY
app_file
"app/assets/javascripts/foo.js"
,
<<-
RUBY
// App's foo js
RUBY
@blog
.
write
"app/assets/javascripts/bar.js"
,
<<-
RUBY
// Blog's bar js
RUBY
app_file
"app/assets/javascripts/bar.js"
,
<<-
RUBY
// App's bar js
RUBY
add_to_config
(
"config.railties_order = [:all, :main_app, Blog::Engine]"
)
boot_rails
require
"
#{
rails_root
}
/config/environment"
get
(
"/foo"
)
assert_equal
"Bukkit's foo partial"
,
last_response
.
body
.
strip
get
(
"/bar"
)
assert_equal
"App's bar partial"
,
last_response
.
body
.
strip
get
(
"/assets/foo.js"
)
assert_equal
"// Bukkit's foo js
\n
;"
,
last_response
.
body
.
strip
get
(
"/assets/bar.js"
)
assert_equal
"// App's bar js
\n
;"
,
last_response
.
body
.
strip
end
test
"railties_order adds :all with lowest priority if not given"
do
@plugin
.
write
"lib/bukkits.rb"
,
<<-
RUBY
module Bukkits
class Engine < ::Rails::Engine
end
end
RUBY
controller
"main"
,
<<-
RUBY
class MainController < ActionController::Base
def foo
render :inline => '<%= render :partial => "shared/foo" %>'
end
end
RUBY
app_file
"config/routes.rb"
,
<<-
RUBY
Rails.application.routes.draw do
match "/foo" => "main#foo"
end
RUBY
@plugin
.
write
"app/views/shared/_foo.html.erb"
,
<<-
RUBY
Bukkit's foo partial
RUBY
app_file
"app/views/shared/_foo.html.erb"
,
<<-
RUBY
App's foo partial
RUBY
add_to_config
(
"config.railties_order = [Bukkits::Engine]"
)
boot_rails
require
"
#{
rails_root
}
/config/environment"
get
(
"/foo"
)
assert_equal
"Bukkit's foo partial"
,
last_response
.
body
.
strip
end
private
def
app
Rails
.
application
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录