module Haml::Util
Haml
does heavy transformations to strings that contain interpolation without a way of perfectly inverting that transformation.
We need this monkey patch to have a way of recovering the original strings as they are in the haml files, so that we can use them and then autocorrect them.
The HamlLint::Document
carries over a hash of interpolation to original string. The below patches are there to extract said information from Haml’s parsing.
Public Class Methods
unescape_interpolation_to_original_cache()
click to toggle source
The cache for the current Thread (technically Fiber)
# File lib/haml_lint/extensions/haml_util_unescape_interpolation_tracking.rb, line 13 def self.unescape_interpolation_to_original_cache Thread.current[:haml_lint_unescape_interpolation_to_original_cache] ||= {} end
unescape_interpolation_to_original_cache_take_and_wipe()
click to toggle source
As soon as a HamlLint::Document
has finished processing a HAML source, this gets called to get a copy of this cache and clear up for the next HAML processing
# File lib/haml_lint/extensions/haml_util_unescape_interpolation_tracking.rb, line 19 def self.unescape_interpolation_to_original_cache_take_and_wipe value = unescape_interpolation_to_original_cache.dup unescape_interpolation_to_original_cache.clear value end
Public Instance Methods
unescape_interpolation(str, escape_html = nil)
Also aliased as: unescape_interpolation_without_original_tracking
unescape_interpolation_with_original_tracking(str, escape_html = nil)
click to toggle source
Overriding the unescape_interpolation
method to store the return and original string in the cache.
# File lib/haml_lint/extensions/haml_util_unescape_interpolation_tracking.rb, line 27 def unescape_interpolation_with_original_tracking(str, escape_html = nil) value = unescape_interpolation_without_original_tracking(str, escape_html) Haml::Util.unescape_interpolation_to_original_cache[value] = str value end
Also aliased as: unescape_interpolation
unescape_interpolation_without_original_tracking(str, escape_html = nil)
Alias for: unescape_interpolation