Exception: Jekyll::Geolexica::JbuilderTag::Error
- Inherits:
-
StandardError
- Object
- StandardError
- Jekyll::Geolexica::JbuilderTag::Error
- Defined in:
- lib/jekyll/geolexica/jbuilder_tag.rb
Instance Attribute Summary collapse
-
#template_body ⇒ Object
readonly
Returns the value of attribute template_body.
Instance Method Summary collapse
-
#detailed_message ⇒ Object
Works only if error has been raised already (requires
#causeto be set). -
#initialize(template_body) ⇒ Error
constructor
A new instance of Error.
-
#location_surroundings(before: 2, after: 2) ⇒ Object
Displays line that the error has occurred at.
- #message ⇒ Object
- #template_backtrace_location ⇒ Object
-
#template_lineno ⇒ Object
This is tricky! The line number relates to the tag content, not to the Liquid template.
Constructor Details
#initialize(template_body) ⇒ Error
Returns a new instance of Error.
67 68 69 |
# File 'lib/jekyll/geolexica/jbuilder_tag.rb', line 67 def initialize(template_body) @template_body = template_body.dup end |
Instance Attribute Details
#template_body ⇒ Object (readonly)
Returns the value of attribute template_body.
65 66 67 |
# File 'lib/jekyll/geolexica/jbuilder_tag.rb', line 65 def template_body @template_body end |
Instance Method Details
#detailed_message ⇒ Object
Works only if error has been raised already (requires #cause
to be set).
88 89 90 91 92 93 94 95 96 97 |
# File 'lib/jekyll/geolexica/jbuilder_tag.rb', line 88 def <<~MSG #{}: #{location_surroundings} Caused by: #{cause.} MSG end |
#location_surroundings(before: 2, after: 2) ⇒ Object
Displays line that the error has occurred at.
100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/jekyll/geolexica/jbuilder_tag.rb', line 100 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 ⇒ Object
82 83 84 |
# File 'lib/jekyll/geolexica/jbuilder_tag.rb', line 82 def "Error when processing Jbuilder template" end |
#template_backtrace_location ⇒ Object
71 72 73 74 |
# File 'lib/jekyll/geolexica/jbuilder_tag.rb', line 71 def template_backtrace_location @template_backtrace_location ||= cause.backtrace_locations.detect { |bl| bl.path == "(eval)" } end |
#template_lineno ⇒ Object
This is tricky! The line number relates to the tag content, not to the Liquid template.
78 79 80 |
# File 'lib/jekyll/geolexica/jbuilder_tag.rb', line 78 def template_lineno template_backtrace_location.lineno end |