Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
a9b72fbc
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 搜索 >>
提交
a9b72fbc
编写于
5月 09, 2011
作者:
J
José Valim
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Optimize the most common resolver case.
上级
4f03e404
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
28 addition
and
15 deletion
+28
-15
actionpack/lib/action_view/path_set.rb
actionpack/lib/action_view/path_set.rb
+1
-1
actionpack/lib/action_view/template/resolver.rb
actionpack/lib/action_view/template/resolver.rb
+26
-13
actionpack/test/template/render_test.rb
actionpack/test/template/render_test.rb
+1
-1
未找到文件。
actionpack/lib/action_view/path_set.rb
浏览文件 @
a9b72fbc
...
...
@@ -35,7 +35,7 @@ def typecast!
each_with_index
do
|
path
,
i
|
path
=
path
.
to_s
if
path
.
is_a?
(
Pathname
)
next
unless
path
.
is_a?
(
String
)
self
[
i
]
=
FileSystemResolver
.
new
(
path
)
self
[
i
]
=
Optimized
FileSystemResolver
.
new
(
path
)
end
end
end
...
...
actionpack/lib/action_view/template/resolver.rb
浏览文件 @
a9b72fbc
...
...
@@ -111,7 +111,8 @@ def sort_locals(locals) #:nodoc:
end
end
class
PathResolver
<
Resolver
# An abstract class that implements a Resolver with path semantics.
class
PathResolver
<
Resolver
#:nodoc:
EXTENSIONS
=
[
:locale
,
:formats
,
:handlers
]
DEFAULT_PATTERN
=
":prefix/:action{.:locale,}{.:formats,}{.:handlers,}"
...
...
@@ -124,12 +125,11 @@ def initialize(pattern=nil)
def
find_templates
(
name
,
prefix
,
partial
,
details
)
path
=
Path
.
build
(
name
,
prefix
,
partial
)
extensions
=
Hash
[
EXTENSIONS
.
map
{
|
ext
|
[
ext
,
details
[
ext
]]
}.
flatten
(
0
)]
query
(
path
,
extensions
,
details
[
:formats
])
query
(
path
,
details
,
details
[
:formats
])
end
def
query
(
path
,
ext
s
,
formats
)
query
=
build_query
(
path
,
ext
s
)
def
query
(
path
,
detail
s
,
formats
)
query
=
build_query
(
path
,
detail
s
)
templates
=
[]
sanitizer
=
Hash
.
new
{
|
h
,
k
|
h
[
k
]
=
Dir
[
"
#{
File
.
dirname
(
k
)
}
/*"
]
}
...
...
@@ -137,7 +137,7 @@ def query(path, exts, formats)
next
if
File
.
directory?
(
p
)
||
!
sanitizer
[
p
].
include?
(
p
)
handler
,
format
=
extract_handler_and_format
(
p
,
formats
)
contents
=
File
.
open
(
p
,
"rb"
)
{
|
io
|
io
.
read
}
contents
=
File
.
open
(
p
,
"rb"
)
{
|
io
|
io
.
read
}
templates
<<
Template
.
new
(
contents
,
File
.
expand_path
(
p
),
handler
,
:virtual_path
=>
path
.
virtual
,
:format
=>
format
,
:updated_at
=>
mtime
(
p
))
...
...
@@ -147,17 +147,14 @@ def query(path, exts, formats)
end
# Helper for building query glob string based on resolver's pattern.
def
build_query
(
path
,
ext
s
)
def
build_query
(
path
,
detail
s
)
query
=
@pattern
.
dup
query
.
gsub!
(
/\:prefix(\/)?/
,
path
.
prefix
.
empty?
?
""
:
"
#{
path
.
prefix
}
\\
1"
)
# prefix can be empty...
query
.
gsub!
(
/\:action/
,
path
.
partial?
?
"_
#{
path
.
name
}
"
:
path
.
name
)
exts
.
each
{
|
ext
,
variants
|
details
.
each
do
|
ext
,
variants
|
query
.
gsub!
(
/\:
#{
ext
}
/
,
"{
#{
variants
.
compact
.
uniq
.
join
(
','
)
}
}"
)
}
query
.
gsub!
(
'.{html,'
,
'.{html,text.html,'
)
query
.
gsub!
(
'.{text,'
,
'.{text,text.plain,'
)
end
File
.
expand_path
(
query
,
@path
)
end
...
...
@@ -234,9 +231,25 @@ def eql?(resolver)
alias
:==
:eql?
end
# An Optimized resolver for Rails' most common case.
class
OptimizedFileSystemResolver
<
FileSystemResolver
#:nodoc:
def
build_query
(
path
,
details
)
exts
=
EXTENSIONS
.
map
{
|
ext
|
details
[
ext
]
}
query
=
File
.
join
(
@path
,
path
)
exts
.
each
do
|
ext
|
query
<<
"{"
ext
.
compact
.
each
{
|
e
|
query
<<
".
#{
e
}
,"
}
query
<<
"}"
end
query
end
end
# The same as FileSystemResolver but does not allow templates to store
# a virtual path since it is invalid for such resolvers.
class
FallbackFileSystemResolver
<
FileSystemResolver
class
FallbackFileSystemResolver
<
FileSystemResolver
#:nodoc:
def
self
.
instances
[
new
(
""
),
new
(
"/"
)]
end
...
...
actionpack/test/template/render_test.rb
浏览文件 @
a9b72fbc
...
...
@@ -325,7 +325,7 @@ class CachedViewRenderTest < ActiveSupport::TestCase
# Ensure view path cache is primed
def
setup
view_paths
=
ActionController
::
Base
.
view_paths
assert_equal
ActionView
::
FileSystemResolver
,
view_paths
.
first
.
class
assert_equal
ActionView
::
Optimized
FileSystemResolver
,
view_paths
.
first
.
class
setup_view
(
view_paths
)
end
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录