Sha256: db1562afc1c0bd8f07694ce5ed27ebb37923a2dd5fddcce4c8204a13ad6bcc5f

Contents?: true

Size: 1016 Bytes

Versions: 7

Compression:

Stored size: 1016 Bytes

Contents

class RenderMePretty::Erb
  class SyntaxErrorHandler < BaseHandler
    # 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("#{template_path_with_error}:(\\\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

    def error_in_layout?
      # first line has the error info
      lines = @exception.message.split("\n")
      error_info = lines.first
      md = error_info.match(/(.*):(\d+): syntax error/)
      file = md[1]
      file == @layout_path
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
render_me_pretty-1.0.0 lib/render_me_pretty/erb/syntax_error_handler.rb
render_me_pretty-0.9.0 lib/render_me_pretty/erb/syntax_error_handler.rb
render_me_pretty-0.8.4 lib/render_me_pretty/erb/syntax_error_handler.rb
render_me_pretty-0.8.3 lib/render_me_pretty/erb/syntax_error_handler.rb
render_me_pretty-0.8.2 lib/render_me_pretty/erb/syntax_error_handler.rb
render_me_pretty-0.8.1 lib/render_me_pretty/erb/syntax_error_handler.rb
render_me_pretty-0.8.0 lib/render_me_pretty/erb/syntax_error_handler.rb