Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
c1aa5b0e
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,体验更适合开发者的 AI 搜索 >>
提交
c1aa5b0e
编写于
4月 07, 2009
作者:
Y
Yehuda Katz and Carl Lerche
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add depends_on, use, and setup to abstract up ideas about module inheritance.
上级
9c8eaf8e
变更
15
隐藏空白更改
内联
并排
Showing
15 changed file
with
82 addition
and
73 deletion
+82
-73
actionpack/lib/action_controller/abstract/callbacks.rb
actionpack/lib/action_controller/abstract/callbacks.rb
+3
-6
actionpack/lib/action_controller/abstract/helpers.rb
actionpack/lib/action_controller/abstract/helpers.rb
+12
-11
actionpack/lib/action_controller/abstract/layouts.rb
actionpack/lib/action_controller/abstract/layouts.rb
+8
-9
actionpack/lib/action_controller/abstract/logger.rb
actionpack/lib/action_controller/abstract/logger.rb
+2
-2
actionpack/lib/action_controller/abstract/renderer.rb
actionpack/lib/action_controller/abstract/renderer.rb
+8
-12
actionpack/lib/action_controller/new_base/hide_actions.rb
actionpack/lib/action_controller/new_base/hide_actions.rb
+3
-6
actionpack/lib/action_controller/new_base/layouts.rb
actionpack/lib/action_controller/new_base/layouts.rb
+3
-0
actionpack/lib/action_controller/new_base/renderer.rb
actionpack/lib/action_controller/new_base/renderer.rb
+1
-10
actionpack/test/abstract_controller/abstract_controller_test.rb
...pack/test/abstract_controller/abstract_controller_test.rb
+2
-2
actionpack/test/abstract_controller/callbacks_test.rb
actionpack/test/abstract_controller/callbacks_test.rb
+1
-1
actionpack/test/abstract_controller/helper_test.rb
actionpack/test/abstract_controller/helper_test.rb
+2
-2
actionpack/test/abstract_controller/layouts_test.rb
actionpack/test/abstract_controller/layouts_test.rb
+2
-2
actionpack/test/new_base/test_helper.rb
actionpack/test/new_base/test_helper.rb
+8
-10
activesupport/lib/active_support/core_ext/module.rb
activesupport/lib/active_support/core_ext/module.rb
+1
-0
activesupport/lib/active_support/core_ext/module/setup.rb
activesupport/lib/active_support/core_ext/module/setup.rb
+26
-0
未找到文件。
actionpack/lib/action_controller/abstract/callbacks.rb
浏览文件 @
c1aa5b0e
module
AbstractController
module
Callbacks
def
self
.
included
(
klass
)
klass
.
class_eval
do
include
ActiveSupport
::
NewCallbacks
define_callbacks
:process_action
extend
ClassMethods
end
setup
do
include
ActiveSupport
::
NewCallbacks
define_callbacks
:process_action
end
def
process_action
...
...
actionpack/lib/action_controller/abstract/helpers.rb
浏览文件 @
c1aa5b0e
module
AbstractController
module
Helpers
def
self
.
included
(
klass
)
klass
.
class_eval
do
extend
ClassMethods
unless
self
<
::
AbstractController
::
Renderer
raise
"You need to include AbstractController::Renderer before including "
\
"AbstractController::Helpers"
end
extlib_inheritable_accessor
:master_helper_module
self
.
master_helper_module
=
Module
.
new
end
depends_on
Renderer
setup
do
extlib_inheritable_accessor
:master_helper_module
self
.
master_helper_module
=
Module
.
new
end
# def self.included(klass)
# klass.class_eval do
# extlib_inheritable_accessor :master_helper_module
# self.master_helper_module = Module.new
# end
# end
def
_action_view
@_action_view
||=
begin
...
...
actionpack/lib/action_controller/abstract/layouts.rb
浏览文件 @
c1aa5b0e
module
AbstractController
module
Layouts
def
self
.
included
(
base
)
base
.
extend
ClassMethods
end
depends_on
Renderer
module
ClassMethods
def
layout
(
layout
)
unless
[
String
,
Symbol
,
FalseClass
,
NilClass
].
include?
(
layout
.
class
)
raise
ArgumentError
,
"Layouts must be specified as a String, Symbol, false, or nil"
end
@layout
=
layout
||
false
# Converts nil to false
@_layout
=
layout
||
false
# Converts nil to false
_write_layout_method
end
def
_write_layout_method
case
@layout
case
@
_
layout
when
String
self
.
class_eval
%{def _layout() #{@layout.inspect} end}
self
.
class_eval
%{def _layout() #{@
_
layout.inspect} end}
when
Symbol
self
.
class_eval
%{def _layout() #{@layout} end}
self
.
class_eval
%{def _layout() #{@
_
layout} end}
when
false
self
.
class_eval
%{def _layout() end}
else
...
...
@@ -43,7 +42,7 @@ def _render_template(template, options)
private
def
_layout
()
end
# This will be overwritten
def
_layout_for_option
(
name
)
case
name
when
String
then
_layout_for_name
(
name
)
...
...
actionpack/lib/action_controller/abstract/logger.rb
浏览文件 @
c1aa5b0e
module
AbstractController
module
Logger
def
self
.
included
(
klass
)
klass
.
cattr_accessor
:logger
setup
do
cattr_accessor
:logger
end
end
end
\ No newline at end of file
actionpack/lib/action_controller/abstract/renderer.rb
浏览文件 @
c1aa5b0e
...
...
@@ -2,20 +2,16 @@
module
AbstractController
module
Renderer
depends_on
AbstractController
::
Logger
def
self
.
included
(
klass
)
klass
.
class_eval
do
extend
ClassMethods
attr_internal
:formats
extlib_inheritable_accessor
:_view_paths
self
.
_view_paths
||=
ActionView
::
PathSet
.
new
include
AbstractController
::
Logger
end
setup
do
attr_internal
:formats
extlib_inheritable_accessor
:_view_paths
self
.
_view_paths
||=
ActionView
::
PathSet
.
new
end
def
_action_view
@_action_view
||=
ActionView
::
Base
.
new
(
self
.
class
.
view_paths
,
{},
self
)
end
...
...
actionpack/lib/action_controller/new_base/hide_actions.rb
浏览文件 @
c1aa5b0e
module
ActionController
module
HideActions
def
self
.
included
(
klass
)
klass
.
class_eval
do
extend
ClassMethods
extlib_inheritable_accessor
:hidden_actions
self
.
hidden_actions
||=
Set
.
new
end
setup
do
extlib_inheritable_accessor
:hidden_actions
self
.
hidden_actions
||=
Set
.
new
end
def
action_methods
()
self
.
class
.
action_names
end
...
...
actionpack/lib/action_controller/new_base/layouts.rb
浏览文件 @
c1aa5b0e
module
ActionController
module
Layouts
depends_on
ActionController
::
Renderer
depends_on
AbstractController
::
Layouts
def
render_to_string
(
options
)
if
!
options
.
key?
(
:text
)
||
options
.
key?
(
:layout
)
options
[
:_layout
]
=
options
.
key?
(
:layout
)
?
_layout_for_option
(
options
[
:layout
])
:
_default_layout
...
...
actionpack/lib/action_controller/new_base/renderer.rb
浏览文件 @
c1aa5b0e
module
ActionController
module
Renderer
# def self.included(klass)
# klass.extend ClassMethods
# end
#
# module ClassMethods
# def prefix
# @prefix ||= name.underscore
# end
# end
depends_on
AbstractController
::
Renderer
def
initialize
(
*
)
self
.
formats
=
[
:html
]
...
...
actionpack/test/abstract_controller/abstract_controller_test.rb
浏览文件 @
c1aa5b0e
...
...
@@ -27,7 +27,7 @@ class TestBasic < ActiveSupport::TestCase
# Test Render mixin
# ====
class
RenderingController
<
AbstractController
::
Base
includ
e
Renderer
us
e
Renderer
def
_prefix
()
end
...
...
@@ -116,7 +116,7 @@ class TestPrefixedViews < ActiveSupport::TestCase
# ====
# self._layout is used when defined
class
WithLayouts
<
PrefixedViews
includ
e
Layouts
us
e
Layouts
private
def
self
.
layout
(
formats
)
...
...
actionpack/test/abstract_controller/callbacks_test.rb
浏览文件 @
c1aa5b0e
...
...
@@ -4,7 +4,7 @@ module AbstractController
module
Testing
class
ControllerWithCallbacks
<
AbstractController
::
Base
includ
e
AbstractController
::
Callbacks
us
e
AbstractController
::
Callbacks
end
class
Callback1
<
ControllerWithCallbacks
...
...
actionpack/test/abstract_controller/helper_test.rb
浏览文件 @
c1aa5b0e
...
...
@@ -4,8 +4,8 @@ module AbstractController
module
Testing
class
ControllerWithHelpers
<
AbstractController
::
Base
includ
e
Renderer
includ
e
Helpers
us
e
Renderer
us
e
Helpers
def
render
(
string
)
super
(
:_template_name
=>
string
)
...
...
actionpack/test/abstract_controller/layouts_test.rb
浏览文件 @
c1aa5b0e
...
...
@@ -5,8 +5,8 @@ module Layouts
# Base controller for these tests
class
Base
<
AbstractController
::
Base
includ
e
AbstractController
::
Renderer
includ
e
AbstractController
::
Layouts
us
e
AbstractController
::
Renderer
us
e
AbstractController
::
Layouts
self
.
view_paths
=
[
ActionView
::
FixtureTemplate
::
FixturePath
.
new
(
"layouts/hello.erb"
=>
"With String <%= yield %>"
,
...
...
actionpack/test/new_base/test_helper.rb
浏览文件 @
c1aa5b0e
...
...
@@ -26,16 +26,14 @@
module
ActionController
class
Base2
<
AbstractBase
include
AbstractController
::
Callbacks
include
AbstractController
::
Renderer
include
AbstractController
::
Helpers
include
AbstractController
::
Layouts
include
AbstractController
::
Logger
include
ActionController
::
HideActions
include
ActionController
::
UrlFor
include
ActionController
::
Layouts
include
ActionController
::
Renderer
use
AbstractController
::
Callbacks
use
AbstractController
::
Helpers
use
AbstractController
::
Logger
use
ActionController
::
HideActions
use
ActionController
::
UrlFor
use
ActionController
::
Renderer
use
ActionController
::
Layouts
def
self
.
inherited
(
klass
)
::
ActionController
::
Base2
.
subclasses
<<
klass
.
to_s
...
...
activesupport/lib/active_support/core_ext/module.rb
浏览文件 @
c1aa5b0e
...
...
@@ -8,6 +8,7 @@
require
'active_support/core_ext/module/aliasing'
require
'active_support/core_ext/module/model_naming'
require
'active_support/core_ext/module/synchronization'
require
'active_support/core_ext/module/setup'
module
ActiveSupport
module
CoreExtensions
...
...
activesupport/lib/active_support/core_ext/module/setup.rb
0 → 100644
浏览文件 @
c1aa5b0e
class
Module
attr_accessor
:_setup_block
attr_accessor
:_dependencies
def
setup
(
&
blk
)
@_setup_block
=
blk
end
def
use
(
mod
)
return
if
self
<
mod
(
mod
.
_dependencies
||
[]).
each
do
|
dep
|
use
dep
end
# raise "Circular dependencies" if self < mod
include
mod
extend
mod
.
const_get
(
"ClassMethods"
)
if
mod
.
const_defined?
(
"ClassMethods"
)
class_eval
(
&
mod
.
_setup_block
)
if
mod
.
_setup_block
end
def
depends_on
(
mod
)
return
if
self
<
mod
@_dependencies
||=
[]
@_dependencies
<<
mod
end
end
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录