Sha256: b38b58c93e57a1c3e40fbdb6c711d0aa5cf7967681c818f2047660a0b9449f92

Contents?: true

Size: 733 Bytes

Versions: 1

Compression:

Stored size: 733 Bytes

Contents

require 'fast_haml/text_compiler'

module FastHaml
  module FilterCompilers
    class Base
      protected

      def compile_texts(temple, texts, tab_width: 0)
        tabs = ' ' * tab_width
        texts = strip_last_empty_lines(texts)
        texts.each do |text|
          temple << [:static, tabs] << text_compiler.compile(text) << [:static, "\n"] << [:newline]
        end
        temple.pop  # discard last [:newline]
        nil
      end

      def text_compiler
        @text_compiler ||= TextCompiler.new(escape_html: false)
      end

      def strip_last_empty_lines(texts)
        texts = texts.dup
        while texts.last && texts.last.empty?
          texts.pop
        end
        texts
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
fast_haml-0.1.9 lib/fast_haml/filter_compilers/base.rb