From 2d11326c7b7c423be48a868feb5fcd9d980d55cd Mon Sep 17 00:00:00 2001 From: Takashi Kokubun Date: Tue, 11 Jul 2017 22:22:06 +0900 Subject: [PATCH] Fix textareas only after preserved timing --- lib/haml/buffer.rb | 2 +- lib/haml/compiler.rb | 6 +++--- lib/haml/helpers/action_view_mods.rb | 8 ++++++-- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/lib/haml/buffer.rb b/lib/haml/buffer.rb index beb0d4711f..81a4e853b0 100644 --- a/lib/haml/buffer.rb +++ b/lib/haml/buffer.rb @@ -159,7 +159,7 @@ def rstrip! # @since Haml 4.0.1 # @private def fix_textareas!(input) - return input unless toplevel? && input.include?(']*)>(\n| )(.*?)<\/textarea>/im input.gsub!(pattern) do |s| diff --git a/lib/haml/compiler.rb b/lib/haml/compiler.rb index 0525b2e57c..faf895a1f8 100644 --- a/lib/haml/compiler.rb +++ b/lib/haml/compiler.rb @@ -287,11 +287,11 @@ def build_script_formatter(text, opts) text = "(#{text}).strip" end if opts[:preserve_tag] - text = "::Haml::Helpers.preserve(#{text})" + text = "_hamlout.fix_textareas!(::Haml::Helpers.preserve(#{text}))" elsif opts[:preserve_script] - text = "::Haml::Helpers.find_and_preserve(#{text}, _hamlout.options[:preserve])" + text = "_hamlout.fix_textareas!(::Haml::Helpers.find_and_preserve(#{text}, _hamlout.options[:preserve]))" end - "_hamlout.fix_textareas!(#{text});" + "#{text};" end def push_generated_script(text) diff --git a/lib/haml/helpers/action_view_mods.rb b/lib/haml/helpers/action_view_mods.rb index 82a83b4b64..014d131074 100644 --- a/lib/haml/helpers/action_view_mods.rb +++ b/lib/haml/helpers/action_view_mods.rb @@ -58,11 +58,15 @@ def content_tag_with_haml(name, *args, &block) preserve = haml_buffer.options.fetch(:preserve, %w[textarea pre code]).include?(name.to_s) if block_given? && block_is_haml?(block) && preserve - return content_tag_without_haml(name, *args) {preserve(&block)} + return content_tag_without_haml(name, *args) do + haml_buffer.fix_textareas!(Haml::Helpers.preserve(&block)).html_safe + end end content = content_tag_without_haml(name, *args, &block) - content = Haml::Helpers.preserve(content) if preserve && content + if preserve && content + content = haml_buffer.fix_textareas!(Haml::Helpers.preserve(content)).html_safe + end content end