class Jekyll::Geolexica::JbuilderTag::Error
Attributes
template_body[R]
Public Class Methods
new(template_body)
click to toggle source
# File lib/jekyll/geolexica/jbuilder_tag.rb, line 69 def initialize(template_body) @template_body = template_body.dup end
Public Instance Methods
detailed_message()
click to toggle source
Works only if error has been raised already (requires #cause
to be set).
# File lib/jekyll/geolexica/jbuilder_tag.rb, line 90 def detailed_message <<~MSG #{message}: #{location_surroundings} Caused by: #{cause.message} MSG end
location_surroundings(before: 2, after: 2)
click to toggle source
Displays line that the error has occurred at.
# File lib/jekyll/geolexica/jbuilder_tag.rb, line 102 def location_surroundings(before: 2, after: 2) line_idx = template_lineno - 1 # template_lineno is indexed from 1 before_lines = template_body.lines[line_idx - before, before] after_lines = template_body.lines[line_idx + 1, after] that_line = template_body.lines[line_idx] before_lines.each { |l| l.prepend("\s" * 4) } after_lines.each { |l| l.prepend("\s" * 4) } that_line.prepend("==> ") [*before_lines, that_line, *after_lines].join("") end
message()
click to toggle source
# File lib/jekyll/geolexica/jbuilder_tag.rb, line 84 def message "Error when processing Jbuilder template" end
template_backtrace_location()
click to toggle source
# File lib/jekyll/geolexica/jbuilder_tag.rb, line 73 def template_backtrace_location @template_backtrace_location ||= cause.backtrace_locations.detect { |bl| bl.path == "(eval)" } end
template_lineno()
click to toggle source
This is tricky! The line number relates to the tag content, not to the Liquid template.
# File lib/jekyll/geolexica/jbuilder_tag.rb, line 80 def template_lineno template_backtrace_location.lineno end