Sha256: 507d3a191e50b236b4c2e874648c4e9fe071954146c4d07090969ff56f559094

Contents?: true

Size: 667 Bytes

Versions: 2

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

2 entries across 2 versions & 1 rubygems

Version Path
faml-0.8.1 lib/faml/filter_compilers/preserve.rb
faml-0.8.0 lib/faml/filter_compilers/preserve.rb