diff --git a/actionmailbox/test/dummy/config/environments/development.rb b/actionmailbox/test/dummy/config/environments/development.rb index a8bba7811f..7a9d9419d7 100644 --- a/actionmailbox/test/dummy/config/environments/development.rb +++ b/actionmailbox/test/dummy/config/environments/development.rb @@ -57,6 +57,9 @@ Rails.application.configure do # Raises error for missing translations # config.action_view.raise_on_missing_translations = true + # Render template filenames as comments in HTML + # config.action_view.annotate_template_file_names = true + # Use an evented file watcher to asynchronously detect changes in source code, # routes, locales, etc. This feature depends on the listen gem. # config.file_watcher = ActiveSupport::EventedFileUpdateChecker diff --git a/actionmailbox/test/dummy/config/environments/test.rb b/actionmailbox/test/dummy/config/environments/test.rb index 0a38fd3ce9..6c2cd6f8ed 100644 --- a/actionmailbox/test/dummy/config/environments/test.rb +++ b/actionmailbox/test/dummy/config/environments/test.rb @@ -43,4 +43,7 @@ Rails.application.configure do # Raises error for missing translations # config.action_view.raise_on_missing_translations = true + + # Render template filenames as comments in HTML + # config.action_view.annotate_template_file_names = true end diff --git a/actiontext/test/dummy/config/environments/development.rb b/actiontext/test/dummy/config/environments/development.rb index a8bba7811f..7a9d9419d7 100644 --- a/actiontext/test/dummy/config/environments/development.rb +++ b/actiontext/test/dummy/config/environments/development.rb @@ -57,6 +57,9 @@ Rails.application.configure do # Raises error for missing translations # config.action_view.raise_on_missing_translations = true + # Render template filenames as comments in HTML + # config.action_view.annotate_template_file_names = true + # Use an evented file watcher to asynchronously detect changes in source code, # routes, locales, etc. This feature depends on the listen gem. # config.file_watcher = ActiveSupport::EventedFileUpdateChecker diff --git a/actiontext/test/dummy/config/environments/test.rb b/actiontext/test/dummy/config/environments/test.rb index 0a38fd3ce9..6c2cd6f8ed 100644 --- a/actiontext/test/dummy/config/environments/test.rb +++ b/actiontext/test/dummy/config/environments/test.rb @@ -43,4 +43,7 @@ Rails.application.configure do # Raises error for missing translations # config.action_view.raise_on_missing_translations = true + + # Render template filenames as comments in HTML + # config.action_view.annotate_template_file_names = true end diff --git a/actionview/CHANGELOG.md b/actionview/CHANGELOG.md index 190c99d628..398a7f2553 100644 --- a/actionview/CHANGELOG.md +++ b/actionview/CHANGELOG.md @@ -1,3 +1,7 @@ +* `ActionView::Base.annotate_template_file_names` annotates HTML output with template file names. + + *Joel Hawksley*, *Aaron Patterson* + * `ActionView::Helpers::TranslationHelper#translate` returns nil when passed `default: nil` without a translation matching `I18n#translate`. diff --git a/actionview/lib/action_view/base.rb b/actionview/lib/action_view/base.rb index e13988b929..ca1ce14b0b 100644 --- a/actionview/lib/action_view/base.rb +++ b/actionview/lib/action_view/base.rb @@ -162,6 +162,9 @@ module ActionView #:nodoc: # Specify whether submit_tag should automatically disable on click cattr_accessor :automatically_disable_submit_tag, default: true + # Render template filenames as comments in HTML + cattr_accessor :annotate_template_file_names, default: false + class_attribute :_routes class_attribute :logger diff --git a/actionview/lib/action_view/template/handlers/erb.rb b/actionview/lib/action_view/template/handlers/erb.rb index 69a5a0b1b9..c98685843f 100644 --- a/actionview/lib/action_view/template/handlers/erb.rb +++ b/actionview/lib/action_view/template/handlers/erb.rb @@ -58,7 +58,8 @@ module ActionView self.class.erb_implementation.new( erb, escape: (self.class.escape_ignore_list.include? template.type), - trim: (self.class.erb_trim_mode == "-") + trim: (self.class.erb_trim_mode == "-"), + short_identifier: template.short_identifier ).src end diff --git a/actionview/lib/action_view/template/handlers/erb/erubi.rb b/actionview/lib/action_view/template/handlers/erb/erubi.rb index e602aa117a..b58560063d 100644 --- a/actionview/lib/action_view/template/handlers/erb/erubi.rb +++ b/actionview/lib/action_view/template/handlers/erb/erubi.rb @@ -13,8 +13,15 @@ module ActionView # Dup properties so that we don't modify argument properties = Hash[properties] - properties[:preamble] = "" - properties[:postamble] = "@output_buffer.to_s" + + if ActionView::Base.annotate_template_file_names + properties[:preamble] = "@output_buffer.safe_append='\n';" + properties[:postamble] = "@output_buffer.safe_append='\n';@output_buffer.to_s" + else + properties[:preamble] = "" + properties[:postamble] = "@output_buffer.to_s" + end + properties[:bufvar] = "@output_buffer" properties[:escapefunc] = "" diff --git a/actionview/test/actionpack/controller/render_test.rb b/actionview/test/actionpack/controller/render_test.rb index 64070a9542..707e4b98f4 100644 --- a/actionview/test/actionpack/controller/render_test.rb +++ b/actionview/test/actionpack/controller/render_test.rb @@ -1453,4 +1453,22 @@ class RenderTest < ActionController::TestCase get :render_call_to_partial_with_layout_in_main_layout_and_within_content_for_layout assert_equal "Before (Anthony)\nInside from partial (Anthony)\nAfter\nBefore (David)\nInside from partial (David)\nAfter\nBefore (Ramm)\nInside from partial (Ramm)\nAfter", @response.body end + + def test_template_annotations + ActionView::Base.annotate_template_file_names = true + + get :render_with_explicit_template_with_locals + + lines = @response.body.split("\n") + + assert_includes lines.first, "" + + assert_includes lines[1], "The secret is area51" + + assert_includes lines.last, "" + ensure + ActionView::Base.annotate_template_file_names = false + end end diff --git a/activestorage/test/dummy/config/environments/development.rb b/activestorage/test/dummy/config/environments/development.rb index b38e7f614c..e04ffa0dd4 100644 --- a/activestorage/test/dummy/config/environments/development.rb +++ b/activestorage/test/dummy/config/environments/development.rb @@ -46,6 +46,9 @@ Rails.application.configure do # Raises error for missing translations # config.action_view.raise_on_missing_translations = true + # Render template filenames as comments in HTML + # config.action_view.annotate_template_file_names = true + # Use an evented file watcher to asynchronously detect changes in source code, # routes, locales, etc. This feature depends on the listen gem. # config.file_watcher = ActiveSupport::EventedFileUpdateChecker diff --git a/activestorage/test/dummy/config/environments/test.rb b/activestorage/test/dummy/config/environments/test.rb index e89182bb5c..b9c2799da0 100644 --- a/activestorage/test/dummy/config/environments/test.rb +++ b/activestorage/test/dummy/config/environments/test.rb @@ -35,4 +35,7 @@ Rails.application.configure do # Raises error for missing translations # config.action_view.raise_on_missing_translations = true + + # Render template filenames as comments in HTML + # config.action_view.annotate_template_file_names = true end