未验证 提交 9dfae153 编写于 作者: R Rafael França 提交者: GitHub

Merge pull request #38900 from joelhawksley/annotations-html-only

`ActionView::Base.annotate_template_file_names` only annotates HTML
......@@ -59,6 +59,7 @@ def call(template, source)
erb,
escape: (self.class.escape_ignore_list.include? template.type),
trim: (self.class.erb_trim_mode == "-"),
format: template.format,
short_identifier: template.short_identifier
).src
end
......
......@@ -14,7 +14,8 @@ def initialize(input, properties = {})
# Dup properties so that we don't modify argument
properties = Hash[properties]
if ActionView::Base.annotate_template_file_names
# 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
......
......@@ -1457,17 +1457,28 @@ def test_render_call_to_partial_with_layout_in_main_layout_and_within_content_fo
def test_template_annotations
ActionView::Base.annotate_template_file_names = true
get :render_with_explicit_template_with_locals
get :greeting
lines = @response.body.split("\n")
assert_includes lines.first, "<!-- BEGIN"
assert_includes lines.first, "test/fixtures/actionpack/test/render_file_with_locals.erb -->"
assert_includes lines.first, "test/fixtures/actionpack/test/greeting.html.erb -->"
assert_includes lines[1], "The secret is area51"
assert_includes lines[1], "This is grand!"
assert_includes lines.last, "<!-- END"
assert_includes lines.last, "test/fixtures/actionpack/test/render_file_with_locals.erb -->"
assert_includes lines.last, "test/fixtures/actionpack/test/greeting.html.erb -->"
ensure
ActionView::Base.annotate_template_file_names = false
end
def test_template_annotations_do_not_render_for_non_html_format
ActionView::Base.annotate_template_file_names = true
get :render_with_explicit_template_with_locals
assert_not_includes @response.body, "BEGIN"
assert_equal @response.body.split("\n").length, 1
ensure
ActionView::Base.annotate_template_file_names = false
end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册