Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
e89ef3ce
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,发现更多精彩内容 >>
提交
e89ef3ce
编写于
7月 19, 2014
作者:
R
Rafael Mendonça França
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #16224 from egilburg/renderer_refactors
Some ActionView renderer refactors
上级
433c5286
080c2ba0
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
32 addition
and
17 deletion
+32
-17
actionview/lib/action_view/renderer/abstract_renderer.rb
actionview/lib/action_view/renderer/abstract_renderer.rb
+4
-2
actionview/lib/action_view/renderer/partial_renderer.rb
actionview/lib/action_view/renderer/partial_renderer.rb
+12
-10
actionview/lib/action_view/renderer/template_renderer.rb
actionview/lib/action_view/renderer/template_renderer.rb
+4
-5
actionview/test/template/render_test.rb
actionview/test/template/render_test.rb
+12
-0
未找到文件。
actionview/lib/action_view/renderer/abstract_renderer.rb
浏览文件 @
e89ef3ce
...
...
@@ -29,8 +29,9 @@ def render
def
extract_details
(
options
)
@lookup_context
.
registered_details
.
each_with_object
({})
do
|
key
,
details
|
next
unless
value
=
options
[
key
]
details
[
key
]
=
Array
(
value
)
value
=
options
[
key
]
details
[
key
]
=
Array
(
value
)
if
value
end
end
...
...
@@ -41,6 +42,7 @@ def instrument(name, options={})
def
prepend_formats
(
formats
)
formats
=
Array
(
formats
)
return
if
formats
.
empty?
||
@lookup_context
.
html_fallback_for_js
@lookup_context
.
formats
=
formats
|
@lookup_context
.
formats
end
end
...
...
actionview/lib/action_view/renderer/partial_renderer.rb
浏览文件 @
e89ef3ce
...
...
@@ -312,6 +312,8 @@ def render(context, options, block)
end
end
private
def
render_collection
return
nil
if
@collection
.
blank?
...
...
@@ -353,25 +355,27 @@ def render_partial
# respond to +to_partial_path+ in order to setup the path.
def
setup
(
context
,
options
,
block
)
@view
=
context
partial
=
options
[
:partial
]
@options
=
options
@locals
=
options
[
:locals
]
||
{}
@block
=
block
@locals
=
options
[
:locals
]
||
{}
@details
=
extract_details
(
options
)
prepend_formats
(
options
[
:formats
])
partial
=
options
[
:partial
]
if
String
===
partial
@object
=
options
[
:object
]
@collection
=
collection_from_options
@path
=
partial
@collection
=
collection
else
@object
=
partial
@collection
=
collection_from_object
||
collection_from_options
if
@collection
=
collection_from_object
||
collection
if
@collection
paths
=
@collection_data
=
@collection
.
map
{
|
o
|
partial_path
(
o
)
}
@path
=
paths
.
uniq
.
size
==
1
?
paths
.
first
:
nil
@path
=
paths
.
uniq
.
one?
?
paths
.
first
:
nil
else
@path
=
partial_path
end
...
...
@@ -392,7 +396,7 @@ def setup(context, options, block)
self
end
def
collection
def
collection
_from_options
if
@options
.
key?
(
:collection
)
collection
=
@options
[
:collection
]
collection
.
respond_to?
(
:to_ary
)
?
collection
.
to_ary
:
[]
...
...
@@ -404,9 +408,7 @@ def collection_from_object
end
def
find_partial
if
path
=
@path
find_template
(
path
,
@template_keys
)
end
find_template
(
@path
,
@template_keys
)
if
@path
end
def
find_template
(
path
,
locals
)
...
...
actionview/lib/action_view/renderer/template_renderer.rb
浏览文件 @
e89ef3ce
...
...
@@ -6,19 +6,18 @@ def render(context, options)
@view
=
context
@details
=
extract_details
(
options
)
template
=
determine_template
(
options
)
context
=
@lookup_context
prepend_formats
(
template
.
formats
)
unless
context
.
rendered_format
context
.
rendered_format
=
template
.
formats
.
first
||
formats
.
first
end
@lookup_context
.
rendered_format
||=
(
template
.
formats
.
first
||
formats
.
first
)
render_template
(
template
,
options
[
:layout
],
options
[
:locals
])
end
private
# Determine the template to be rendered using the given options.
def
determine_template
(
options
)
#:nodoc:
def
determine_template
(
options
)
keys
=
options
.
fetch
(
:locals
,
{}).
keys
if
options
.
key?
(
:body
)
...
...
actionview/test/template/render_test.rb
浏览文件 @
e89ef3ce
...
...
@@ -324,6 +324,10 @@ def test_render_partial_using_collection
@controller_view
.
render
(
customers
,
:greeting
=>
"Hello"
)
end
def
test_render_partial_using_collection_without_path
assert_equal
"hi good customer: david0"
,
@controller_view
.
render
([
GoodCustomer
.
new
(
"david"
)
],
greeting:
"hi"
)
end
def
test_render_partial_without_object_or_collection_does_not_generate_partial_name_local_variable
exception
=
assert_raises
ActionView
::
Template
::
Error
do
@controller_view
.
render
(
"partial_name_local_variable"
)
...
...
@@ -388,6 +392,14 @@ def test_render_inline_with_locals_and_compilable_custom_type
ActionView
::
Template
.
unregister_template_handler
:foo
end
def
test_render_body
assert_equal
'some body'
,
@view
.
render
(
body:
'some body'
)
end
def
test_render_plain
assert_equal
'some plaintext'
,
@view
.
render
(
plain:
'some plaintext'
)
end
def
test_render_knows_about_types_registered_when_extensions_are_checked_earlier_in_initialization
ActionView
::
Template
::
Handlers
.
extensions
ActionView
::
Template
.
register_template_handler
:foo
,
CustomHandler
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录