Sha256: 2838934f4d80bb13c0bf890446a21c3b8c68b7247dc06e6e4d1d4a69d7a452a3
Contents?: true
Size: 1.02 KB
Versions: 9
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
9 entries across 9 versions & 1 rubygems