Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
5273bd97
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,发现更多精彩内容 >>
提交
5273bd97
编写于
6月 07, 2010
作者:
J
José Valim
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Make AP test suite green once again and speed up performance in layouts lookup for some cases.
上级
b3d20802
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
39 addition
and
45 deletion
+39
-45
actionpack/lib/action_view/base.rb
actionpack/lib/action_view/base.rb
+1
-1
actionpack/lib/action_view/lookup_context.rb
actionpack/lib/action_view/lookup_context.rb
+33
-18
actionpack/lib/action_view/render/layouts.rb
actionpack/lib/action_view/render/layouts.rb
+3
-12
actionpack/test/template/lookup_context_test.rb
actionpack/test/template/lookup_context_test.rb
+2
-14
未找到文件。
actionpack/lib/action_view/base.rb
浏览文件 @
5273bd97
...
...
@@ -184,7 +184,7 @@ class << self
attr_internal
:captures
,
:request
,
:controller
,
:template
,
:config
delegate
:find_template
,
:template_exists?
,
:formats
,
:formats
=
,
:locale
,
:locale
=
,
:view_paths
,
:view_paths
=
,
:with_fallbacks
,
:update_details
,
:to
=>
:lookup_context
:view_paths
,
:view_paths
=
,
:with_fallbacks
,
:update_details
,
:
with_layout_format
,
:
to
=>
:lookup_context
delegate
:request_forgery_protection_token
,
:template
,
:params
,
:session
,
:cookies
,
:response
,
:headers
,
:flash
,
:action_name
,
:controller_name
,
:to
=>
:controller
...
...
actionpack/lib/action_view/lookup_context.rb
浏览文件 @
5273bd97
...
...
@@ -19,6 +19,7 @@ class LookupContext #:nodoc:
def
self
.
register_detail
(
name
,
options
=
{},
&
block
)
self
.
registered_details
<<
name
self
.
registered_detail_setters
<<
[
name
,
"
#{
name
}
="
]
Accessors
.
send
:define_method
,
:"_
#{
name
}
_defaults"
,
&
block
Accessors
.
module_eval
<<-
METHOD
,
__FILE__
,
__LINE__
+
1
def
#{
name
}
...
...
@@ -27,12 +28,7 @@ def #{name}
def
#{
name
}
=(value)
value = Array.wrap(value.presence || _
#{
name
}
_defaults)
if value != @details[:
#{
name
}
]
@details_key = nil
@details = @details.dup if @details.frozen?
@details[:
#{
name
}
] = value.freeze
end
_set_detail(:
#{
name
}
, value) if value != @details[:
#{
name
}
]
end
METHOD
end
...
...
@@ -63,8 +59,11 @@ def initialize
def
initialize
(
view_paths
,
details
=
{})
@details
,
@details_key
=
{
:handlers
=>
default_handlers
},
nil
@frozen_formats
,
@skip_default_locale
=
false
,
false
self
.
view_paths
=
view_paths
self
.
initialize_details
(
details
)
self
.
registered_detail_setters
.
each
do
|
key
,
setter
|
send
(
setter
,
details
[
key
])
end
end
module
ViewPaths
...
...
@@ -177,11 +176,20 @@ def locale=(value)
super
(
@skip_default_locale
?
I18n
.
locale
:
_locale_defaults
)
end
def
initialize_details
(
details
)
details
=
details
.
dup
registered_detail_setters
.
each
do
|
key
,
setter
|
send
(
setter
,
details
[
key
])
# A method which only uses the first format in the formats array for layout lookup.
# This method plays straight with instance variables for performance reasons.
def
with_layout_format
if
formats
.
size
==
1
yield
else
old_formats
=
formats
_set_detail
(
:formats
,
formats
[
0
,
1
])
begin
yield
ensure
_set_detail
(
:formats
,
formats
)
end
end
end
...
...
@@ -195,14 +203,21 @@ def update_details(new_details)
send
(
setter
,
new_details
[
key
])
if
new_details
.
key?
(
key
)
end
if
block_given?
begin
yield
ensure
@details
=
old_details
end
begin
yield
ensure
@details_key
=
nil
@details
=
old_details
end
end
protected
def
_set_detail
(
key
,
value
)
@details_key
=
nil
@details
=
@details
.
dup
if
@details
.
frozen?
@details
[
key
]
=
value
.
freeze
end
end
include
Accessors
...
...
actionpack/lib/action_view/render/layouts.rb
浏览文件 @
5273bd97
...
...
@@ -57,15 +57,11 @@ def _layout_for(name = nil, &block) #:nodoc:
# This is the method which actually finds the layout using details in the lookup
# context object. If no layout is found, it checkes if at least a layout with
# the given name exists across all details before raising the error.
#
# If self.formats contains several formats, just the first one is considered in
# the layout lookup.
def
find_layout
(
layout
)
begin
if
formats
.
size
==
1
_find_layout
(
layout
)
else
update_details
(
:formats
=>
[
self
.
formats
.
first
])
{
_find_layout
(
layout
)
}
with_layout_format
do
layout
=~
/^\//
?
with_fallbacks
{
find_template
(
layout
)
}
:
find_template
(
layout
)
end
rescue
ActionView
::
MissingTemplate
=>
e
update_details
(
:formats
=>
nil
)
do
...
...
@@ -74,11 +70,6 @@ def find_layout(layout)
end
end
def
_find_layout
(
layout
)
#:nodoc:
layout
=~
/^\//
?
with_fallbacks
{
find_template
(
layout
)
}
:
find_template
(
layout
)
end
# Contains the logic that actually renders the layout.
def
_render_layout
(
layout
,
locals
,
&
block
)
#:nodoc:
layout
.
render
(
self
,
locals
){
|*
name
|
_layout_for
(
*
name
,
&
block
)
}
...
...
actionpack/test/template/lookup_context_test.rb
浏览文件 @
5273bd97
...
...
@@ -26,18 +26,6 @@ def teardown
assert_equal
:en
,
@lookup_context
.
locale
end
test
"allows me to update details"
do
@lookup_context
.
update_details
(
:formats
=>
[
:html
],
:locale
=>
:pt
)
assert_equal
[
:html
],
@lookup_context
.
formats
assert_equal
:pt
,
@lookup_context
.
locale
end
test
"allows me to update an specific detail"
do
@lookup_context
.
update_details
(
:locale
=>
:pt
)
assert_equal
:pt
,
I18n
.
locale
assert_equal
:pt
,
@lookup_context
.
locale
end
test
"allows me to freeze and retrieve frozen formats"
do
@lookup_context
.
formats
.
freeze
assert
@lookup_context
.
formats
.
frozen?
...
...
@@ -54,7 +42,7 @@ def teardown
end
test
"provides getters and setters for formats"
do
@lookup_context
.
formats
=
:html
@lookup_context
.
formats
=
[
:html
]
assert_equal
[
:html
],
@lookup_context
.
formats
end
...
...
@@ -138,7 +126,7 @@ def teardown
keys
<<
@lookup_context
.
details_key
assert_equal
2
,
keys
.
uniq
.
size
@lookup_context
.
formats
=
:html
@lookup_context
.
formats
=
[
:html
]
keys
<<
@lookup_context
.
details_key
assert_equal
3
,
keys
.
uniq
.
size
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录