Sha256: f50e1e06510d4e2c4ad73d95ecf2cd87704261b4f5a61a482a7a055176e2b208

Contents?: true

Size: 974 Bytes

Versions: 7

Compression:

Stored size: 974 Bytes

Contents

require 'faml/text_compiler'

module Faml
  module FilterCompilers
    class Base
      def need_newline?
        true
      end

      protected

      def compile_texts(temple, texts, tab_width: 0, keep_last_empty_lines: false)
        tabs = ' ' * tab_width
        n = 0
        unless keep_last_empty_lines
          texts, n = strip_last_empty_lines(texts)
        end
        texts.each do |text|
          temple << [:static, tabs] << text_compiler.compile(text)
          unless texts.last.equal?(text)
            temple << [:static, "\n"] << [:newline]
          end
        end
        temple.concat([[:newline]] * n)
        nil
      end

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

      def strip_last_empty_lines(texts)
        n = 0
        texts = texts.dup
        while texts.last && texts.last.empty?
          n += 1
          texts.pop
        end
        [texts, n]
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
faml-0.2.6 lib/faml/filter_compilers/base.rb
faml-0.2.5 lib/faml/filter_compilers/base.rb
faml-0.2.4 lib/faml/filter_compilers/base.rb
faml-0.2.3 lib/faml/filter_compilers/base.rb
faml-0.2.2 lib/faml/filter_compilers/base.rb
faml-0.2.1 lib/faml/filter_compilers/base.rb
faml-0.2.0 lib/faml/filter_compilers/base.rb