Sha256: 71b059c236ad67e8922b155deb63d5ff4c63d4f4251f18228639e37c2db1736a

Contents?: true

Size: 879 Bytes

Versions: 1

Compression:

Stored size: 879 Bytes

Contents

class RenderMePretty::Erb
  class SyntaxErrorHandler < BaseHandler
    def handle
      line_number = find_line_number
      pretty_trace(line_number, full_message=false) # returns StringIO
    end

    # spec/fixtures/invalid/syntax.erb:2: syntax error, unexpected ';', expecting ']'
    # );  if ENV['TEST' ; _erbout.<<(-" missing ending...
    #                   ^
    # spec/fixtures/invalid/syntax.erb:12: syntax error, unexpected keyword_end, expecting end-of-input
    # end;end;end;end
    #             ^~~
    #
    # We will only find the first line number for the error.
    def find_line_number
      pattern = Regexp.new("#{@path}:(\\\d+): syntax error")
      lines = @exception.message.split("\n")
      found_line = lines.find do |line|
        line.match(pattern)
      end
      md = found_line.match(pattern)
      md[1].to_i # line_number
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
render_me_pretty-0.6.0 lib/render_me_pretty/erb/syntax_error_handler.rb