Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
7e8b7f46
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,发现更多精彩内容 >>
提交
7e8b7f46
编写于
12月 27, 2009
作者:
J
José Valim
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add config.action_controller.include behavior to plugins.
上级
75ba102a
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
53 addition
and
1 deletion
+53
-1
railties/lib/rails/configuration.rb
railties/lib/rails/configuration.rb
+19
-1
railties/lib/rails/plugin.rb
railties/lib/rails/plugin.rb
+18
-0
railties/test/plugins/configuration_test.rb
railties/test/plugins/configuration_test.rb
+16
-0
未找到文件。
railties/lib/rails/configuration.rb
浏览文件 @
7e8b7f46
require
'active_support/ordered_options'
require
'active_support/ordered_options'
module
Rails
module
Rails
# Create a Plugin::Options from ActiveSuppot::OrderedOptions,
# which support the following syntax:
#
# controller.action_controller.include FooBar
#
class
Plugin::Options
<
ActiveSupport
::
OrderedOptions
#:nodoc:
attr_reader
:includes
def
initialize
(
*
args
)
@includes
=
[]
super
end
def
include
(
*
args
)
@includes
.
concat
(
args
)
end
end
# Temporarily separate the plugin configuration class from the main
# Temporarily separate the plugin configuration class from the main
# configuration class while this bit is being cleaned up.
# configuration class while this bit is being cleaned up.
class
Plugin::Configuration
class
Plugin::Configuration
...
@@ -16,7 +34,7 @@ def initialize(base = nil)
...
@@ -16,7 +34,7 @@ def initialize(base = nil)
@options
=
base
.
options
.
dup
@options
=
base
.
options
.
dup
@middleware
=
base
.
middleware
.
dup
@middleware
=
base
.
middleware
.
dup
else
else
@options
=
Hash
.
new
{
|
h
,
k
|
h
[
k
]
=
ActiveSupport
::
Ordered
Options
.
new
}
@options
=
Hash
.
new
{
|
h
,
k
|
h
[
k
]
=
Rails
::
Plugin
::
Options
.
new
}
@middleware
=
ActionDispatch
::
MiddlewareStack
.
new
@middleware
=
ActionDispatch
::
MiddlewareStack
.
new
end
end
end
end
...
...
railties/lib/rails/plugin.rb
浏览文件 @
7e8b7f46
...
@@ -25,6 +25,24 @@ def self.config
...
@@ -25,6 +25,24 @@ def self.config
Configuration
.
default
Configuration
.
default
end
end
# Creates an initializer which includes all given modules to the given class.
#
# module Rails
# class ActionController < Rails::Plugin
# plugin_name :action_controller
# include_modules_in "ActionController::Base"
# end
# end
#
def
self
.
include_modules_in
(
klass
,
from
=
plugin_name
)
self
.
initializer
:"
#{
from
}
.include_modules"
do
|
app
|
klass
=
klass
.
constantize
if
klass
.
is_a?
(
String
)
app
.
config
.
send
(
from
).
includes
.
each
do
|
mod
|
klass
.
send
(
:include
,
mod
.
is_a?
(
String
)
?
mod
.
constantize
:
mod
)
end
end
end
class
Vendored
<
Plugin
class
Vendored
<
Plugin
def
self
.
all
(
list
,
paths
)
def
self
.
all
(
list
,
paths
)
plugins
=
[]
plugins
=
[]
...
...
railties/test/plugins/configuration_test.rb
浏览文件 @
7e8b7f46
...
@@ -8,6 +8,10 @@ def setup
...
@@ -8,6 +8,10 @@ def setup
require
"rails"
require
"rails"
end
end
module
Bar
;
end
module
Baz
;
end
module
All
;
end
test
"config is available to plugins"
do
test
"config is available to plugins"
do
class
Foo
<
Rails
::
Plugin
;
end
class
Foo
<
Rails
::
Plugin
;
end
assert_nil
Foo
.
config
.
action_controller
.
foo
assert_nil
Foo
.
config
.
action_controller
.
foo
...
@@ -24,6 +28,18 @@ class Foo < Rails::Plugin ; config.foo.greetings = "hello" ; end
...
@@ -24,6 +28,18 @@ class Foo < Rails::Plugin ; config.foo.greetings = "hello" ; end
assert_equal
"hello"
,
AppTemplate
::
Application
.
config
.
foo
.
greetings
assert_equal
"hello"
,
AppTemplate
::
Application
.
config
.
foo
.
greetings
end
end
test
"plugin configurations allow modules to be given"
do
class
Foo
<
Rails
::
Plugin
;
config
.
foo
.
include
(
Bar
,
Baz
)
;
end
assert_equal
[
Bar
,
Baz
],
Foo
.
config
.
foo
.
includes
end
test
"plugin includes given modules in given class"
do
class
Foo
<
Rails
::
Plugin
;
config
.
foo
.
include
(
Bar
,
"PluginsTest::ConfigurationTest::Baz"
)
;
include_modules_in
All
;
end
Foo
.
new
.
run_initializers
(
Foo
)
assert
All
.
ancestors
.
include?
(
Bar
)
assert
All
.
ancestors
.
include?
(
Baz
)
end
test
"plugin config merges are deep"
do
test
"plugin config merges are deep"
do
class
Foo
<
Rails
::
Plugin
;
config
.
foo
.
greetings
=
'hello'
;
end
class
Foo
<
Rails
::
Plugin
;
config
.
foo
.
greetings
=
'hello'
;
end
class
MyApp
<
Rails
::
Application
class
MyApp
<
Rails
::
Application
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录