Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
c63b18de
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,发现更多精彩内容 >>
提交
c63b18de
编写于
3月 12, 2014
作者:
Ł
Łukasz Strzałkowski
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add variants to Template class
上级
0ca6836a
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
20 addition
and
12 deletion
+20
-12
actionview/lib/action_view/template.rb
actionview/lib/action_view/template.rb
+2
-1
actionview/lib/action_view/template/resolver.rb
actionview/lib/action_view/template/resolver.rb
+10
-7
actionview/lib/action_view/testing/resolvers.rb
actionview/lib/action_view/testing/resolvers.rb
+8
-4
未找到文件。
actionview/lib/action_view/template.rb
浏览文件 @
c63b18de
...
@@ -97,7 +97,7 @@ class Template
...
@@ -97,7 +97,7 @@ class Template
extend
Template
::
Handlers
extend
Template
::
Handlers
attr_accessor
:locals
,
:formats
,
:virtual_path
attr_accessor
:locals
,
:formats
,
:v
ariants
,
:v
irtual_path
attr_reader
:source
,
:identifier
,
:handler
,
:original_encoding
,
:updated_at
attr_reader
:source
,
:identifier
,
:handler
,
:original_encoding
,
:updated_at
...
@@ -123,6 +123,7 @@ def initialize(source, identifier, handler, details)
...
@@ -123,6 +123,7 @@ def initialize(source, identifier, handler, details)
@virtual_path
=
details
[
:virtual_path
]
@virtual_path
=
details
[
:virtual_path
]
@updated_at
=
details
[
:updated_at
]
||
Time
.
now
@updated_at
=
details
[
:updated_at
]
||
Time
.
now
@formats
=
Array
(
format
).
map
{
|
f
|
f
.
respond_to?
(
:ref
)
?
f
.
ref
:
f
}
@formats
=
Array
(
format
).
map
{
|
f
|
f
.
respond_to?
(
:ref
)
?
f
.
ref
:
f
}
@variants
=
[
details
[
:variant
]]
@compile_mutex
=
Mutex
.
new
@compile_mutex
=
Mutex
.
new
end
end
...
...
actionview/lib/action_view/template/resolver.rb
浏览文件 @
c63b18de
...
@@ -154,7 +154,8 @@ def decorate(templates, path_info, details, locals) #:nodoc:
...
@@ -154,7 +154,8 @@ def decorate(templates, path_info, details, locals) #:nodoc:
cached
=
nil
cached
=
nil
templates
.
each
do
|
t
|
templates
.
each
do
|
t
|
t
.
locals
=
locals
t
.
locals
=
locals
t
.
formats
=
details
[
:formats
]
||
[
:html
]
if
t
.
formats
.
empty?
t
.
formats
=
details
[
:formats
]
||
[
:html
]
if
t
.
formats
.
empty?
t
.
variants
=
details
[
:variants
]
||
[]
if
t
.
variants
.
empty?
t
.
virtual_path
||=
(
cached
||=
build_path
(
*
path_info
))
t
.
virtual_path
||=
(
cached
||=
build_path
(
*
path_info
))
end
end
end
end
...
@@ -189,13 +190,15 @@ def query(path, details, formats)
...
@@ -189,13 +190,15 @@ def query(path, details, formats)
}
}
template_paths
.
map
{
|
template
|
template_paths
.
map
{
|
template
|
handler
,
format
=
extract_handler_and_forma
t
(
template
,
formats
)
handler
,
format
,
variant
=
extract_handler_and_format_and_varian
t
(
template
,
formats
)
contents
=
File
.
binread
template
contents
=
File
.
binread
(
template
)
Template
.
new
(
contents
,
File
.
expand_path
(
template
),
handler
,
Template
.
new
(
contents
,
File
.
expand_path
(
template
),
handler
,
:virtual_path
=>
path
.
virtual
,
:virtual_path
=>
path
.
virtual
,
:format
=>
format
,
:format
=>
format
,
:updated_at
=>
mtime
(
template
))
:variant
=>
variant
,
:updated_at
=>
mtime
(
template
)
)
}
}
end
end
...
@@ -228,7 +231,7 @@ def mtime(p)
...
@@ -228,7 +231,7 @@ def mtime(p)
# Extract handler and formats from path. If a format cannot be a found neither
# Extract handler and formats from path. If a format cannot be a found neither
# from the path, or the handler, we should return the array of formats given
# from the path, or the handler, we should return the array of formats given
# to the resolver.
# to the resolver.
def
extract_handler_and_format
(
path
,
default_formats
)
def
extract_handler_and_format
_and_variant
(
path
,
default_formats
)
pieces
=
File
.
basename
(
path
).
split
(
"."
)
pieces
=
File
.
basename
(
path
).
split
(
"."
)
pieces
.
shift
pieces
.
shift
...
@@ -240,10 +243,10 @@ def extract_handler_and_format(path, default_formats)
...
@@ -240,10 +243,10 @@ def extract_handler_and_format(path, default_formats)
end
end
handler
=
Template
.
handler_for_extension
(
extension
)
handler
=
Template
.
handler_for_extension
(
extension
)
format
=
pieces
.
last
&&
pieces
.
last
.
split
(
EXTENSIONS
[
:variants
],
2
).
first
# remove variant from forma
t
format
,
variant
=
pieces
.
last
.
split
(
EXTENSIONS
[
:variants
],
2
)
if
pieces
.
las
t
format
&&=
Template
::
Types
[
format
]
format
&&=
Template
::
Types
[
format
]
[
handler
,
format
]
[
handler
,
format
,
variant
]
end
end
end
end
...
...
actionview/lib/action_view/testing/resolvers.rb
浏览文件 @
c63b18de
...
@@ -30,9 +30,13 @@ def query(path, exts, formats)
...
@@ -30,9 +30,13 @@ def query(path, exts, formats)
@hash
.
each
do
|
_path
,
array
|
@hash
.
each
do
|
_path
,
array
|
source
,
updated_at
=
array
source
,
updated_at
=
array
next
unless
_path
=~
query
next
unless
_path
=~
query
handler
,
format
=
extract_handler_and_forma
t
(
_path
,
formats
)
handler
,
format
,
variant
=
extract_handler_and_format_and_varian
t
(
_path
,
formats
)
templates
<<
Template
.
new
(
source
,
_path
,
handler
,
templates
<<
Template
.
new
(
source
,
_path
,
handler
,
:virtual_path
=>
path
.
virtual
,
:format
=>
format
,
:updated_at
=>
updated_at
)
:virtual_path
=>
path
.
virtual
,
:format
=>
format
,
:variant
=>
variant
,
:updated_at
=>
updated_at
)
end
end
templates
.
sort_by
{
|
t
|
-
t
.
identifier
.
match
(
/^
#{
query
}
$/
).
captures
.
reject
(
&
:blank?
).
size
}
templates
.
sort_by
{
|
t
|
-
t
.
identifier
.
match
(
/^
#{
query
}
$/
).
captures
.
reject
(
&
:blank?
).
size
}
...
@@ -41,8 +45,8 @@ def query(path, exts, formats)
...
@@ -41,8 +45,8 @@ def query(path, exts, formats)
class
NullResolver
<
PathResolver
class
NullResolver
<
PathResolver
def
query
(
path
,
exts
,
formats
)
def
query
(
path
,
exts
,
formats
)
handler
,
format
=
extract_handler_and_forma
t
(
path
,
formats
)
handler
,
format
,
variant
=
extract_handler_and_format_and_varian
t
(
path
,
formats
)
[
ActionView
::
Template
.
new
(
"Template generated by Null Resolver"
,
path
,
handler
,
:virtual_path
=>
path
,
:format
=>
format
)]
[
ActionView
::
Template
.
new
(
"Template generated by Null Resolver"
,
path
,
handler
,
:virtual_path
=>
path
,
:format
=>
format
,
:variant
=>
variant
)]
end
end
end
end
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录