Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
0cac68d3
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 搜索 >>
提交
0cac68d3
编写于
5月 11, 2009
作者:
Y
Yehuda Katz + Carl Lerche
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Revert "Whitespace!"
This reverts commit
a747ab5b
.
上级
ddbeb15a
变更
14
隐藏空白更改
内联
并排
Showing
14 changed file
with
95 addition
and
84 deletion
+95
-84
actionpack/lib/action_controller/abstract.rb
actionpack/lib/action_controller/abstract.rb
+1
-1
actionpack/lib/action_controller/abstract/base.rb
actionpack/lib/action_controller/abstract/base.rb
+11
-8
actionpack/lib/action_controller/abstract/callbacks.rb
actionpack/lib/action_controller/abstract/callbacks.rb
+4
-4
actionpack/lib/action_controller/abstract/exceptions.rb
actionpack/lib/action_controller/abstract/exceptions.rb
+1
-1
actionpack/lib/action_controller/abstract/helpers.rb
actionpack/lib/action_controller/abstract/helpers.rb
+9
-8
actionpack/lib/action_controller/abstract/layouts.rb
actionpack/lib/action_controller/abstract/layouts.rb
+14
-13
actionpack/lib/action_controller/abstract/logger.rb
actionpack/lib/action_controller/abstract/logger.rb
+1
-1
actionpack/lib/action_controller/abstract/renderer.rb
actionpack/lib/action_controller/abstract/renderer.rb
+10
-9
actionpack/lib/action_controller/new_base.rb
actionpack/lib/action_controller/new_base.rb
+1
-1
actionpack/lib/action_controller/new_base/base.rb
actionpack/lib/action_controller/new_base/base.rb
+14
-13
actionpack/lib/action_controller/new_base/hide_actions.rb
actionpack/lib/action_controller/new_base/hide_actions.rb
+6
-5
actionpack/lib/action_controller/new_base/layouts.rb
actionpack/lib/action_controller/new_base/layouts.rb
+8
-6
actionpack/lib/action_controller/new_base/renderer.rb
actionpack/lib/action_controller/new_base/renderer.rb
+12
-11
actionpack/lib/action_controller/new_base/url_for.rb
actionpack/lib/action_controller/new_base/url_for.rb
+3
-3
未找到文件。
actionpack/lib/action_controller/abstract.rb
浏览文件 @
0cac68d3
...
...
@@ -7,4 +7,4 @@ module AbstractController
autoload
:Renderer
,
"action_controller/abstract/renderer"
# === Exceptions
autoload
:ActionNotFound
,
"action_controller/abstract/exceptions"
end
end
\ No newline at end of file
actionpack/lib/action_controller/abstract/base.rb
浏览文件 @
0cac68d3
module
AbstractController
class
Base
attr_internal
:response_body
attr_internal
:response_obj
attr_internal
:action_name
def
self
.
process
(
action
)
new
.
process
(
action
)
end
def
self
.
inherited
(
klass
)
end
def
initialize
self
.
response_obj
=
{}
end
def
process
(
action_name
)
unless
respond_to_action?
(
action_name
)
raise
ActionNotFound
,
"The action '
#{
action_name
}
' could not be found"
end
@_action_name
=
action_name
process_action
self
.
response_obj
[
:body
]
=
self
.
response_body
self
end
private
def
process_action
respond_to?
(
action_name
)
?
send
(
action_name
)
:
send
(
:action_missing
,
action_name
)
end
def
respond_to_action?
(
action_name
)
respond_to?
(
action_name
)
||
respond_to?
(
:action_missing
,
true
)
end
end
end
end
\ No newline at end of file
actionpack/lib/action_controller/abstract/callbacks.rb
浏览文件 @
0cac68d3
...
...
@@ -13,7 +13,7 @@ def process_action
super
end
end
module
ClassMethods
def
_normalize_callback_options
(
options
)
if
only
=
options
[
:only
]
...
...
@@ -21,11 +21,11 @@ def _normalize_callback_options(options)
options
[
:per_key
]
=
{
:if
=>
only
}
end
if
except
=
options
[
:except
]
except
=
Array
(
except
).
map
{
|
e
|
"action_name == :
#{
e
}
"
}.
join
(
" || "
)
except
=
Array
(
except
).
map
{
|
e
|
"action_name == :
#{
e
}
"
}.
join
(
" || "
)
options
[
:per_key
]
=
{
:unless
=>
except
}
end
end
[
:before
,
:after
,
:around
].
each
do
|
filter
|
class_eval
<<-
RUBY_EVAL
,
__FILE__
,
__LINE__
+
1
def
#{
filter
}
_filter(*names, &blk)
...
...
@@ -40,4 +40,4 @@ def #{filter}_filter(*names, &blk)
end
end
end
end
end
\ No newline at end of file
actionpack/lib/action_controller/abstract/exceptions.rb
浏览文件 @
0cac68d3
module
AbstractController
class
ActionNotFound
<
StandardError
;
end
end
end
\ No newline at end of file
actionpack/lib/action_controller/abstract/helpers.rb
浏览文件 @
0cac68d3
...
...
@@ -8,14 +8,14 @@ module Helpers
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
av
=
super
...
...
@@ -23,19 +23,19 @@ def _action_view
av
end
end
module
ClassMethods
def
inherited
(
klass
)
klass
.
master_helper_module
=
Module
.
new
klass
.
master_helper_module
.
__send__
:include
,
master_helper_module
super
end
def
add_template_helper
(
mod
)
master_helper_module
.
module_eval
{
include
mod
}
end
def
helper_method
(
*
meths
)
meths
.
flatten
.
each
do
|
meth
|
master_helper_module
.
class_eval
<<-
ruby_eval
,
__FILE__
,
__LINE__
+
1
...
...
@@ -45,7 +45,7 @@ def #{meth}(*args, &blk)
ruby_eval
end
end
def
helper
(
*
args
,
&
blk
)
args
.
flatten
.
each
do
|
arg
|
case
arg
...
...
@@ -56,5 +56,6 @@ def helper(*args, &blk)
master_helper_module
.
module_eval
(
&
blk
)
if
block_given?
end
end
end
end
end
\ No newline at end of file
actionpack/lib/action_controller/abstract/layouts.rb
浏览文件 @
0cac68d3
...
...
@@ -9,18 +9,18 @@ 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
_write_layout_method
end
def
_implied_layout_name
name
.
underscore
end
# Takes the specified layout and creates a _layout method to be called
# by _default_layout
#
#
# If the specified layout is a:
# String:: return the string
# Symbol:: call the method specified by the symbol
...
...
@@ -49,34 +49,35 @@ def _layout
end
end
end
def
_render_template
(
template
,
options
)
_action_view
.
_render_template_with_layout
(
template
,
options
[
:_layout
])
end
private
def
_layout
()
end
# This will be overwritten
def
_layout_for_name
(
name
)
unless
[
String
,
FalseClass
,
NilClass
].
include?
(
name
.
class
)
raise
ArgumentError
,
"String, false, or nil expected; you passed
#{
name
.
inspect
}
"
end
name
&&
view_paths
.
find_by_parts
(
name
,
{
:formats
=>
formats
},
"layouts"
)
end
def
_default_layout
(
require_layout
=
false
)
if
require_layout
&&
!
_layout
raise
ArgumentError
,
raise
ArgumentError
,
"There was no default layout for
#{
self
.
class
}
in
#{
view_paths
.
inspect
}
"
end
begin
layout
=
_layout_for_name
(
_layout
)
rescue
NameError
=>
e
raise
NoMethodError
,
raise
NoMethodError
,
"You specified
#{
@_layout
.
inspect
}
as the layout, but no such method was found"
end
end
end
end
end
\ No newline at end of file
actionpack/lib/action_controller/abstract/logger.rb
浏览文件 @
0cac68d3
...
...
@@ -6,4 +6,4 @@ module Logger
cattr_accessor
:logger
end
end
end
end
\ No newline at end of file
actionpack/lib/action_controller/abstract/renderer.rb
浏览文件 @
0cac68d3
...
...
@@ -15,22 +15,22 @@ module Renderer
end
def
_action_view
@_action_view
||=
ActionView
::
Base
.
new
(
self
.
class
.
view_paths
,
{},
self
)
@_action_view
||=
ActionView
::
Base
.
new
(
self
.
class
.
view_paths
,
{},
self
)
end
def
render
(
options
=
{})
self
.
response_body
=
render_to_body
(
options
)
end
# Raw rendering of a template to a Rack-compatible body.
# ====
# @option _prefix<String> The template's path prefix
# @option _layout<String> The relative path to the layout template to use
#
#
# :api: plugin
def
render_to_body
(
options
=
{})
name
=
options
[
:_template_name
]
||
action_name
template
=
options
[
:_template
]
||
view_paths
.
find_by_parts
(
name
.
to_s
,
{
:formats
=>
formats
},
options
[
:_prefix
])
_render_template
(
template
,
options
)
end
...
...
@@ -39,7 +39,7 @@ def render_to_body(options = {})
# ====
# @option _prefix<String> The template's path prefix
# @option _layout<String> The relative path to the layout template to use
#
#
# :api: plugin
def
render_to_string
(
options
=
{})
AbstractController
::
Renderer
.
body_to_s
(
render_to_body
(
options
))
...
...
@@ -48,7 +48,7 @@ def render_to_string(options = {})
def
_render_template
(
template
,
options
)
_action_view
.
_render_template_with_layout
(
template
)
end
def
view_paths
()
_view_paths
end
# Return a string representation of a Rack-compatible response body.
...
...
@@ -64,14 +64,15 @@ def self.body_to_s(body)
end
module
ClassMethods
def
append_view_path
(
path
)
self
.
view_paths
<<
path
end
def
view_paths
self
.
_view_paths
end
def
view_paths
=
(
paths
)
self
.
_view_paths
=
paths
.
is_a?
(
ActionView
::
PathSet
)
?
paths
:
ActionView
::
Base
.
process_view_paths
(
paths
)
...
...
actionpack/lib/action_controller/new_base.rb
浏览文件 @
0cac68d3
...
...
@@ -4,4 +4,4 @@ module ActionController
autoload
:Layouts
,
"action_controller/new_base/layouts"
autoload
:Renderer
,
"action_controller/new_base/renderer"
autoload
:UrlFor
,
"action_controller/new_base/url_for"
end
end
\ No newline at end of file
actionpack/lib/action_controller/new_base/base.rb
浏览文件 @
0cac68d3
module
ActionController
class
AbstractBase
<
AbstractController
::
Base
# :api: public
attr_internal
:request
,
:response
,
:params
...
...
@@ -11,46 +12,46 @@ def self.controller_name
# :api: public
def
controller_name
()
self
.
class
.
controller_name
end
# :api: public
# :api: public
def
self
.
controller_path
@controller_path
||=
self
.
name
.
sub
(
/Controller$/
,
''
).
underscore
end
# :api: public
# :api: public
def
controller_path
()
self
.
class
.
controller_path
end
# :api: private
# :api: private
def
self
.
action_methods
@action_names
||=
Set
.
new
(
self
.
public_instance_methods
-
self
::
CORE_METHODS
)
end
# :api: private
# :api: private
def
self
.
action_names
()
action_methods
end
# :api: private
# :api: private
def
action_methods
()
self
.
class
.
action_names
end
# :api: private
def
action_names
()
action_methods
end
# :api: plugin
def
self
.
call
(
env
)
controller
=
new
controller
.
call
(
env
).
to_rack
end
# :api: plugin
def
response_body
=
(
body
)
@_response
.
body
=
body
end
# :api: private
def
call
(
env
)
@_request
=
ActionDispatch
::
Request
.
new
(
env
)
@_response
=
ActionDispatch
::
Response
.
new
process
(
@_request
.
parameters
[
:action
])
end
# :api: private
def
to_rack
response
.
to_a
...
...
actionpack/lib/action_controller/new_base/hide_actions.rb
浏览文件 @
0cac68d3
...
...
@@ -6,20 +6,21 @@ module HideActions
end
def
action_methods
()
self
.
class
.
action_names
end
def
action_names
()
action_methods
end
def
action_names
()
action_methods
end
private
def
respond_to_action?
(
action_name
)
!
hidden_actions
.
include?
(
action_name
)
&&
(
super
||
respond_to?
(
:method_missing
))
end
module
ClassMethods
def
hide_action
(
*
args
)
args
.
each
do
|
arg
|
self
.
hidden_actions
<<
arg
.
to_s
end
end
def
action_methods
@action_names
||=
Set
.
new
(
super
.
reject
{
|
name
|
self
.
hidden_actions
.
include?
(
name
.
to_s
)})
end
...
...
@@ -27,4 +28,4 @@ def action_methods
def
self
.
action_names
()
action_methods
end
end
end
end
end
\ No newline at end of file
actionpack/lib/action_controller/new_base/layouts.rb
浏览文件 @
0cac68d3
...
...
@@ -4,13 +4,13 @@ module Layouts
depends_on
ActionController
::
Renderer
depends_on
AbstractController
::
Layouts
module
ClassMethods
def
_implied_layout_name
controller_path
end
end
def
render_to_body
(
options
)
# render :text => ..., :layout => ...
# or
...
...
@@ -18,20 +18,22 @@ def render_to_body(options)
if
!
options
.
key?
(
:text
)
||
options
.
key?
(
:layout
)
options
[
:_layout
]
=
options
.
key?
(
:layout
)
?
_layout_for_option
(
options
[
:layout
])
:
_default_layout
end
super
end
private
def
_layout_for_option
(
name
)
case
name
when
String
then
_layout_for_name
(
name
)
when
true
then
_default_layout
(
true
)
when
false
,
nil
then
nil
else
raise
ArgumentError
,
"String, true, or false, expected for `layout'; you passed
#{
name
.
inspect
}
"
raise
ArgumentError
,
"String, true, or false, expected for `layout'; you passed
#{
name
.
inspect
}
"
end
end
end
end
actionpack/lib/action_controller/new_base/renderer.rb
浏览文件 @
0cac68d3
...
...
@@ -3,22 +3,22 @@ module Renderer
extend
ActiveSupport
::
DependencyModule
depends_on
AbstractController
::
Renderer
def
initialize
(
*
)
self
.
formats
=
[
:html
]
super
end
def
render
(
action
,
options
=
{})
# TODO: Move this into #render_to_body
if
action
.
is_a?
(
Hash
)
options
,
action
=
action
,
nil
options
,
action
=
action
,
nil
else
options
.
merge!
:action
=>
action
end
_process_options
(
options
)
self
.
response_body
=
render_to_body
(
options
)
end
...
...
@@ -34,17 +34,18 @@ def render_to_body(options)
options
[
:_template_name
]
=
options
[
:template
]
elsif
options
.
key?
(
:action
)
options
[
:_template_name
]
=
options
[
:action
].
to_s
options
[
:_prefix
]
=
_prefix
options
[
:_prefix
]
=
_prefix
end
super
(
options
)
end
private
def
_prefix
controller_path
end
end
def
_text
(
options
)
text
=
options
[
:text
]
...
...
@@ -53,7 +54,7 @@ def _text(options)
else
text
.
to_s
end
end
def
_process_options
(
options
)
if
status
=
options
[
:status
]
response
.
status
=
status
.
to_i
...
...
actionpack/lib/action_controller/new_base/url_for.rb
浏览文件 @
0cac68d3
...
...
@@ -16,7 +16,7 @@ def initialize_current_url
# by this method.
def
default_url_options
(
options
=
nil
)
end
def
rewrite_options
(
options
)
#:nodoc:
if
defaults
=
default_url_options
(
options
)
defaults
.
merge
(
options
)
...
...
@@ -24,7 +24,7 @@ def rewrite_options(options) #:nodoc:
options
end
end
def
url_for
(
options
=
{})
options
||=
{}
case
options
...
...
@@ -37,4 +37,4 @@ def url_for(options = {})
end
end
end
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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录