Class: Faml::FilterCompilers::Preserve

Inherits:
Base
  • Object
show all
Includes:
Temple::Utils
Defined in:
lib/faml/filter_compilers/preserve.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#need_newline?

Class Method Details

.preserve(str) ⇒ Object



20
21
22
# File 'lib/faml/filter_compilers/preserve.rb', line 20

def self.preserve(str)
  str.gsub("\n", '
')
end

Instance Method Details

#compile(ast) ⇒ Object



9
10
11
12
13
14
15
16
17
18
# File 'lib/faml/filter_compilers/preserve.rb', line 9

def compile(ast)
  temple = [:multi, [:newline]]
  # I don't know why only :preserve filter keeps the last empty lines.
  compile_texts(temple, ast.lineno, ast.texts, keep_last_empty_lines: true)
  sym = unique_name
  [:multi,
   [:capture, sym, temple],
   [:dynamic, "::Faml::FilterCompilers::Preserve.preserve(#{sym})"],
  ]
end