Exception: Curlybars::Error::Parse

Inherits:
Base
  • Object
show all
Defined in:
lib/curlybars/error/parse.rb

Instance Attribute Summary

Attributes inherited from Base

#id, #metadata, #position

Instance Method Summary collapse

Constructor Details

#initialize(source, exception) ⇒ Parse

Returns a new instance of Parse.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/curlybars/error/parse.rb', line 6

def initialize(source, exception)
  position = exception.current.position

  if exception.current.type == :EOS
    message = "A block helper hasn't been closed properly"
    position = EOSPosition.new(source)
  else
    line_number = position.line_number
    line_offset = position.line_offset
    length = exception.current.position.length

    error_line = source.split("\n")[line_number - 1]
    before_error = error_line.first(line_offset).last(10)
    after_error = error_line[line_offset + length..].first(10)
    error = error_line.slice(line_offset, length)

    details = [before_error, error, after_error]
    message = ".. %s `%s` %s .. is not permitted in this context" % details
  end

  super('parse', message, position)
end