Sha256: 19f4bfc5dfb6f548faa0d0f7b48b05eb2341205c6495313b4d3b918596623279
Contents?: true
Size: 1.02 KB
Versions: 2
Compression:
Stored size: 1.02 KB
Contents
# frozen_string_literal: true require_relative '../text_compiler' module Faml module FilterCompilers class Base def need_newline? true end protected def compile_texts(temple, lineno, 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_with_index do |text, i| temple << [:static, tabs] << text_compiler.compile(text, lineno + i + 1) 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
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
faml-0.8.1 | lib/faml/filter_compilers/base.rb |
faml-0.8.0 | lib/faml/filter_compilers/base.rb |