Class: Hamlit::Filters::TextBase

Inherits:
Base show all
Defined in:
lib/hamlit/filters/text_base.rb

Direct Known Subclasses

Cdata, Css, Javascript

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from Hamlit::Filters::Base

Instance Method Details

#compile_text!(temple, node, prefix) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/hamlit/filters/text_base.rb', line 5

def compile_text!(temple, node, prefix)
  text = node.value[:text].rstrip.gsub(/^/, prefix)
  if ::Hamlit::HamlUtil.contains_interpolation?(node.value[:text])
    # original: Haml::Filters#compile
    text = ::Hamlit::HamlUtil.slow_unescape_interpolation(text).gsub(/(\\+)n/) do |s|
      escapes = $1.size
      next s if escapes % 2 == 0
      "#{'\\' * (escapes - 1)}\n"
    end
    text.prepend("\n")
    temple << [:dynamic, text]
  else
    node.value[:text].split("\n").size.times do
      temple << [:newline]
    end
    temple << [:static, text]
  end
end