Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
8bea6072
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 搜索 >>
提交
8bea6072
编写于
5月 13, 2012
作者:
S
Steve Klabnik
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Created a Raw handler for templates.
Fixes #2394
上级
1839ecd2
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
36 addition
and
6 deletion
+36
-6
actionpack/lib/action_view/template/handlers.rb
actionpack/lib/action_view/template/handlers.rb
+2
-0
actionpack/lib/action_view/template/handlers/raw.rb
actionpack/lib/action_view/template/handlers/raw.rb
+11
-0
actionpack/lib/action_view/template/resolver.rb
actionpack/lib/action_view/template/resolver.rb
+3
-1
actionpack/test/fixtures/plain_text.raw
actionpack/test/fixtures/plain_text.raw
+1
-0
actionpack/test/fixtures/plain_text_with_characters.raw
actionpack/test/fixtures/plain_text_with_characters.raw
+1
-0
actionpack/test/template/render_test.rb
actionpack/test/template/render_test.rb
+8
-0
actionpack/test/template/template_test.rb
actionpack/test/template/template_test.rb
+6
-1
actionpack/test/template/testing/fixture_resolver_test.rb
actionpack/test/template/testing/fixture_resolver_test.rb
+2
-2
actionpack/test/template/testing/null_resolver_test.rb
actionpack/test/template/testing/null_resolver_test.rb
+2
-2
未找到文件。
actionpack/lib/action_view/template/handlers.rb
浏览文件 @
8bea6072
...
...
@@ -4,10 +4,12 @@ class Template
module
Handlers
#:nodoc:
autoload
:ERB
,
'action_view/template/handlers/erb'
autoload
:Builder
,
'action_view/template/handlers/builder'
autoload
:Raw
,
'action_view/template/handlers/raw'
def
self
.
extended
(
base
)
base
.
register_default_template_handler
:erb
,
ERB
.
new
base
.
register_template_handler
:builder
,
Builder
.
new
base
.
register_template_handler
:raw
,
Raw
.
new
end
@@template_handlers
=
{}
...
...
actionpack/lib/action_view/template/handlers/raw.rb
0 → 100644
浏览文件 @
8bea6072
module
ActionView
module
Template::Handlers
class
Raw
def
call
(
template
)
escaped
=
template
.
source
.
gsub
(
':'
,
'\:'
)
'%q:'
+
escaped
+
':;'
end
end
end
end
actionpack/lib/action_view/template/resolver.rb
浏览文件 @
8bea6072
...
...
@@ -171,7 +171,9 @@ def mtime(p)
def
extract_handler_and_format
(
path
,
default_formats
)
pieces
=
File
.
basename
(
path
).
split
(
"."
)
pieces
.
shift
handler
=
Template
.
handler_for_extension
(
pieces
.
pop
)
extension
=
pieces
.
pop
ActiveSupport
::
Deprecation
.
warn
"The file
#{
path
}
did not specify a template handler. The default is currently ERB, but will change to RAW in the future."
unless
extension
handler
=
Template
.
handler_for_extension
(
extension
)
format
=
pieces
.
last
&&
Mime
[
pieces
.
last
]
[
handler
,
format
]
end
...
...
actionpack/test/fixtures/plain_text.raw
0 → 100644
浏览文件 @
8bea6072
<%= hello_world %>
actionpack/test/fixtures/plain_text_with_characters.raw
0 → 100644
浏览文件 @
8bea6072
Here are some characters: !@#$%^&*()-="'}{`
actionpack/test/template/render_test.rb
浏览文件 @
8bea6072
...
...
@@ -79,6 +79,14 @@ def test_render_template_with_handlers
assert_equal
"<h1>No Comment</h1>
\n
"
,
@view
.
render
(
:template
=>
"comments/empty"
,
:handlers
=>
[
:builder
])
end
def
test_render_raw_template_with_handlers
assert_equal
"<%= hello_world %>
\n
"
,
@view
.
render
(
:template
=>
"plain_text"
)
end
def
test_render_raw_template_with_quotes
assert_equal
%q;Here are some characters: !@#$%^&*()-="'}{`;
+
"
\n
"
,
@view
.
render
(
:template
=>
"plain_text_with_characters"
)
end
def
test_render_file_with_localization_on_context_level
old_locale
,
@view
.
locale
=
@view
.
locale
,
:da
assert_equal
"Hey verden"
,
@view
.
render
(
:file
=>
"test/hello_world"
)
...
...
actionpack/test/template/template_test.rb
浏览文件 @
8bea6072
...
...
@@ -48,7 +48,7 @@ def my_buffer
end
def
new_template
(
body
=
"<%= hello %>"
,
details
=
{})
ActionView
::
Template
.
new
(
body
,
"hello template"
,
ERBHandler
,
{
:virtual_path
=>
"hello"
}.
merge!
(
details
))
ActionView
::
Template
.
new
(
body
,
"hello template"
,
details
.
fetch
(
:handler
)
{
ERBHandler
}
,
{
:virtual_path
=>
"hello"
}.
merge!
(
details
))
end
def
render
(
locals
=
{})
...
...
@@ -64,6 +64,11 @@ def test_basic_template
assert_equal
"Hello"
,
render
end
def
test_raw_template
@template
=
new_template
(
"<%= hello %>"
,
:handler
=>
ActionView
::
Template
::
Handlers
::
Raw
.
new
)
assert_equal
"<%= hello %>"
,
render
end
def
test_template_loses_its_source_after_rendering
@template
=
new_template
render
...
...
actionpack/test/template/testing/fixture_resolver_test.rb
浏览文件 @
8bea6072
...
...
@@ -8,8 +8,8 @@ def test_should_return_empty_list_for_unknown_path
end
def
test_should_return_template_for_declared_path
resolver
=
ActionView
::
FixtureResolver
.
new
(
"arbitrary/path"
=>
"this text"
)
templates
=
resolver
.
find_all
(
"path"
,
"arbitrary"
,
false
,
{
:locale
=>
[],
:formats
=>
[
:html
],
:handlers
=>
[]})
resolver
=
ActionView
::
FixtureResolver
.
new
(
"arbitrary/path
.erb
"
=>
"this text"
)
templates
=
resolver
.
find_all
(
"path"
,
"arbitrary"
,
false
,
{
:locale
=>
[],
:formats
=>
[
:html
],
:handlers
=>
[
:erb
]})
assert_equal
1
,
templates
.
size
,
"expected one template"
assert_equal
"this text"
,
templates
.
first
.
source
assert_equal
"arbitrary/path"
,
templates
.
first
.
virtual_path
...
...
actionpack/test/template/testing/null_resolver_test.rb
浏览文件 @
8bea6072
...
...
@@ -3,10 +3,10 @@
class
NullResolverTest
<
ActiveSupport
::
TestCase
def
test_should_return_template_for_any_path
resolver
=
ActionView
::
NullResolver
.
new
()
templates
=
resolver
.
find_all
(
"path"
,
"arbitrary"
,
false
,
{
:locale
=>
[],
:formats
=>
[
:html
],
:handlers
=>
[]})
templates
=
resolver
.
find_all
(
"path
.erb
"
,
"arbitrary"
,
false
,
{
:locale
=>
[],
:formats
=>
[
:html
],
:handlers
=>
[]})
assert_equal
1
,
templates
.
size
,
"expected one template"
assert_equal
"Template generated by Null Resolver"
,
templates
.
first
.
source
assert_equal
"arbitrary/path"
,
templates
.
first
.
virtual_path
assert_equal
"arbitrary/path
.erb
"
,
templates
.
first
.
virtual_path
assert_equal
[
:html
],
templates
.
first
.
formats
end
end
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录