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
#cause
to 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.
69 70 71 |
# File 'lib/jekyll/geolexica/jbuilder_tag.rb', line 69 def initialize(template_body) @template_body = template_body.dup end |
Instance Attribute Details
#template_body ⇒ Object (readonly)
Returns the value of attribute template_body.
67 68 69 |
# File 'lib/jekyll/geolexica/jbuilder_tag.rb', line 67 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).
90 91 92 93 94 95 96 97 98 99 |
# File 'lib/jekyll/geolexica/jbuilder_tag.rb', line 90 def <<~MSG #{}: #{location_surroundings} Caused by: #{cause.} MSG end |
#location_surroundings(before: 2, after: 2) ⇒ Object
Displays line that the error has occurred at.
102 103 104 105 106 107 108 109 110 111 112 113 114 |
# 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 ⇒ Object
84 85 86 |
# File 'lib/jekyll/geolexica/jbuilder_tag.rb', line 84 def "Error when processing Jbuilder template" end |
#template_backtrace_location ⇒ Object
73 74 75 76 |
# 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 ⇒ Object
This is tricky! The line number relates to the tag content, not to the Liquid template.
80 81 82 |
# File 'lib/jekyll/geolexica/jbuilder_tag.rb', line 80 def template_lineno template_backtrace_location.lineno end |