Sha256: 1b2dc8dd1326ba596bf4dabf632a04fcb129f926ba93ba22ceaac1511de56bd9
Contents?: true
Size: 1.27 KB
Versions: 37
Compression:
Stored size: 1.27 KB
Contents
module Hamlit module Concerns module LineReader def reset_lines(lines) @lines = lines @current_lineno = -1 end def current_line @lines[@current_lineno] end # Return nearest line ignoring empty lines. def next_line lineno = @current_lineno + 1 while @lines[lineno] && empty_line?(@lines[lineno]) lineno += 1 end @lines[lineno] end def empty_line?(line) line =~ /\A *\Z/ end def skip_lines while next_indent >= @current_indent @current_lineno += 1 end end def read_lines lines = [] while read_line? lines << @lines[@current_lineno + 1] @current_lineno += 1 end trim_lines(lines) end private def trim_lines(lines) size = (lines.first || '').index(/[^\s]/) || 0 lines.map { |line| line.gsub(/\A {#{size}}/, '') } end def read_line? return true if count_indent(next_line, strict: false) >= @current_indent line = @lines[@current_lineno + 1] return false unless line # NOTE: preserve filter also requires an empty line line.gsub(/ /, '').length == 0 end end end end
Version data entries
37 entries across 37 versions & 1 rubygems