Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
44ebab96
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 搜索 >>
提交
44ebab96
编写于
3月 08, 2010
作者:
J
José Valim
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Rename Template::Lookup to LookupContext.
上级
ea68fe59
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
105 addition
and
105 deletion
+105
-105
actionpack/lib/abstract_controller/rendering.rb
actionpack/lib/abstract_controller/rendering.rb
+11
-24
actionpack/lib/action_view.rb
actionpack/lib/action_view.rb
+1
-0
actionpack/lib/action_view/base.rb
actionpack/lib/action_view/base.rb
+8
-19
actionpack/lib/action_view/lookup_context.rb
actionpack/lib/action_view/lookup_context.rb
+80
-0
actionpack/lib/action_view/render/layouts.rb
actionpack/lib/action_view/render/layouts.rb
+2
-2
actionpack/lib/action_view/render/partials.rb
actionpack/lib/action_view/render/partials.rb
+1
-1
actionpack/lib/action_view/render/rendering.rb
actionpack/lib/action_view/render/rendering.rb
+2
-2
actionpack/lib/action_view/template.rb
actionpack/lib/action_view/template.rb
+0
-1
actionpack/lib/action_view/template/lookup.rb
actionpack/lib/action_view/template/lookup.rb
+0
-56
未找到文件。
actionpack/lib/abstract_controller/rendering.rb
浏览文件 @
44ebab96
...
...
@@ -18,39 +18,26 @@ module ViewPaths
self
.
_view_paths
=
ActionView
::
PathSet
.
new
end
delegate
:f
ormats
,
:formats
=
,
:to
=>
:template_lookup
delegate
:_view_paths
,
:to
=>
:'self.class'
delegate
:f
ind_template
,
:template_exists?
,
:view_paths
,
:formats
,
:formats
=
,
:to
=>
:lookup_context
def
template_lookup
@template_lookup
||=
ActionView
::
Template
::
Lookup
.
new
(
_view_paths
,
details_for_lookup
)
# LookupContext is the object responsible to hold all information required to lookup
# templates, i.e. view paths and details. Check ActionView::LookupContext for more
# information.
def
lookup_context
@lookup_context
||=
ActionView
::
LookupContext
.
new
(
self
.
class
.
_view_paths
,
details_for_lookup
)
end
def
details_for_lookup
{
}
end
# The list of view paths for this controller. See ActionView::ViewPathSet for
# more details about writing custom view paths.
def
view_paths
template_lookup
.
view_paths
end
def
append_view_path
(
path
)
template_lookup
.
view_paths
.
push
(
*
path
)
lookup_context
.
view_paths
.
push
(
*
path
)
end
def
prepend_view_path
(
path
)
template_lookup
.
view_paths
.
unshift
(
*
path
)
end
protected
def
template_exists?
(
*
args
)
template_lookup
.
exists?
(
*
args
)
end
def
find_template
(
*
args
)
template_lookup
.
find
(
*
args
)
lookup_context
.
view_paths
.
unshift
(
*
path
)
end
module
ClassMethods
...
...
@@ -191,12 +178,12 @@ def _normalize_options(options)
options
[
:template
]
||=
(
options
[
:action
]
||
action_name
).
to_s
details
=
_normalize_details
(
options
)
template_lookup
.
details
=
details
lookup_context
.
update_details
(
details
)
options
end
def
_normalize_details
(
options
)
details
=
template_lookup
.
details
details
=
{}
details
[
:formats
]
=
Array
(
options
[
:format
])
if
options
[
:format
]
details
[
:locale
]
=
Array
(
options
[
:locale
])
if
options
[
:locale
]
details
...
...
actionpack/lib/action_view.rb
浏览文件 @
44ebab96
...
...
@@ -42,6 +42,7 @@ module ActionView
autoload
:Rendering
end
autoload
:LookupContext
,
'action_view/lookup_context'
autoload
:MissingTemplate
,
'action_view/base'
autoload
:Resolver
,
'action_view/template/resolver'
autoload
:PathResolver
,
'action_view/template/resolver'
...
...
actionpack/lib/action_view/base.rb
浏览文件 @
44ebab96
...
...
@@ -242,12 +242,11 @@ def inspect
klass
=
self
end
klass
.
new
(
controller
.
template_lookup
,
{},
controller
)
klass
.
new
(
controller
.
lookup_context
,
{},
controller
)
end
def
initialize
(
template_lookup
=
nil
,
assigns_for_first_render
=
{},
controller
=
nil
,
formats
=
nil
)
#:nodoc:
def
initialize
(
lookup_context
=
nil
,
assigns_for_first_render
=
{},
controller
=
nil
,
formats
=
nil
)
#:nodoc:
@config
=
nil
@formats
=
formats
@assigns
=
assigns_for_first_render
.
each
{
|
key
,
value
|
instance_variable_set
(
"@
#{
key
}
"
,
value
)
}
@helpers
=
self
.
class
.
helpers
||
Module
.
new
...
...
@@ -256,27 +255,17 @@ def initialize(template_lookup = nil, assigns_for_first_render = {}, controller
@_content_for
=
Hash
.
new
{
|
h
,
k
|
h
[
k
]
=
ActiveSupport
::
SafeBuffer
.
new
}
@_virtual_path
=
nil
@template_lookup
=
template_lookup
.
is_a?
(
ActionView
::
Template
::
Lookup
)
?
template_lookup
:
ActionView
::
Template
::
Lookup
.
new
(
template_lookup
)
@lookup_context
=
lookup_context
.
is_a?
(
ActionView
::
LookupContext
)
?
lookup_context
:
ActionView
::
LookupContext
.
new
(
lookup_context
)
@lookup_context
.
formats
=
formats
if
formats
end
attr_internal
:controller
,
:template
,
:config
attr_reader
:template_lookup
delegate
:find
,
:formats
,
:formats
=
,
:view_paths
,
:view_paths
=
,
:to
=>
:template_lookup
attr_reader
:lookup_context
def
update_details
(
details
)
old_details
=
template_lookup
.
details
template_lookup
.
details
=
old_details
.
merge
(
details
)
if
block_given?
begin
yield
ensure
template_lookup
.
details
=
old_details
end
end
end
delegate
:find_template
,
:template_exists?
,
:formats
,
:formats
=
,
:view_paths
,
:view_paths
=
,
:update_details
,
:to
=>
:lookup_context
def
punctuate_body!
(
part
)
flush_output_buffer
...
...
actionpack/lib/action_view/lookup_context.rb
0 → 100644
浏览文件 @
44ebab96
module
ActionView
# LookupContext is the object responsible to hold all information required to lookup
# templates, i.e. view paths and details. The LookupContext is also responsible to
# generate a key, given to view paths, used in the resolver cache lookup. Since
# this key is generated just once during the request, it speeds up all cache accesses.
class
LookupContext
#:nodoc:
attr_reader
:details
,
:view_paths
class
DetailsKey
#:nodoc:
attr_reader
:details
alias
:eql?
:equal?
@details_keys
=
Hash
.
new
def
self
.
get
(
details
)
@details_keys
[
details
]
||=
new
(
details
)
end
def
initialize
(
details
)
@details
,
@hash
=
details
,
details
.
hash
end
end
def
initialize
(
view_paths
,
details
=
{})
@details
,
@details_key
=
details
,
nil
self
.
view_paths
=
view_paths
end
# Shortcut to read formats from details.
def
formats
@details
[
:formats
]
end
# Shortcut to set formats in details.
def
formats
=
(
value
)
self
.
details
=
@details
.
merge
(
:formats
=>
Array
(
value
))
end
# Whenever setting view paths, makes a copy so we can manipulate then in
# instance objects as we wish.
def
view_paths
=
(
paths
)
@view_paths
=
ActionView
::
Base
.
process_view_paths
(
paths
)
end
# Setter for details. Everything this method is invoked, we need to nullify
# the details key if it changed.
def
details
=
(
details
)
@details
=
details
@details_key
=
nil
if
@details_key
&&
@details_key
.
details
!=
details
end
def
details_key
@details_key
||=
DetailsKey
.
get
(
details
)
unless
details
.
empty?
end
# Update the details keys by merging the given hash into the current
# details hash. If a block is given, the details are modified just during
# the execution of the block and reverted to the previous value after.
def
update_details
(
new_details
)
old_details
=
self
.
details
self
.
details
=
old_details
.
merge
(
new_details
)
if
block_given?
begin
yield
ensure
self
.
details
=
old_details
end
end
end
def
find_template
(
name
,
prefix
=
nil
,
partial
=
false
)
@view_paths
.
find
(
name
,
details
,
prefix
,
partial
||
false
,
details_key
)
end
def
template_exists?
(
name
,
prefix
=
nil
,
partial
=
false
)
@view_paths
.
exists?
(
name
,
details
,
prefix
,
partial
||
false
,
details_key
)
end
end
end
\ No newline at end of file
actionpack/lib/action_view/render/layouts.rb
浏览文件 @
44ebab96
...
...
@@ -48,10 +48,10 @@ def _layout_for(name = nil, &block) #:nodoc:
# the given name exists across all details before raising the error.
def
_find_layout
(
layout
)
#:nodoc:
begin
find
(
layout
)
find
_template
(
layout
)
rescue
ActionView
::
MissingTemplate
=>
e
update_details
(
:formats
=>
nil
)
do
raise
unless
template_
lookup
.
exists?
(
layout
)
raise
unless
template_exists?
(
layout
)
end
end
end
...
...
actionpack/lib/action_view/render/partials.rb
浏览文件 @
44ebab96
...
...
@@ -294,7 +294,7 @@ def collection
def
find_template
(
path
=
@path
)
return
path
unless
path
.
is_a?
(
String
)
prefix
=
@view
.
controller_path
unless
path
.
include?
(
?/
)
@view
.
find
(
path
,
prefix
,
true
)
@view
.
find
_template
(
path
,
prefix
,
true
)
end
def
partial_path
(
object
=
@object
)
...
...
actionpack/lib/action_view/render/rendering.rb
浏览文件 @
44ebab96
...
...
@@ -63,9 +63,9 @@ def _determine_template(options) #:nodoc:
elsif
options
.
key?
(
:text
)
Template
::
Text
.
new
(
options
[
:text
],
self
.
formats
.
try
(
:first
))
elsif
options
.
key?
(
:file
)
find
(
options
[
:file
],
options
[
:_prefix
])
find
_template
(
options
[
:file
],
options
[
:_prefix
])
elsif
options
.
key?
(
:template
)
find
(
options
[
:template
],
options
[
:_prefix
])
find
_template
(
options
[
:template
],
options
[
:_prefix
])
end
end
...
...
actionpack/lib/action_view/template.rb
浏览文件 @
44ebab96
...
...
@@ -13,7 +13,6 @@ class Template
autoload
:Handler
autoload
:Handlers
autoload
:Text
autoload
:Lookup
end
extend
Template
::
Handlers
...
...
actionpack/lib/action_view/template/lookup.rb
已删除
100644 → 0
浏览文件 @
ea68fe59
module
ActionView
class
Template
class
Lookup
attr_reader
:details
,
:view_paths
class
DetailsKey
attr_reader
:details
alias
:eql?
:equal?
@details_keys
=
Hash
.
new
def
self
.
get
(
details
)
@details_keys
[
details
]
||=
new
(
details
)
end
def
initialize
(
details
)
@details
,
@hash
=
details
,
details
.
hash
end
end
def
initialize
(
view_paths
,
details
=
{})
@details
=
details
self
.
view_paths
=
view_paths
end
def
formats
@details
[
:formats
]
end
def
formats
=
(
value
)
self
.
details
=
@details
.
merge
(
:formats
=>
Array
(
value
))
end
def
view_paths
=
(
paths
)
@view_paths
=
ActionView
::
Base
.
process_view_paths
(
paths
)
end
def
details
=
(
details
)
@details
=
details
@details_key
=
nil
if
@details_key
&&
@details_key
.
details
!=
details
end
def
details_key
@details_key
||=
DetailsKey
.
get
(
details
)
unless
details
.
empty?
end
def
find
(
name
,
prefix
=
nil
,
partial
=
false
)
@view_paths
.
find
(
name
,
details
,
prefix
,
partial
||
false
,
details_key
)
end
def
exists?
(
name
,
prefix
=
nil
,
partial
=
false
)
@view_paths
.
exists?
(
name
,
details
,
prefix
,
partial
||
false
,
details_key
)
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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录