Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
d54d90f2
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,发现更多精彩内容 >>
提交
d54d90f2
编写于
6月 03, 2008
作者:
J
josevalim
提交者:
Joshua Peek
6月 03, 2008
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Allow caches_action to accept a layout option [#198 state:resolved]
Signed-off-by:
N
Joshua Peek
<
josh@joshpeek.com
>
上级
aa177166
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
34 addition
and
3 deletion
+34
-3
actionpack/CHANGELOG
actionpack/CHANGELOG
+2
-0
actionpack/lib/action_controller/caching/actions.rb
actionpack/lib/action_controller/caching/actions.rb
+17
-3
actionpack/test/controller/caching_test.rb
actionpack/test/controller/caching_test.rb
+15
-0
未找到文件。
actionpack/CHANGELOG
浏览文件 @
d54d90f2
*
Allow
caches_action
to
accept
a
layout
option
[
Jos
é
Valim
]
*
Added
Rack
processor
[
Ezra
Zygmuntowicz
,
Josh
Peek
]
...
...
actionpack/lib/action_controller/caching/actions.rb
浏览文件 @
d54d90f2
...
...
@@ -40,6 +40,8 @@ module Caching
# controller.send(:list_url, c.params[:id]) }
# end
#
# If you pass :layout => false, it will only cache your action content. It is useful when your layout has dynamic information.
#
module
Actions
def
self
.
included
(
base
)
#:nodoc:
base
.
extend
(
ClassMethods
)
...
...
@@ -54,7 +56,8 @@ module ClassMethods
def
caches_action
(
*
actions
)
return
unless
cache_configured?
options
=
actions
.
extract_options!
around_filter
(
ActionCacheFilter
.
new
(
:cache_path
=>
options
.
delete
(
:cache_path
)),
{
:only
=>
actions
}.
merge
(
options
))
cache_filter
=
ActionCacheFilter
.
new
(
:layout
=>
options
.
delete
(
:layout
),
:cache_path
=>
options
.
delete
(
:cache_path
))
around_filter
(
cache_filter
,
{
:only
=>
actions
}.
merge
(
options
))
end
end
...
...
@@ -81,7 +84,9 @@ def before(controller)
if
cache
=
controller
.
read_fragment
(
cache_path
.
path
)
controller
.
rendered_action_cache
=
true
set_content_type!
(
controller
,
cache_path
.
extension
)
controller
.
send!
(
:render_for_text
,
cache
)
options
=
{
:text
=>
cache
}
options
.
merge!
(
:layout
=>
true
)
if
cache_layout?
controller
.
send!
(
:render
,
options
)
false
else
controller
.
action_cache_path
=
cache_path
...
...
@@ -90,7 +95,8 @@ def before(controller)
def
after
(
controller
)
return
if
controller
.
rendered_action_cache
||
!
caching_allowed
(
controller
)
controller
.
write_fragment
(
controller
.
action_cache_path
.
path
,
controller
.
response
.
body
)
action_content
=
cache_layout?
?
content_for_layout
(
controller
)
:
controller
.
response
.
body
controller
.
write_fragment
(
controller
.
action_cache_path
.
path
,
action_content
)
end
private
...
...
@@ -105,6 +111,14 @@ def path_options_for(controller, options)
def
caching_allowed
(
controller
)
controller
.
request
.
get?
&&
controller
.
response
.
headers
[
'Status'
].
to_i
==
200
end
def
cache_layout?
@options
[
:layout
]
==
false
end
def
content_for_layout
(
controller
)
controller
.
response
.
layout
&&
controller
.
response
.
template
.
instance_variable_get
(
'@content_for_layout'
)
end
end
class
ActionCachePath
...
...
actionpack/test/controller/caching_test.rb
浏览文件 @
d54d90f2
...
...
@@ -156,6 +156,7 @@ class ActionCachingTestController < ActionController::Base
caches_action
:show
,
:cache_path
=>
'http://test.host/custom/show'
caches_action
:edit
,
:cache_path
=>
Proc
.
new
{
|
c
|
c
.
params
[
:id
]
?
"http://test.host/
#{
c
.
params
[
:id
]
}
;edit"
:
"http://test.host/edit"
}
caches_action
:with_layout
caches_action
:layout_false
,
:layout
=>
false
layout
'talk_from_action.erb'
...
...
@@ -181,6 +182,7 @@ def with_layout
alias_method
:show
,
:index
alias_method
:edit
,
:index
alias_method
:destroy
,
:index
alias_method
:layout_false
,
:with_layout
def
expire
expire_action
:controller
=>
'action_caching_test'
,
:action
=>
'index'
...
...
@@ -263,6 +265,19 @@ def test_action_cache_with_layout
assert_equal
@response
.
body
,
read_fragment
(
'hostname.com/action_caching_test/with_layout'
)
end
def
test_action_cache_with_layout_and_layout_cache_false
get
:layout_false
cached_time
=
content_to_cache
assert_not_equal
cached_time
,
@response
.
body
assert
fragment_exist?
(
'hostname.com/action_caching_test/layout_false'
)
reset!
get
:layout_false
assert_not_equal
cached_time
,
@response
.
body
assert_equal
cached_time
,
read_fragment
(
'hostname.com/action_caching_test/layout_false'
)
end
def
test_action_cache_conditional_options
@request
.
env
[
'HTTP_ACCEPT'
]
=
'application/json'
get
:index
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录