lib/sprockets/source_line.rb in sprockets-0.9.1 vs lib/sprockets/source_line.rb in sprockets-1.0.0
- old
+ new
@@ -55,16 +55,28 @@
def inspect
"line #@number of #{@source_file.pathname}"
end
def to_s(constants = source_file.environment.constants)
- line.chomp.gsub(/<%=(.*?)%>/) do
- constant = $1.strip
- if value = constants[constant]
- value
- else
- raise UndefinedConstantError, "couldn't find constant `#{constant}' in #{inspect}"
- end
- end + $/
+ result = line.chomp
+ interpolate_constants!(result, constants)
+ strip_trailing_whitespace!(result)
+ result + $/
end
+
+ protected
+ def interpolate_constants!(result, constants)
+ result.gsub!(/<%=(.*?)%>/) do
+ constant = $1.strip
+ if value = constants[constant]
+ value
+ else
+ raise UndefinedConstantError, "couldn't find constant `#{constant}' in #{inspect}"
+ end
+ end
+ end
+
+ def strip_trailing_whitespace!(result)
+ result.gsub!(/\s+$/, "")
+ end
end
end