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

Version Path
hamlit-1.4.5 lib/hamlit/parsers/multiline.rb
hamlit-1.4.3 lib/hamlit/parsers/multiline.rb
hamlit-1.4.2 lib/hamlit/parsers/multiline.rb
hamlit-1.4.1 lib/hamlit/parsers/multiline.rb
hamlit-1.3.2 lib/hamlit/parsers/multiline.rb
hamlit-1.3.1 lib/hamlit/parsers/multiline.rb
hamlit-1.3.0 lib/hamlit/parsers/multiline.rb
hamlit-1.2.1 lib/hamlit/parsers/multiline.rb
hamlit-1.2.0 lib/hamlit/parsers/multiline.rb
hamlit-1.1.1 lib/hamlit/parsers/multiline.rb
hamlit-1.1.0 lib/hamlit/parsers/multiline.rb
hamlit-1.0.0 lib/hamlit/parsers/multiline.rb
hamlit-0.6.2 lib/hamlit/parsers/multiline.rb
hamlit-0.6.1 lib/hamlit/parsers/multiline.rb
hamlit-0.6.0 lib/hamlit/parsers/multiline.rb
hamlit-0.5.3 lib/hamlit/parsers/multiline.rb
hamlit-0.5.2 lib/hamlit/parsers/multiline.rb
hamlit-0.5.1 lib/hamlit/parsers/multiline.rb
hamlit-0.5.0 lib/hamlit/parsers/multiline.rb
hamlit-0.4.3 lib/hamlit/parsers/multiline.rb