Sha256: 92dda672f59fb09cf761f20d729a967d552652491666db847831be43d43cb5be

Contents?: true

Size: 700 Bytes

Versions: 11

Compression:

Stored size: 700 Bytes

Contents

module FastHaml
  module RubyMultiline
    def self.read(line_parser, current_text)
      buf = []
      while is_ruby_multiline?(current_text)
        current_text = line_parser.next_line
        buf << current_text
      end
      buf.join(' ')
    end

    # `text' is a Ruby multiline block if it:
    # - ends with a comma
    # - but not "?," which is a character literal
    #   (however, "x?," is a method call and not a literal)
    # - and not "?\," which is a character literal
    def self.is_ruby_multiline?(text)
      text && text.length > 1 && text[-1] == ?, &&
        !((text[-3, 2] =~ /\W\?/) || text[-3, 2] == "?\\")
    end
    private_class_method :is_ruby_multiline?
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
fast_haml-0.1.10 lib/fast_haml/ruby_multiline.rb
fast_haml-0.1.9 lib/fast_haml/ruby_multiline.rb
fast_haml-0.1.8 lib/fast_haml/ruby_multiline.rb
fast_haml-0.1.7 lib/fast_haml/ruby_multiline.rb
fast_haml-0.1.6 lib/fast_haml/ruby_multiline.rb
fast_haml-0.1.5 lib/fast_haml/ruby_multiline.rb
fast_haml-0.1.4 lib/fast_haml/ruby_multiline.rb
fast_haml-0.1.3 lib/fast_haml/ruby_multiline.rb
fast_haml-0.1.2 lib/fast_haml/ruby_multiline.rb
fast_haml-0.1.1 lib/fast_haml/ruby_multiline.rb
fast_haml-0.1.0 lib/fast_haml/ruby_multiline.rb