Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
c7760809
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,发现更多精彩内容 >>
提交
c7760809
编写于
10月 07, 2010
作者:
J
José Valim
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Allow cache to be temporarily disabled through lookup_context.
上级
c563f10f
变更
5
显示空白变更内容
内联
并排
Showing
5 changed file
with
53 addition
and
6 deletion
+53
-6
actionpack/lib/action_view/lookup_context.rb
actionpack/lib/action_view/lookup_context.rb
+12
-1
actionpack/lib/action_view/template.rb
actionpack/lib/action_view/template.rb
+3
-1
actionpack/lib/action_view/testing/resolvers.rb
actionpack/lib/action_view/testing/resolvers.rb
+5
-3
actionpack/test/controller/new_base/render_template_test.rb
actionpack/test/controller/new_base/render_template_test.rb
+12
-1
actionpack/test/template/lookup_context_test.rb
actionpack/test/template/lookup_context_test.rb
+21
-0
未找到文件。
actionpack/lib/action_view/lookup_context.rb
浏览文件 @
c7760809
...
...
@@ -61,6 +61,7 @@ def initialize
def
initialize
(
view_paths
,
details
=
{})
@details
,
@details_key
=
{
:handlers
=>
default_handlers
},
nil
@frozen_formats
,
@skip_default_locale
=
false
,
false
@cache
=
details
.
key?
(
:cache
)
?
details
.
delete
(
:cache
)
:
true
self
.
view_paths
=
view_paths
self
.
registered_detail_setters
.
each
do
|
key
,
setter
|
...
...
@@ -130,10 +131,20 @@ def handlers_regexp #:nodoc:
end
module
Details
attr_accessor
:cache
# Calculate the details key. Remove the handlers from calculation to improve performance
# since the user cannot modify it explicitly.
def
details_key
#:nodoc:
@details_key
||=
DetailsKey
.
get
(
@details
)
@details_key
||=
DetailsKey
.
get
(
@details
)
if
@cache
end
# Temporary skip passing the details_key forward.
def
disable_cache
old_value
,
@cache
=
@cache
,
false
yield
ensure
@cache
=
old_value
end
# Freeze the current formats in the lookup context. By freezing them, you are guaranteeing
...
...
actionpack/lib/action_view/template.rb
浏览文件 @
c7760809
...
...
@@ -286,7 +286,9 @@ def refresh(view)
pieces
=
@virtual_path
.
split
(
"/"
)
name
=
pieces
.
pop
partial
=
name
.
sub!
(
/^_/
,
""
)
view
.
find_template
(
name
,
pieces
.
join
,
partial
||
false
,
[
"unlikely_local_key"
])
view
.
lookup_context
.
disable_cache
do
view
.
find_template
(
name
,
pieces
.
join
,
partial
||
false
,
@locals
)
end
end
def
method_name
...
...
actionpack/lib/action_view/testing/resolvers.rb
浏览文件 @
c7760809
...
...
@@ -16,16 +16,18 @@ def initialize(hash = {})
private
def
query
(
path
,
exts
,
formats
)
query
=
Regexp
.
escape
(
path
)
query
=
""
exts
.
each
do
|
ext
|
query
<<
'('
<<
ext
.
map
{
|
e
|
e
&&
Regexp
.
escape
(
".
#{
e
}
"
)
}.
join
(
'|'
)
<<
'|)'
end
query
=
/^(
#{
Regexp
.
escape
(
path
)
}
)
#{
query
}
$/
templates
=
[]
@hash
.
select
{
|
k
,
v
|
k
=~
/^
#{
query
}
$/
}.
each
do
|
_path
,
source
|
@hash
.
each
do
|
_path
,
source
|
next
unless
_path
=~
query
handler
,
format
=
extract_handler_and_format
(
_path
,
formats
)
templates
<<
Template
.
new
(
source
,
_path
,
handler
,
:virtual_path
=>
_path
,
:format
=>
format
)
:virtual_path
=>
$1
,
:format
=>
format
)
end
templates
.
sort_by
{
|
t
|
-
t
.
identifier
.
match
(
/^
#{
query
}
$/
).
captures
.
reject
(
&
:blank?
).
size
}
...
...
actionpack/test/controller/new_base/render_template_test.rb
浏览文件 @
c7760809
...
...
@@ -11,7 +11,8 @@ class WithoutLayoutController < ActionController::Base
"with_raw.html.erb"
=>
"Hello <%=raw '<strong>this is raw</strong>' %>"
,
"test/with_json.html.erb"
=>
"<%= render :template => 'test/with_json.json' %>"
,
"test/with_json.json.erb"
=>
"<%= render :template => 'test/final' %>"
,
"test/final.json.erb"
=>
"{ final: json }"
"test/final.json.erb"
=>
"{ final: json }"
,
"test/with_error.html.erb"
=>
"<%= idontexist %>"
)]
def
index
...
...
@@ -49,6 +50,10 @@ def builder_template
def
with_raw
render
:template
=>
"with_raw"
end
def
with_error
render
:template
=>
"test/with_error"
end
end
class
TestWithoutLayout
<
Rack
::
TestCase
...
...
@@ -101,6 +106,12 @@ class TestWithoutLayout < Rack::TestCase
assert_content_type
"text/html; charset=utf-8"
assert_response
"{ final: json }"
end
test
"rendering a template with error properly exceprts the code"
do
get
:with_error
assert_status
500
assert_match
"undefined local variable or method `idontexist'"
,
response
.
body
end
end
class
WithLayoutController
<
::
ApplicationController
...
...
actionpack/test/template/lookup_context_test.rb
浏览文件 @
c7760809
...
...
@@ -163,4 +163,25 @@ def teardown
template
=
@lookup_context
.
find
(
"foo"
,
"test"
,
true
)
assert_equal
"Bar"
,
template
.
source
end
test
"can disable the cache on demand"
do
@lookup_context
.
view_paths
=
ActionView
::
FixtureResolver
.
new
(
"test/_foo.erb"
=>
"Foo"
)
old_template
=
@lookup_context
.
find
(
"foo"
,
"test"
,
true
)
template
=
@lookup_context
.
find
(
"foo"
,
"test"
,
true
)
assert_equal
template
,
old_template
assert
@lookup_context
.
cache
template
=
@lookup_context
.
disable_cache
do
assert
!
@lookup_context
.
cache
@lookup_context
.
find
(
"foo"
,
"test"
,
true
)
end
assert
@lookup_context
.
cache
assert_not_equal
template
,
old_template
end
test
"can have cache disabled on initialization"
do
assert
!
ActionView
::
LookupContext
.
new
(
FIXTURE_LOAD_PATH
,
:cache
=>
false
).
cache
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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录