Exception: Curly::SyntaxError

Inherits:
Error
  • Object
show all
Defined in:
lib/curly/syntax_error.rb

Instance Method Summary collapse

Constructor Details

#initialize(position, source) ⇒ SyntaxError

Returns a new instance of SyntaxError


5
6
7
# File 'lib/curly/syntax_error.rb', line 5

def initialize(position, source)
  @position, @source = position, source
end

Instance Method Details

#messageObject


9
10
11
12
13
14
15
16
# File 'lib/curly/syntax_error.rb', line 9

def message
  start   = [@position - 8, 0].max
  stop    = [@position + 8, @source.length].min
  snippet = @source[start..stop].strip
  line    = @source[0..@position].count("\n") + 1
  "invalid syntax near `#{snippet}` on line #{line} in " \
    "template:\n\n#{@source}\n"
end