Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
70a440aa
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,发现更多精彩内容 >>
提交
70a440aa
编写于
8月 07, 2009
作者:
Y
Yehuda Katz
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Clean up render
@object
a bit more.
上级
4ac9d391
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
19 addition
and
78 deletion
+19
-78
actionpack/lib/action_controller/record_identifier.rb
actionpack/lib/action_controller/record_identifier.rb
+0
-15
actionpack/lib/action_view/render/partials.rb
actionpack/lib/action_view/render/partials.rb
+19
-6
actionpack/test/controller/record_identifier_test.rb
actionpack/test/controller/record_identifier_test.rb
+0
-57
未找到文件。
actionpack/lib/action_controller/record_identifier.rb
浏览文件 @
70a440aa
...
@@ -36,21 +36,6 @@ module RecordIdentifier
...
@@ -36,21 +36,6 @@ module RecordIdentifier
JOIN
=
'_'
.
freeze
JOIN
=
'_'
.
freeze
NEW
=
'new'
.
freeze
NEW
=
'new'
.
freeze
# Returns plural/singular for a record or class. Example:
#
# partial_path(post) # => "posts/post"
# partial_path(Person) # => "people/person"
# partial_path(Person, "admin/games") # => "admin/people/person"
def
partial_path
(
record_or_class
,
controller_path
=
nil
)
name
=
model_name_from_record_or_class
(
record_or_class
)
if
controller_path
&&
controller_path
.
include?
(
"/"
)
"
#{
File
.
dirname
(
controller_path
)
}
/
#{
name
.
partial_path
}
"
else
name
.
partial_path
end
end
# The DOM class convention is to use the singular form of an object or class. Examples:
# The DOM class convention is to use the singular form of an object or class. Examples:
#
#
# dom_class(post) # => "post"
# dom_class(post) # => "post"
...
...
actionpack/lib/action_view/render/partials.rb
浏览文件 @
70a440aa
...
@@ -177,6 +177,12 @@ module Partials
...
@@ -177,6 +177,12 @@ module Partials
attr_accessor
:_partial
attr_accessor
:_partial
end
end
module
ClassMethods
def
_partial_names
@_partial_names
||=
ActiveSupport
::
ConcurrentHash
.
new
end
end
def
render_partial
(
*
args
)
def
render_partial
(
*
args
)
@assigns_added
=
false
@assigns_added
=
false
_render_partial
(
*
args
)
_render_partial
(
*
args
)
...
@@ -189,12 +195,9 @@ def _render_partial(options = {}) #:nodoc:
...
@@ -189,12 +195,9 @@ def _render_partial(options = {}) #:nodoc:
if
partial
.
respond_to?
(
:to_ary
)
if
partial
.
respond_to?
(
:to_ary
)
return
_render_partial_collection
(
partial
,
options
)
return
_render_partial_collection
(
partial
,
options
)
elsif
partial
.
is_a?
(
ActionView
::
Helpers
::
FormBuilder
)
path
=
partial
.
class
.
model_name
.
partial_path
options
[
:locals
].
merge!
(
path
.
to_sym
=>
partial
)
elsif
!
partial
.
is_a?
(
String
)
elsif
!
partial
.
is_a?
(
String
)
options
[
:object
]
=
object
=
partial
options
[
:object
]
=
object
=
partial
path
=
ActionController
::
RecordIdentifier
.
partial_path
(
object
,
controller_path
)
path
=
_partial_path
(
object
)
end
end
parts
=
partial_parts
(
path
,
options
)
parts
=
partial_parts
(
path
,
options
)
...
@@ -203,6 +206,17 @@ def _render_partial(options = {}) #:nodoc:
...
@@ -203,6 +206,17 @@ def _render_partial(options = {}) #:nodoc:
end
end
private
private
def
_partial_path
(
object
)
self
.
class
.
_partial_names
[[
controller
.
class
,
object
.
class
]]
||=
begin
name
=
object
.
class
.
model_name
if
controller_path
&&
controller_path
.
include?
(
"/"
)
File
.
join
(
File
.
dirname
(
controller_path
),
name
.
partial_path
)
else
name
.
partial_path
end
end
end
def
partial_parts
(
name
,
options
)
def
partial_parts
(
name
,
options
)
segments
=
name
.
split
(
"/"
)
segments
=
name
.
split
(
"/"
)
parts
=
segments
.
pop
.
split
(
"."
)
parts
=
segments
.
pop
.
split
(
"."
)
...
@@ -278,8 +292,7 @@ def _render_partial_collection(collection, options = {}, passed_template = nil)
...
@@ -278,8 +292,7 @@ def _render_partial_collection(collection, options = {}, passed_template = nil)
index
,
@_partial_path
=
0
,
nil
index
,
@_partial_path
=
0
,
nil
collection
.
map
do
|
object
|
collection
.
map
do
|
object
|
options
[
:_template
]
=
template
=
passed_template
||
begin
options
[
:_template
]
=
template
=
passed_template
||
begin
_partial_path
=
_partial_path
=
_partial_path
(
object
)
ActionController
::
RecordIdentifier
.
partial_path
(
object
,
controller_path
)
template
=
_pick_partial_template
(
_partial_path
)
template
=
_pick_partial_template
(
_partial_path
)
end
end
...
...
actionpack/test/controller/record_identifier_test.rb
浏览文件 @
70a440aa
...
@@ -54,24 +54,6 @@ def test_dom_id_with_prefix
...
@@ -54,24 +54,6 @@ def test_dom_id_with_prefix
assert_equal
"edit_
#{
@singular
}
_1"
,
dom_id
(
@record
,
:edit
)
assert_equal
"edit_
#{
@singular
}
_1"
,
dom_id
(
@record
,
:edit
)
end
end
def
test_partial_path
expected
=
"
#{
@plural
}
/
#{
@singular
}
"
assert_equal
expected
,
partial_path
(
@record
)
assert_equal
expected
,
partial_path
(
Comment
)
end
def
test_partial_path_with_namespaced_controller_path
expected
=
"admin/
#{
@plural
}
/
#{
@singular
}
"
assert_equal
expected
,
partial_path
(
@record
,
"admin/posts"
)
assert_equal
expected
,
partial_path
(
@klass
,
"admin/posts"
)
end
def
test_partial_path_with_not_namespaced_controller_path
expected
=
"
#{
@plural
}
/
#{
@singular
}
"
assert_equal
expected
,
partial_path
(
@record
,
"posts"
)
assert_equal
expected
,
partial_path
(
@klass
,
"posts"
)
end
def
test_dom_class
def
test_dom_class
assert_equal
@singular
,
dom_class
(
@record
)
assert_equal
@singular
,
dom_class
(
@record
)
end
end
...
@@ -101,42 +83,3 @@ def method_missing(method, *args)
...
@@ -101,42 +83,3 @@ def method_missing(method, *args)
RecordIdentifier
.
send
(
method
,
*
args
)
RecordIdentifier
.
send
(
method
,
*
args
)
end
end
end
end
class
NestedRecordIdentifierTest
<
RecordIdentifierTest
def
setup
@klass
=
Comment
::
Nested
@record
=
@klass
.
new
@singular
=
'comment_nested'
@plural
=
'comment_nesteds'
end
def
test_partial_path
expected
=
"comment/nesteds/nested"
assert_equal
expected
,
partial_path
(
@record
)
assert_equal
expected
,
partial_path
(
Comment
::
Nested
)
end
def
test_partial_path_with_namespaced_controller_path
expected
=
"admin/comment/nesteds/nested"
assert_equal
expected
,
partial_path
(
@record
,
"admin/posts"
)
assert_equal
expected
,
partial_path
(
@klass
,
"admin/posts"
)
end
def
test_partial_path_with_deeper_namespaced_controller_path
expected
=
"deeper/admin/comment/nesteds/nested"
assert_equal
expected
,
partial_path
(
@record
,
"deeper/admin/posts"
)
assert_equal
expected
,
partial_path
(
@klass
,
"deeper/admin/posts"
)
end
def
test_partial_path_with_even_deeper_namespaced_controller_path
expected
=
"even/more/deeper/admin/comment/nesteds/nested"
assert_equal
expected
,
partial_path
(
@record
,
"even/more/deeper/admin/posts"
)
assert_equal
expected
,
partial_path
(
@klass
,
"even/more/deeper/admin/posts"
)
end
def
test_partial_path_with_not_namespaced_controller_path
expected
=
"comment/nesteds/nested"
assert_equal
expected
,
partial_path
(
@record
,
"posts"
)
assert_equal
expected
,
partial_path
(
@klass
,
"posts"
)
end
end
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录