Exception: Svelte::Errors::TemplateError
- Inherits:
-
StandardError
- Object
- StandardError
- Svelte::Errors::TemplateError
- Defined in:
- lib/svelte/errors.rb
Constant Summary collapse
- SOURCE_CODE_RADIUS =
3
Instance Attribute Summary collapse
-
#cause ⇒ Object
readonly
Returns the value of attribute cause.
-
#template ⇒ Object
readonly
Returns the value of attribute template.
Instance Method Summary collapse
- #annotated_source_code ⇒ Object
-
#backtrace ⇒ Object
Following is copypasta-ed from ActionView::Template::Error.
- #backtrace_locations ⇒ Object
- #file_name ⇒ Object
-
#initialize(template, error) ⇒ TemplateError
constructor
A new instance of TemplateError.
- #line_number ⇒ Object
- #message ⇒ Object
- #source_extract(indentation = 0) ⇒ Object
- #sub_template_message ⇒ Object
- #sub_template_of(template_path) ⇒ Object
Constructor Details
#initialize(template, error) ⇒ TemplateError
Returns a new instance of TemplateError.
59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/svelte/errors.rb', line 59 def initialize(template, error) raise("Did not provide cause error") unless error @cause = error raise("Did not provide template") unless template @template, @sub_templates = template, nil raise("Cause error is nil for TemplateError") unless @cause @cause.template = template # steep:ignore:start super(@cause.) # : self # steep:ignore:end end |
Instance Attribute Details
#cause ⇒ Object (readonly)
Returns the value of attribute cause.
55 56 57 |
# File 'lib/svelte/errors.rb', line 55 def cause @cause end |
#template ⇒ Object (readonly)
Returns the value of attribute template.
55 56 57 |
# File 'lib/svelte/errors.rb', line 55 def template @template end |
Instance Method Details
#annotated_source_code ⇒ Object
78 79 80 |
# File 'lib/svelte/errors.rb', line 78 def annotated_source_code @cause.annotated_source_code end |
#backtrace ⇒ Object
Following is copypasta-ed from ActionView::Template::Error
83 84 85 |
# File 'lib/svelte/errors.rb', line 83 def backtrace @cause.backtrace end |
#backtrace_locations ⇒ Object
87 88 89 |
# File 'lib/svelte/errors.rb', line 87 def backtrace_locations @cause.backtrace_locations end |
#file_name ⇒ Object
91 92 93 |
# File 'lib/svelte/errors.rb', line 91 def file_name @template.identifier end |
#line_number ⇒ Object
124 125 126 127 128 129 130 |
# File 'lib/svelte/errors.rb', line 124 def line_number @line_number ||= if file_name regexp = /#{Regexp.escape File.basename(file_name)}:(\d+)/ $1 if =~ regexp || backtrace.find { |line| line =~ regexp } end end |
#message ⇒ Object
74 75 76 |
# File 'lib/svelte/errors.rb', line 74 def @cause. end |
#source_extract(indentation = 0) ⇒ Object
104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/svelte/errors.rb', line 104 def source_extract(indentation = 0) return [] unless (num = line_number) num = num.to_i source_code = @template.encode!.split("\n") start_on_line = [num - SOURCE_CODE_RADIUS - 1, 0].max end_on_line = [num + SOURCE_CODE_RADIUS - 1, source_code.length].min indent = end_on_line.to_s.size + indentation return [] unless (source_code = source_code[start_on_line..end_on_line]) formatted_code_for(source_code, start_on_line, indent) end |
#sub_template_message ⇒ Object
95 96 97 98 99 100 101 102 |
# File 'lib/svelte/errors.rb', line 95 def if @sub_templates "Trace of template inclusion: " + @sub_templates.collect(&:inspect).join(", ") else "" end end |
#sub_template_of(template_path) ⇒ Object
119 120 121 122 |
# File 'lib/svelte/errors.rb', line 119 def sub_template_of(template_path) @sub_templates ||= [] @sub_templates << template_path end |