Module: HamlLint::Spec::IndentNormalizer

Defined in:
lib/haml_lint/spec/normalize_indent.rb

Overview

Strips off excess leading indentation from each line so we can use Heredocs for writing code without having the leading indentation count.

Instance Method Summary collapse

Instance Method Details

#normalize_indent(code) ⇒ Object



8
9
10
11
# File 'lib/haml_lint/spec/normalize_indent.rb', line 8

def normalize_indent(code)
  leading_indent = code[/^(\s*)/, 1]
  code.lstrip.gsub(/\n#{leading_indent}/, "\n")
end