Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
6c5a3bb3
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,发现更多精彩内容 >>
提交
6c5a3bb3
编写于
12月 12, 2010
作者:
A
artemave
提交者:
wycats
12月 26, 2010
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
all tests pass
上级
ce21ea78
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
40 addition
and
40 deletion
+40
-40
actionpack/lib/action_view/base.rb
actionpack/lib/action_view/base.rb
+2
-2
actionpack/lib/action_view/lookup_context.rb
actionpack/lib/action_view/lookup_context.rb
+1
-1
actionpack/lib/action_view/renderer/partial_renderer.rb
actionpack/lib/action_view/renderer/partial_renderer.rb
+1
-1
actionpack/lib/action_view/renderer/template_renderer.rb
actionpack/lib/action_view/renderer/template_renderer.rb
+2
-2
actionpack/lib/action_view/template.rb
actionpack/lib/action_view/template.rb
+1
-1
actionpack/test/controller/new_base/render_once_test.rb
actionpack/test/controller/new_base/render_once_test.rb
+4
-4
actionpack/test/template/log_subscriber_test.rb
actionpack/test/template/log_subscriber_test.rb
+3
-3
actionpack/test/template/lookup_context_test.rb
actionpack/test/template/lookup_context_test.rb
+24
-24
actionpack/test/template/template_test.rb
actionpack/test/template/template_test.rb
+2
-2
未找到文件。
actionpack/lib/action_view/base.rb
浏览文件 @
6c5a3bb3
...
...
@@ -232,8 +232,8 @@ def controller_path
@controller_path
||=
controller
&&
controller
.
controller_path
end
def
controller_prefix
@controller_prefix
||=
controller
&&
controller
.
_prefix
def
controller_prefix
es
@controller_prefix
es
||=
controller
&&
controller
.
_prefixes
end
ActiveSupport
.
run_load_hooks
(
:action_view
,
self
)
...
...
actionpack/lib/action_view/lookup_context.rb
浏览文件 @
6c5a3bb3
...
...
@@ -119,7 +119,7 @@ def normalize_name(name, prefixes) #:nodoc:
name
=
name
.
to_s
.
gsub
(
handlers_regexp
,
''
)
parts
=
name
.
split
(
'/'
)
name
=
parts
.
pop
prx
=
if
not
prefixes
or
prefixes
.
empty
?
prx
=
if
prefixes
.
blank
?
[
parts
.
compact
.
join
(
'/'
)]
else
prefixes
.
map
{
|
prefix
|
[
prefix
,
*
parts
].
compact
.
join
(
'/'
)
}
...
...
actionpack/lib/action_view/renderer/partial_renderer.rb
浏览文件 @
6c5a3bb3
...
...
@@ -152,7 +152,7 @@ def partial_path(object = @object)
object
=
object
.
to_model
if
object
.
respond_to?
(
:to_model
)
object
.
class
.
model_name
.
partial_path
.
dup
.
tap
do
|
partial
|
path
=
@view
.
controller_prefix
path
=
@view
.
controller_prefix
es
.
first
partial
.
insert
(
0
,
"
#{
File
.
dirname
(
path
)
}
/"
)
if
partial
.
include?
(
?/
)
&&
path
.
include?
(
?/
)
end
end
...
...
actionpack/lib/action_view/renderer/template_renderer.rb
浏览文件 @
6c5a3bb3
...
...
@@ -22,14 +22,14 @@ def render(options)
def
render_once
(
options
)
paths
,
locals
=
options
[
:once
],
options
[
:locals
]
||
{}
layout
,
keys
=
options
[
:layout
],
locals
.
keys
prefix
=
options
.
fetch
(
:prefix
,
@view
.
controller_prefix
)
prefix
es
=
options
.
fetch
(
:prefixes
,
@view
.
controller_prefixes
)
raise
"render :once expects a String or an Array to be given"
unless
paths
render_with_layout
(
layout
,
locals
)
do
contents
=
[]
Array
.
wrap
(
paths
).
each
do
|
path
|
template
=
find_template
(
path
,
prefix
,
false
,
keys
)
template
=
find_template
(
path
,
prefix
es
,
false
,
keys
)
contents
<<
render_template
(
template
,
nil
,
locals
)
if
@rendered
.
add?
(
template
)
end
contents
.
join
(
"
\n
"
)
...
...
actionpack/lib/action_view/template.rb
浏览文件 @
6c5a3bb3
...
...
@@ -163,7 +163,7 @@ def refresh(view)
name
=
pieces
.
pop
partial
=
!!
name
.
sub!
(
/^_/
,
""
)
lookup
.
disable_cache
do
lookup
.
find_template
(
name
,
pieces
.
join
(
'/'
)
,
partial
,
@locals
)
lookup
.
find_template
(
name
,
[
pieces
.
join
(
'/'
)
]
,
partial
,
@locals
)
end
end
...
...
actionpack/test/controller/new_base/render_once_test.rb
浏览文件 @
6c5a3bb3
...
...
@@ -18,8 +18,8 @@ class RenderOnceController < ActionController::Base
self
.
view_paths
=
[
RESOLVER
]
def
_prefix
"test"
def
_prefix
es
%w(test)
end
def
multiple
...
...
@@ -39,11 +39,11 @@ def with_layout
end
def
with_prefix
render
:once
=>
"result"
,
:prefix
=>
"other"
render
:once
=>
"result"
,
:prefix
es
=>
%w(other)
end
def
with_nil_prefix
render
:once
=>
"test/result"
,
:prefix
=>
nil
render
:once
=>
"test/result"
,
:prefix
es
=>
[]
end
end
...
...
actionpack/test/template/log_subscriber_test.rb
浏览文件 @
6c5a3bb3
...
...
@@ -57,7 +57,7 @@ def test_render_partial_template
end
def
test_render_partial_with_implicit_path
@view
.
stubs
(
:controller_prefix
).
returns
(
"test"
)
@view
.
stubs
(
:controller_prefix
es
).
returns
(
%w(test)
)
@view
.
render
(
Customer
.
new
(
"david"
),
:greeting
=>
"hi"
)
wait
...
...
@@ -74,7 +74,7 @@ def test_render_collection_template
end
def
test_render_collection_with_implicit_path
@view
.
stubs
(
:controller_prefix
).
returns
(
"test"
)
@view
.
stubs
(
:controller_prefix
es
).
returns
(
%w(test)
)
@view
.
render
([
Customer
.
new
(
"david"
),
Customer
.
new
(
"mary"
)
],
:greeting
=>
"hi"
)
wait
...
...
@@ -83,7 +83,7 @@ def test_render_collection_with_implicit_path
end
def
test_render_collection_template_without_path
@view
.
stubs
(
:controller_prefix
).
returns
(
"test"
)
@view
.
stubs
(
:controller_prefix
es
).
returns
(
%w(test)
)
@view
.
render
([
GoodCustomer
.
new
(
"david"
),
Customer
.
new
(
"mary"
)
],
:greeting
=>
"hi"
)
wait
...
...
actionpack/test/template/lookup_context_test.rb
浏览文件 @
6c5a3bb3
...
...
@@ -80,18 +80,18 @@ def teardown
end
test
"find templates using the given view paths and configured details"
do
template
=
@lookup_context
.
find
(
"hello_world"
,
"test"
)
template
=
@lookup_context
.
find
(
"hello_world"
,
%w(test)
)
assert_equal
"Hello world!"
,
template
.
source
@lookup_context
.
locale
=
:da
template
=
@lookup_context
.
find
(
"hello_world"
,
"test"
)
template
=
@lookup_context
.
find
(
"hello_world"
,
%w(test)
)
assert_equal
"Hey verden"
,
template
.
source
end
test
"found templates respects given formats if one cannot be found from template or handler"
do
ActionView
::
Template
::
Handlers
::
ERB
.
expects
(
:default_format
).
returns
(
nil
)
@lookup_context
.
formats
=
[
:text
]
template
=
@lookup_context
.
find
(
"hello_world"
,
"test"
)
template
=
@lookup_context
.
find
(
"hello_world"
,
%w(test)
)
assert_equal
[
:text
],
template
.
formats
end
...
...
@@ -137,44 +137,44 @@ def teardown
test
"gives the key forward to the resolver, so it can be used as cache key"
do
@lookup_context
.
view_paths
=
ActionView
::
FixtureResolver
.
new
(
"test/_foo.erb"
=>
"Foo"
)
template
=
@lookup_context
.
find
(
"foo"
,
"test"
,
true
)
template
=
@lookup_context
.
find
(
"foo"
,
%w(test)
,
true
)
assert_equal
"Foo"
,
template
.
source
# Now we are going to change the template, but it won't change the returned template
# since we will hit the cache.
@lookup_context
.
view_paths
.
first
.
hash
[
"test/_foo.erb"
]
=
"Bar"
template
=
@lookup_context
.
find
(
"foo"
,
"test"
,
true
)
template
=
@lookup_context
.
find
(
"foo"
,
%w(test)
,
true
)
assert_equal
"Foo"
,
template
.
source
# This time we will change the locale. The updated template should be picked since
# lookup_context generated a new key after we changed the locale.
@lookup_context
.
locale
=
:da
template
=
@lookup_context
.
find
(
"foo"
,
"test"
,
true
)
template
=
@lookup_context
.
find
(
"foo"
,
%w(test)
,
true
)
assert_equal
"Bar"
,
template
.
source
# Now we will change back the locale and it will still pick the old template.
# This is expected because lookup_context will reuse the previous key for :en locale.
@lookup_context
.
locale
=
:en
template
=
@lookup_context
.
find
(
"foo"
,
"test"
,
true
)
template
=
@lookup_context
.
find
(
"foo"
,
%w(test)
,
true
)
assert_equal
"Foo"
,
template
.
source
# Finally, we can expire the cache. And the expected template will be used.
@lookup_context
.
view_paths
.
first
.
clear_cache
template
=
@lookup_context
.
find
(
"foo"
,
"test"
,
true
)
template
=
@lookup_context
.
find
(
"foo"
,
%w(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
)
old_template
=
@lookup_context
.
find
(
"foo"
,
%w(test)
,
true
)
template
=
@lookup_context
.
find
(
"foo"
,
"test"
,
true
)
template
=
@lookup_context
.
find
(
"foo"
,
%w(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
)
@lookup_context
.
find
(
"foo"
,
%w(test)
,
true
)
end
assert
@lookup_context
.
cache
...
...
@@ -182,11 +182,11 @@ def teardown
end
test
"data can be stored in cached templates"
do
template
=
@lookup_context
.
find
(
"hello_world"
,
"test"
)
template
=
@lookup_context
.
find
(
"hello_world"
,
%w(test)
)
template
.
data
[
"cached"
]
=
"data"
assert_equal
"Hello world!"
,
template
.
source
template
=
@lookup_context
.
find
(
"hello_world"
,
"test"
)
template
=
@lookup_context
.
find
(
"hello_world"
,
%w(test)
)
assert_equal
"data"
,
template
.
data
[
"cached"
]
assert_equal
"Hello world!"
,
template
.
source
end
...
...
@@ -200,54 +200,54 @@ def setup
end
test
"templates are always found in the resolver but timestamp is checked before being compiled"
do
template
=
@lookup_context
.
find
(
"foo"
,
"test"
,
true
)
template
=
@lookup_context
.
find
(
"foo"
,
%w(test)
,
true
)
assert_equal
"Foo"
,
template
.
source
# Now we are going to change the template, but it won't change the returned template
# since the timestamp is the same.
@resolver
.
hash
[
"test/_foo.erb"
][
0
]
=
"Bar"
template
=
@lookup_context
.
find
(
"foo"
,
"test"
,
true
)
template
=
@lookup_context
.
find
(
"foo"
,
%w(test)
,
true
)
assert_equal
"Foo"
,
template
.
source
# Now update the timestamp.
@resolver
.
hash
[
"test/_foo.erb"
][
1
]
=
Time
.
now
.
utc
template
=
@lookup_context
.
find
(
"foo"
,
"test"
,
true
)
template
=
@lookup_context
.
find
(
"foo"
,
%w(test)
,
true
)
assert_equal
"Bar"
,
template
.
source
end
test
"if no template was found in the second lookup, with no cache, raise error"
do
template
=
@lookup_context
.
find
(
"foo"
,
"test"
,
true
)
template
=
@lookup_context
.
find
(
"foo"
,
%w(test)
,
true
)
assert_equal
"Foo"
,
template
.
source
@resolver
.
hash
.
clear
assert_raise
ActionView
::
MissingTemplate
do
@lookup_context
.
find
(
"foo"
,
"test"
,
true
)
@lookup_context
.
find
(
"foo"
,
%w(test)
,
true
)
end
end
test
"if no template was cached in the first lookup, retrieval should work in the second call"
do
@resolver
.
hash
.
clear
assert_raise
ActionView
::
MissingTemplate
do
@lookup_context
.
find
(
"foo"
,
"test"
,
true
)
@lookup_context
.
find
(
"foo"
,
%w(test)
,
true
)
end
@resolver
.
hash
[
"test/_foo.erb"
]
=
[
"Foo"
,
Time
.
utc
(
2000
)]
template
=
@lookup_context
.
find
(
"foo"
,
"test"
,
true
)
template
=
@lookup_context
.
find
(
"foo"
,
%w(test)
,
true
)
assert_equal
"Foo"
,
template
.
source
end
test
"data can be stored as long as template was not updated"
do
template
=
@lookup_context
.
find
(
"foo"
,
"test"
,
true
)
template
=
@lookup_context
.
find
(
"foo"
,
%w(test)
,
true
)
template
.
data
[
"cached"
]
=
"data"
assert_equal
"Foo"
,
template
.
source
template
=
@lookup_context
.
find
(
"foo"
,
"test"
,
true
)
template
=
@lookup_context
.
find
(
"foo"
,
%w(test)
,
true
)
assert_equal
"data"
,
template
.
data
[
"cached"
]
assert_equal
"Foo"
,
template
.
source
@resolver
.
hash
[
"test/_foo.erb"
][
1
]
=
Time
.
now
.
utc
template
=
@lookup_context
.
find
(
"foo"
,
"test"
,
true
)
template
=
@lookup_context
.
find
(
"foo"
,
%w(test)
,
true
)
assert_nil
template
.
data
[
"cached"
]
assert_equal
"Foo"
,
template
.
source
end
end
\ No newline at end of file
end
actionpack/test/template/template_test.rb
浏览文件 @
6c5a3bb3
...
...
@@ -95,14 +95,14 @@ def test_virtual_path
def
test_refresh_with_templates
@template
=
new_template
(
"Hello"
,
:virtual_path
=>
"test/foo/bar"
)
@template
.
locals
=
[
:key
]
@context
.
lookup_context
.
expects
(
:find_template
).
with
(
"bar"
,
"test/foo"
,
false
,
[
:key
]).
returns
(
"template"
)
@context
.
lookup_context
.
expects
(
:find_template
).
with
(
"bar"
,
%w(test/foo)
,
false
,
[
:key
]).
returns
(
"template"
)
assert_equal
"template"
,
@template
.
refresh
(
@context
)
end
def
test_refresh_with_partials
@template
=
new_template
(
"Hello"
,
:virtual_path
=>
"test/_foo"
)
@template
.
locals
=
[
:key
]
@context
.
lookup_context
.
expects
(
:find_template
).
with
(
"foo"
,
"test"
,
true
,
[
:key
]).
returns
(
"partial"
)
@context
.
lookup_context
.
expects
(
:find_template
).
with
(
"foo"
,
%w(test)
,
true
,
[
:key
]).
returns
(
"partial"
)
assert_equal
"partial"
,
@template
.
refresh
(
@context
)
end
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录