Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
4758d370
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,发现更多精彩内容 >>
提交
4758d370
编写于
5月 04, 2011
作者:
J
José Valim
浏览文件
操作
浏览文件
下载
差异文件
Merge remote branch 'apotonick/presentation'
上级
bff37405
eb327c1b
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
32 addition
and
21 deletion
+32
-21
actionpack/lib/abstract_controller/rendering.rb
actionpack/lib/abstract_controller/rendering.rb
+1
-1
actionpack/lib/abstract_controller/view_paths.rb
actionpack/lib/abstract_controller/view_paths.rb
+5
-2
actionpack/lib/action_view/base.rb
actionpack/lib/action_view/base.rb
+3
-2
actionpack/lib/action_view/lookup_context.rb
actionpack/lib/action_view/lookup_context.rb
+3
-0
actionpack/lib/action_view/renderer/abstract_renderer.rb
actionpack/lib/action_view/renderer/abstract_renderer.rb
+1
-2
actionpack/lib/action_view/renderer/partial_renderer.rb
actionpack/lib/action_view/renderer/partial_renderer.rb
+3
-7
actionpack/lib/action_view/renderer/renderer.rb
actionpack/lib/action_view/renderer/renderer.rb
+6
-7
actionpack/test/controller/view_paths_test.rb
actionpack/test/controller/view_paths_test.rb
+4
-0
actionpack/test/template/lookup_context_test.rb
actionpack/test/template/lookup_context_test.rb
+6
-0
未找到文件。
actionpack/lib/abstract_controller/rendering.rb
浏览文件 @
4758d370
...
@@ -104,7 +104,7 @@ def view_context
...
@@ -104,7 +104,7 @@ def view_context
# Returns an object that is able to render templates.
# Returns an object that is able to render templates.
def
view_renderer
def
view_renderer
@view_renderer
||=
ActionView
::
Renderer
.
new
(
lookup_context
,
self
)
@view_renderer
||=
ActionView
::
Renderer
.
new
(
lookup_context
)
end
end
# Normalize arguments, options and then delegates render_to_body and
# Normalize arguments, options and then delegates render_to_body and
...
...
actionpack/lib/abstract_controller/view_paths.rb
浏览文件 @
4758d370
...
@@ -15,7 +15,10 @@ module ViewPaths
...
@@ -15,7 +15,10 @@ module ViewPaths
# templates, i.e. view paths and details. Check ActionView::LookupContext for more
# templates, i.e. view paths and details. Check ActionView::LookupContext for more
# information.
# information.
def
lookup_context
def
lookup_context
@lookup_context
||=
ActionView
::
LookupContext
.
new
(
self
.
class
.
_view_paths
,
details_for_lookup
)
@lookup_context
||=
ActionView
::
LookupContext
.
new
(
self
.
class
.
_view_paths
,
details_for_lookup
).
tap
do
|
ctx
|
ctx
.
prefixes
=
_prefixes
end
end
end
def
details_for_lookup
def
details_for_lookup
...
@@ -67,4 +70,4 @@ def view_paths=(paths)
...
@@ -67,4 +70,4 @@ def view_paths=(paths)
end
end
end
end
end
end
end
end
\ No newline at end of file
actionpack/lib/action_view/base.rb
浏览文件 @
4758d370
...
@@ -199,8 +199,9 @@ def initialize(context = nil, assigns_for_first_render = {}, controller = nil, f
...
@@ -199,8 +199,9 @@ def initialize(context = nil, assigns_for_first_render = {}, controller = nil, f
elsif
elsif
lookup_context
=
context
.
is_a?
(
ActionView
::
LookupContext
)
?
lookup_context
=
context
.
is_a?
(
ActionView
::
LookupContext
)
?
context
:
ActionView
::
LookupContext
.
new
(
context
)
context
:
ActionView
::
LookupContext
.
new
(
context
)
lookup_context
.
formats
=
formats
if
formats
lookup_context
.
formats
=
formats
if
formats
@view_renderer
=
ActionView
::
Renderer
.
new
(
lookup_context
,
controller
)
lookup_context
.
prefixes
=
controller
.
_prefixes
if
controller
@view_renderer
=
ActionView
::
Renderer
.
new
(
lookup_context
)
end
end
_prepare_context
_prepare_context
...
...
actionpack/lib/action_view/lookup_context.rb
浏览文件 @
4758d370
...
@@ -9,6 +9,8 @@ module ActionView
...
@@ -9,6 +9,8 @@ module ActionView
# generate a key, given to view paths, used in the resolver cache lookup. Since
# generate a key, given to view paths, used in the resolver cache lookup. Since
# this key is generated just once during the request, it speeds up all cache accesses.
# this key is generated just once during the request, it speeds up all cache accesses.
class
LookupContext
#:nodoc:
class
LookupContext
#:nodoc:
attr_accessor
:prefixes
mattr_accessor
:fallbacks
mattr_accessor
:fallbacks
@@fallbacks
=
FallbackFileSystemResolver
.
instances
@@fallbacks
=
FallbackFileSystemResolver
.
instances
...
@@ -62,6 +64,7 @@ def initialize(view_paths, details = {})
...
@@ -62,6 +64,7 @@ def initialize(view_paths, details = {})
@details
,
@details_key
=
{
:handlers
=>
default_handlers
},
nil
@details
,
@details_key
=
{
:handlers
=>
default_handlers
},
nil
@frozen_formats
,
@skip_default_locale
=
false
,
false
@frozen_formats
,
@skip_default_locale
=
false
,
false
@cache
=
true
@cache
=
true
@prefixes
=
[]
self
.
view_paths
=
view_paths
self
.
view_paths
=
view_paths
self
.
registered_detail_setters
.
each
do
|
key
,
setter
|
self
.
registered_detail_setters
.
each
do
|
key
,
setter
|
...
...
actionpack/lib/action_view/renderer/abstract_renderer.rb
浏览文件 @
4758d370
...
@@ -3,9 +3,8 @@ class AbstractRenderer #:nodoc:
...
@@ -3,9 +3,8 @@ class AbstractRenderer #:nodoc:
delegate
:find_template
,
:template_exists?
,
:with_fallbacks
,
:update_details
,
delegate
:find_template
,
:template_exists?
,
:with_fallbacks
,
:update_details
,
:with_layout_format
,
:formats
,
:freeze_formats
,
:to
=>
:@lookup_context
:with_layout_format
,
:formats
,
:freeze_formats
,
:to
=>
:@lookup_context
def
initialize
(
lookup_context
,
controller
)
def
initialize
(
lookup_context
)
@lookup_context
=
lookup_context
@lookup_context
=
lookup_context
@controller
=
controller
end
end
def
render
def
render
...
...
actionpack/lib/action_view/renderer/partial_renderer.rb
浏览文件 @
4758d370
...
@@ -219,7 +219,7 @@ class PartialRenderer < AbstractRenderer #:nodoc:
...
@@ -219,7 +219,7 @@ class PartialRenderer < AbstractRenderer #:nodoc:
def
initialize
(
*
)
def
initialize
(
*
)
super
super
@partial_names
=
PARTIAL_NAMES
[
@
controller
.
class
.
name
]
@partial_names
=
PARTIAL_NAMES
[
@
lookup_context
.
prefixes
.
first
]
end
end
def
render
(
context
,
options
,
block
)
def
render
(
context
,
options
,
block
)
...
@@ -304,10 +304,6 @@ def setup(context, options, block)
...
@@ -304,10 +304,6 @@ def setup(context, options, block)
self
self
end
end
def
controller_prefixes
@controller_prefixes
||=
@controller
&&
@controller
.
_prefixes
end
def
collection
def
collection
if
@options
.
key?
(
:collection
)
if
@options
.
key?
(
:collection
)
collection
=
@options
[
:collection
]
collection
=
@options
[
:collection
]
...
@@ -331,7 +327,7 @@ def find_partial
...
@@ -331,7 +327,7 @@ def find_partial
end
end
def
find_template
(
path
=
@path
,
locals
=
@locals
.
keys
)
def
find_template
(
path
=
@path
,
locals
=
@locals
.
keys
)
prefixes
=
path
.
include?
(
?/
)
?
[]
:
controller_
prefixes
prefixes
=
path
.
include?
(
?/
)
?
[]
:
@lookup_context
.
prefixes
@lookup_context
.
find_template
(
path
,
prefixes
,
true
,
locals
)
@lookup_context
.
find_template
(
path
,
prefixes
,
true
,
locals
)
end
end
...
@@ -372,7 +368,7 @@ def partial_path(object = @object)
...
@@ -372,7 +368,7 @@ def partial_path(object = @object)
object
=
object
.
to_model
if
object
.
respond_to?
(
:to_model
)
object
=
object
.
to_model
if
object
.
respond_to?
(
:to_model
)
object
.
class
.
model_name
.
partial_path
.
dup
.
tap
do
|
partial
|
object
.
class
.
model_name
.
partial_path
.
dup
.
tap
do
|
partial
|
path
=
controller_
prefixes
.
first
path
=
@lookup_context
.
prefixes
.
first
partial
.
insert
(
0
,
"
#{
File
.
dirname
(
path
)
}
/"
)
if
partial
.
include?
(
?/
)
&&
path
.
include?
(
?/
)
partial
.
insert
(
0
,
"
#{
File
.
dirname
(
path
)
}
/"
)
if
partial
.
include?
(
?/
)
&&
path
.
include?
(
?/
)
end
end
end
end
...
...
actionpack/lib/action_view/renderer/renderer.rb
浏览文件 @
4758d370
...
@@ -3,11 +3,10 @@ module ActionView
...
@@ -3,11 +3,10 @@ module ActionView
# to other objects like TemplateRenderer and PartialRenderer which
# to other objects like TemplateRenderer and PartialRenderer which
# actually renders the template.
# actually renders the template.
class
Renderer
class
Renderer
attr_accessor
:lookup_context
,
:controller
attr_accessor
:lookup_context
def
initialize
(
lookup_context
,
controller
)
def
initialize
(
lookup_context
)
@lookup_context
=
lookup_context
@lookup_context
=
lookup_context
@controller
=
controller
end
end
# Main render entry point shared by AV and AC.
# Main render entry point shared by AV and AC.
...
@@ -28,7 +27,7 @@ def render_body(context, options)
...
@@ -28,7 +27,7 @@ def render_body(context, options)
if
options
.
key?
(
:partial
)
if
options
.
key?
(
:partial
)
[
render_partial
(
context
,
options
)]
[
render_partial
(
context
,
options
)]
else
else
StreamingTemplateRenderer
.
new
(
@lookup_context
,
@controller
).
render
(
context
,
options
)
StreamingTemplateRenderer
.
new
(
@lookup_context
).
render
(
context
,
options
)
end
end
end
end
...
@@ -45,11 +44,11 @@ def render_partial(context, options, &block) #:nodoc:
...
@@ -45,11 +44,11 @@ def render_partial(context, options, &block) #:nodoc:
private
private
def
_template_renderer
#:nodoc:
def
_template_renderer
#:nodoc:
@_template_renderer
||=
TemplateRenderer
.
new
(
@lookup_context
,
@controller
)
@_template_renderer
||=
TemplateRenderer
.
new
(
@lookup_context
)
end
end
def
_partial_renderer
#:nodoc:
def
_partial_renderer
#:nodoc:
@_partial_renderer
||=
PartialRenderer
.
new
(
@lookup_context
,
@controller
)
@_partial_renderer
||=
PartialRenderer
.
new
(
@lookup_context
)
end
end
end
end
end
end
\ No newline at end of file
actionpack/test/controller/view_paths_test.rb
浏览文件 @
4758d370
...
@@ -179,4 +179,8 @@ class C < ActionController::Base; end
...
@@ -179,4 +179,8 @@ class C < ActionController::Base; end
assert_nothing_raised
{
C
.
append_view_path
'c/path'
}
assert_nothing_raised
{
C
.
append_view_path
'c/path'
}
assert_paths
C
,
"c/path"
assert_paths
C
,
"c/path"
end
end
def
test_lookup_context_accessor
assert_equal
[
"test"
],
TestController
.
new
.
lookup_context
.
prefixes
end
end
end
actionpack/test/template/lookup_context_test.rb
浏览文件 @
4758d370
...
@@ -180,6 +180,12 @@ def teardown
...
@@ -180,6 +180,12 @@ def teardown
assert_not_equal
template
,
old_template
assert_not_equal
template
,
old_template
end
end
test
"responds to #prefixes"
do
assert_equal
[],
@lookup_context
.
prefixes
@lookup_context
.
prefixes
=
[
"foo"
]
assert_equal
[
"foo"
],
@lookup_context
.
prefixes
end
end
end
class
LookupContextWithFalseCaching
<
ActiveSupport
::
TestCase
class
LookupContextWithFalseCaching
<
ActiveSupport
::
TestCase
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录