Sha256: 83b6683b27dc51001f8566c04eba7b1909b94329499479e73f82d4d6c7c92843

Contents?: true

Size: 709 Bytes

Versions: 7

Compression:

Stored size: 709 Bytes

Contents

require 'fast_haml/filter_compilers/base'

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

      def compile(texts)
        temple = [:multi]
        texts.each do |text|
          temple << text_compiler.compile(text)
          unless texts.last.equal?(text)
            temple << [:static, "\n"]
          end
          temple << [:newline]
        end
        sym = unique_name
        [:multi,
          [:capture, sym, temple],
          [:dynamic, "::FastHaml::FilterCompilers::Preserve.preserve(#{sym})"],
        ]
      end

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

    register(:preserve, Preserve)
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
fast_haml-0.1.8 lib/fast_haml/filter_compilers/preserve.rb
fast_haml-0.1.7 lib/fast_haml/filter_compilers/preserve.rb
fast_haml-0.1.6 lib/fast_haml/filter_compilers/preserve.rb
fast_haml-0.1.5 lib/fast_haml/filter_compilers/preserve.rb
fast_haml-0.1.4 lib/fast_haml/filter_compilers/preserve.rb
fast_haml-0.1.3 lib/fast_haml/filter_compilers/preserve.rb
fast_haml-0.1.2 lib/fast_haml/filter_compilers/preserve.rb