Sha256: ab982a7b38fa8b9394be9228c4aa5470aacf70c0e96d8ee7a48517391514049b
Contents?: true
Size: 1.15 KB
Versions: 32
Compression:
Stored size: 1.15 KB
Contents
require 'hamlit/concerns/line_reader' module Hamlit module Parsers module Multiline include Concerns::LineReader def preprocess_multilines(template) reset_lines(template.split("\n")) result = [] while @lines[@current_lineno + 1] @current_lineno += 1 unless end_with_pipe?(current_line) result << current_line next end prefix = current_line[/\A */] lines = scan_multilines result << prefix + build_multiline(lines) (lines.length - 1).times { result << '' } end result.map { |line| "#{line}\n" }.join end private def end_with_pipe?(line) return false unless line line.strip =~ / \|\Z/ end def scan_multilines lines = [] while end_with_pipe?(current_line) lines << current_line @current_lineno += 1 end @current_lineno -= 1 lines end def build_multiline(lines) lines = lines.map do |line| line.strip.gsub(/ *\|\Z/, '') end lines.join(' ') end end end end
Version data entries
32 entries across 32 versions & 1 rubygems