Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
bf412c9e
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,体验更适合开发者的 AI 搜索 >>
提交
bf412c9e
编写于
8月 08, 2009
作者:
Y
Yehuda Katz
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Clean up initializer and some of the internals of PartialRenderer
上级
b5b1576a
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
45 addition
and
49 deletion
+45
-49
actionpack/lib/action_view/helpers/form_helper.rb
actionpack/lib/action_view/helpers/form_helper.rb
+4
-0
actionpack/lib/action_view/render/partials.rb
actionpack/lib/action_view/render/partials.rb
+41
-49
未找到文件。
actionpack/lib/action_view/helpers/form_helper.rb
浏览文件 @
bf412c9e
...
...
@@ -936,6 +936,10 @@ def self.model_name
@model_name
||=
Struct
.
new
(
:partial_path
).
new
(
name
.
demodulize
.
underscore
.
sub!
(
/_builder$/
,
''
))
end
def
to_model
self
end
def
initialize
(
object_name
,
object
,
template
,
options
,
proc
)
@nested_child_index
=
{}
@object_name
,
@object
,
@template
,
@options
,
@proc
=
object_name
,
object
,
template
,
options
,
proc
...
...
actionpack/lib/action_view/render/partials.rb
浏览文件 @
bf412c9e
...
...
@@ -177,69 +177,62 @@ def self.partial_names
@partial_names
||=
Hash
.
new
{
|
h
,
k
|
h
[
k
]
=
ActiveSupport
::
ConcurrentHash
.
new
}
end
def
initialize
(
view_context
,
options
,
formats
)
object
=
options
[
:partial
]
def
initialize
(
view_context
,
options
)
partial
=
options
[
:partial
]
@view
,
@formats
=
view_context
,
formats
@view
=
view_context
@options
=
options
||
{}
@locals
=
options
[
:locals
]
||
{}
@layout
=
options
[
:layout
]
if
object
.
is_a?
(
String
)
@path
=
object
elsif
@object
=
object
@path
=
partial_path
unless
collection
end
@partial_names
=
self
.
class
.
partial_names
[
@view
.
controller
.
class
]
@templates
,
@formats_hash
=
Hash
.
new
{
|
h
,
k
|
h
[
k
]
=
{}},
view_context
.
formats
.
hash
@locals
=
options
[
:locals
]
||
{}
@object
||=
@options
[
:object
]
||
@locals
[
:object
]
@layout
=
options
[
:layout
]
if
partial
.
is_a?
(
String
)
@object
,
@path
=
options
[
:object
],
partial
else
@object
=
partial
@path
=
partial_path
(
partial
)
end
end
def
render
(
&
block
)
template
=
find
if
@path
if
collection
render_collection
(
template
,
&
block
)
else
render_object
(
template
,
&
block
)
end
collection
?
render_collection
(
&
block
)
:
render_object
(
&
block
)
end
def
render_template
(
template
,
&
block
)
def
render_template
(
template
,
object
=
@object
,
&
block
)
@options
[
:_template
]
=
template
@locals
[
:object
]
=
@locals
[
template
.
variable_name
]
=
@
object
@locals
[
@options
[
:as
]]
=
@
object
if
@options
[
:as
]
@locals
[
:object
]
=
@locals
[
template
.
variable_name
]
=
object
@locals
[
@options
[
:as
]]
=
object
if
@options
[
:as
]
content
=
@view
.
_render_single_template
(
template
,
@locals
,
&
block
)
return
content
if
block_given?
||
!
@layout
find
(
@layout
).
render
(
@view
,
@locals
)
{
content
}
find
_template
(
@layout
).
render
(
@view
,
@locals
)
{
content
}
end
def
render_object
(
template
,
&
block
)
@object
||=
@locals
[
template
.
variable_name
]
render_template
(
template
,
&
block
)
def
render_object
(
&
block
)
template
=
find_template
render_template
(
template
,
@object
||
@locals
[
template
.
variable_name
],
&
block
)
end
def
render_collection
(
passed_template
=
nil
,
&
block
)
@options
[
:_template
]
=
p
asse
d_template
def
render_collection
(
&
block
)
@options
[
:_template
]
=
p
rovided_template
=
@path
&&
fin
d_template
return
nil
if
collection
.
blank?
if
@options
.
key?
(
:spacer_template
)
spacer
=
@view
.
render_partial
(
:partial
=>
@options
[
:spacer_template
],
:_details
=>
@options
[
:_details
])
spacer
=
render_template
(
find_template
(
@options
[
:spacer_template
]))
end
index
=
0
segments
=
[]
collection
.
map
do
|
object
|
@object
,
@path
=
object
,
partial_path
template
=
passed_template
||
find
collection
.
each_with_index
do
|
object
,
index
|
template
=
provided_template
||
find_template
(
partial_path
(
object
))
@locals
[
template
.
counter_name
]
=
index
index
+=
1
segments
<<
render_template
(
template
,
object
,
&
block
)
end
render_template
(
template
,
&
block
)
end
.
join
(
spacer
)
segments
.
join
(
spacer
)
end
private
...
...
@@ -251,21 +244,20 @@ def collection
end
end
def
find
(
path
=
@path
)
prefix
=
@view
.
controller
.
controller_path
unless
path
.
include?
(
?/
)
@view
.
find
(
path
,
{
:formats
=>
@view
.
formats
},
prefix
,
true
)
def
find_template
(
path
=
@path
)
@templates
[
path
][
@formats_hash
]
||=
begin
prefix
=
@view
.
controller
.
controller_path
unless
path
.
include?
(
?/
)
@view
.
find
(
path
,
{
:formats
=>
@view
.
formats
},
prefix
,
true
)
end
end
def
partial_path
(
object
=
@object
)
self
.
class
.
partial_names
[
@view
.
controller
.
class
]
[
object
.
class
]
||=
begin
return
nil
unless
object
.
class
.
respond_to?
(
:model_name
)
@partial_names
[
object
.
class
]
||=
begin
return
nil
unless
object
.
respond_to?
(
:to_model
)
name
=
object
.
class
.
model_name
path
=
@view
.
controller_path
if
path
&&
path
.
include?
(
?/
)
File
.
join
(
File
.
dirname
(
path
),
name
.
partial_path
)
else
name
.
partial_path
object
.
to_model
.
class
.
model_name
.
partial_path
.
tap
do
|
partial
|
path
=
@view
.
controller_path
partial
.
insert
(
0
,
"
#{
File
.
dirname
(
path
)
}
/"
)
if
path
.
include?
(
?/
)
end
end
end
...
...
@@ -279,7 +271,7 @@ def render_partial(options)
end
def
_render_partial
(
options
,
&
block
)
#:nodoc:
PartialRenderer
.
new
(
self
,
options
,
formats
).
render
(
&
block
)
PartialRenderer
.
new
(
self
,
options
).
render
(
&
block
)
end
end
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录