Sha256: ee1813ac24ee416c906d6a107fa0f6ba0d7e1ec12658768efe65d285f71796c7

Contents?: true

Size: 667 Bytes

Versions: 9

Compression:

Stored size: 667 Bytes

Contents

# frozen-string-literal: true
require_relative 'base'

module Faml
  module FilterCompilers
    class Preserve < Base
      include Temple::Utils

      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

      def self.preserve(str)
        str.gsub("\n", '&#x000A;')
      end
    end

    register(:preserve, Preserve)
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
faml-0.7.3 lib/faml/filter_compilers/preserve.rb
faml-0.7.2 lib/faml/filter_compilers/preserve.rb
faml-0.7.1 lib/faml/filter_compilers/preserve.rb
faml-0.7.0 lib/faml/filter_compilers/preserve.rb
faml-0.6.5 lib/faml/filter_compilers/preserve.rb
faml-0.6.4 lib/faml/filter_compilers/preserve.rb
faml-0.6.3 lib/faml/filter_compilers/preserve.rb
faml-0.6.2 lib/faml/filter_compilers/preserve.rb
faml-0.6.1 lib/faml/filter_compilers/preserve.rb