Sha256: 60ff7a8d39cbb4acce7323c2c4d0d8d3850568918c20d664874d8f1b34af8165

Contents?: true

Size: 652 Bytes

Versions: 12

Compression:

Stored size: 652 Bytes

Contents

require 'faml/filter_compilers/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

12 entries across 12 versions & 1 rubygems

Version Path
faml-0.3.1 lib/faml/filter_compilers/preserve.rb
faml-0.3.0 lib/faml/filter_compilers/preserve.rb
faml-0.2.16 lib/faml/filter_compilers/preserve.rb
faml-0.2.15 lib/faml/filter_compilers/preserve.rb
faml-0.2.14 lib/faml/filter_compilers/preserve.rb
faml-0.2.13 lib/faml/filter_compilers/preserve.rb
faml-0.2.12 lib/faml/filter_compilers/preserve.rb
faml-0.2.11 lib/faml/filter_compilers/preserve.rb
faml-0.2.10 lib/faml/filter_compilers/preserve.rb
faml-0.2.9 lib/faml/filter_compilers/preserve.rb
faml-0.2.8 lib/faml/filter_compilers/preserve.rb
faml-0.2.7 lib/faml/filter_compilers/preserve.rb