From 9f4d12ffdfac6b3a7c20cfc0ed6cacf14224034d Mon Sep 17 00:00:00 2001 From: Holger Just <h.just@finn.de> Date: Sat, 26 Nov 2011 16:10:24 +0100 Subject: [PATCH] [#734] Don't modify text inline. This is not only a wee bit faster (yay!) but also allows use to deal with frozen strings and doesn't change content which might inadvertently be saved later on. And it fixes some broken tests on Ruby 1.9 :) --- app/helpers/application_helper.rb | 2 +- lib/chili_project/liquid/legacy.rb | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 73bfc5aa6..ac3d7da58 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -461,7 +461,7 @@ module ApplicationHelper only_path = options.delete(:only_path) == false ? false : true begin - ChiliProject::Liquid::Legacy.run_macros(text) + text = ChiliProject::Liquid::Legacy.run_macros(text) liquid_template = ChiliProject::Liquid::Template.parse(text) liquid_variables = get_view_instance_variables_for_liquid liquid_variables.merge!({'current_user' => User.current}) diff --git a/lib/chili_project/liquid/legacy.rb b/lib/chili_project/liquid/legacy.rb index c2a237687..73642e56e 100644 --- a/lib/chili_project/liquid/legacy.rb +++ b/lib/chili_project/liquid/legacy.rb @@ -22,11 +22,12 @@ module ChiliProject def self.run_macros(content) macros.each do |macro_name, macro| next unless macro[:match].present? && macro[:replace].present? - content.gsub!(macro[:match]) do |match| + content = content.gsub(macro[:match]) do |match| # Use block form so $1 and $2 are set properly "{#{macro[:replace]} #{macro[:new_name]} '#{$2}' #{macro[:replace]}}" end end + content end # Add support for a legacy macro syntax that was converted to liquid -- GitLab