[#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 :)
This commit is contained in:
Holger Just 2011-11-26 16:10:24 +01:00
parent 28ce07b1dd
commit 9f4d12ffdf
2 changed files with 3 additions and 2 deletions

View File

@ -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})

View File

@ -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