Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
673685cd
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,发现更多精彩内容 >>
未验证
提交
673685cd
编写于
4月 14, 2020
作者:
R
Rafael França
提交者:
GitHub
4月 14, 2020
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #38950 from joelhawksley/annotations-error-line
Raise template errors on correct line with annotations enabled
上级
9da56296
ab8ea481
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
42 addition
and
15 deletion
+42
-15
actionview/lib/action_view/template.rb
actionview/lib/action_view/template.rb
+3
-1
actionview/lib/action_view/template/handlers/erb.rb
actionview/lib/action_view/template/handlers/erb.rb
+23
-6
actionview/lib/action_view/template/handlers/erb/erubi.rb
actionview/lib/action_view/template/handlers/erb/erubi.rb
+2
-8
actionview/test/actionpack/controller/render_test.rb
actionview/test/actionpack/controller/render_test.rb
+14
-0
未找到文件。
actionview/lib/action_view/template.rb
浏览文件 @
673685cd
...
...
@@ -334,8 +334,10 @@ def #{method_name}(local_assigns, output_buffer)
raise
WrongEncodingError
.
new
(
source
,
Encoding
.
default_internal
)
end
start_line
=
@handler
.
respond_to?
(
:start_line
)
?
@handler
.
start_line
(
self
)
:
0
begin
mod
.
module_eval
(
source
,
identifier
,
0
)
mod
.
module_eval
(
source
,
identifier
,
start_line
)
rescue
SyntaxError
# Account for when code in the template is not syntactically valid; e.g. if we're using
# ERB and the user writes <%= foo( %>, attempting to call a helper `foo` and interpolate
...
...
actionview/lib/action_view/template/handlers/erb.rb
浏览文件 @
673685cd
...
...
@@ -40,6 +40,15 @@ def handles_encoding?
true
end
# Line number to pass to #module_eval
#
# If we're annotating the template, we need to offset the starting
# line number passed to #module_eval so that errors in the template
# will be raised on the correct line.
def
start_line
(
template
)
annotate?
(
template
)
?
-
1
:
0
end
def
call
(
template
,
source
)
# First, convert to BINARY, so in case the encoding is
# wrong, we can still find an encoding tag
...
...
@@ -55,16 +64,24 @@ def call(template, source)
# Always make sure we return a String in the default_internal
erb
.
encode!
self
.
class
.
erb_implementation
.
new
(
erb
,
options
=
{
escape:
(
self
.
class
.
escape_ignore_list
.
include?
template
.
type
),
trim:
(
self
.
class
.
erb_trim_mode
==
"-"
),
format:
template
.
format
,
short_identifier:
template
.
short_identifier
).
src
trim:
(
self
.
class
.
erb_trim_mode
==
"-"
)
}
if
annotate?
(
template
)
options
[
:preamble
]
=
"@output_buffer.safe_append='<!-- BEGIN
#{
template
.
short_identifier
}
-->
\n
';"
options
[
:postamble
]
=
"@output_buffer.safe_append='<!-- END
#{
template
.
short_identifier
}
-->
\n
';@output_buffer.to_s"
end
self
.
class
.
erb_implementation
.
new
(
erb
,
options
).
src
end
private
def
annotate?
(
template
)
ActionView
::
Base
.
annotate_template_file_names
&&
template
.
format
==
:html
end
def
valid_encoding
(
string
,
encoding
)
# If a magic encoding comment was found, tag the
# String with this encoding. This is for a case
...
...
actionview/lib/action_view/template/handlers/erb/erubi.rb
浏览文件 @
673685cd
...
...
@@ -14,14 +14,8 @@ def initialize(input, properties = {})
# Dup properties so that we don't modify argument
properties
=
Hash
[
properties
]
# Annotate output with template file names, if we're rendering HTML
if
ActionView
::
Base
.
annotate_template_file_names
&&
properties
[
:format
]
==
:html
properties
[
:preamble
]
=
"@output_buffer.safe_append='<!-- BEGIN
#{
properties
[
:short_identifier
]
}
-->
\n
';"
properties
[
:postamble
]
=
"@output_buffer.safe_append='<!-- END
#{
properties
[
:short_identifier
]
}
-->
\n
';@output_buffer.to_s"
else
properties
[
:preamble
]
=
""
properties
[
:postamble
]
=
"@output_buffer.to_s"
end
properties
[
:preamble
]
||=
""
properties
[
:postamble
]
||=
"@output_buffer.to_s"
properties
[
:bufvar
]
=
"@output_buffer"
properties
[
:escapefunc
]
=
""
...
...
actionview/test/actionpack/controller/render_test.rb
浏览文件 @
673685cd
...
...
@@ -1482,4 +1482,18 @@ def test_template_annotations_do_not_render_for_non_html_format
ensure
ActionView
::
Base
.
annotate_template_file_names
=
false
end
def
test_line_offset_with_annotations_enabled
ActionView
::
Base
.
annotate_template_file_names
=
true
exc
=
assert_raises
ActionView
::
Template
::
Error
do
get
:render_line_offset
end
line
=
exc
.
backtrace
.
first
assert
(
line
=~
%r{:(
\d
+):}
)
assert_equal
"1"
,
$1
,
"The line offset is wrong, perhaps the wrong exception has been raised, exception was:
#{
exc
.
inspect
}
"
ensure
ActionView
::
Base
.
annotate_template_file_names
=
false
end
end
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录