Exception: StaticMatic::TemplateError
- Inherits:
-
StandardError
- Object
- StandardError
- StaticMatic::TemplateError
- Defined in:
- lib/staticmatic/template_error.rb
Constant Summary
- SOURCE_CODE_RADIUS =
3
Instance Attribute Summary (collapse)
-
- (Object) backtrace
readonly
Returns the value of attribute backtrace.
-
- (Object) original_exception
readonly
Returns the value of attribute original_exception.
Instance Method Summary (collapse)
- - (Object) filename
-
- (TemplateError) initialize(template, original_exception)
constructor
A new instance of TemplateError.
-
- (Object) line_number
TODO: Replace 'haml|sass' with any registered engines.
- - (Object) source_extract(indentation = 0)
Constructor Details
- (TemplateError) initialize(template, original_exception)
A new instance of TemplateError
6 7 8 9 10 11 12 13 14 15 |
# File 'lib/staticmatic/template_error.rb', line 6 def initialize(template, original_exception) @template, @original_exception = template, original_exception @backtrace = original_exception.backtrace if template @source = File.read(template) else @source = "" end end |
Instance Attribute Details
- (Object) backtrace (readonly)
Returns the value of attribute backtrace
4 5 6 |
# File 'lib/staticmatic/template_error.rb', line 4 def backtrace @backtrace end |
- (Object) original_exception (readonly)
Returns the value of attribute original_exception
4 5 6 |
# File 'lib/staticmatic/template_error.rb', line 4 def original_exception @original_exception end |
Instance Method Details
- (Object) filename
22 23 24 |
# File 'lib/staticmatic/template_error.rb', line 22 def filename @template end |
- (Object) line_number
TODO: Replace 'haml|sass' with any registered engines
18 19 20 |
# File 'lib/staticmatic/template_error.rb', line 18 def line_number @line_number ||= $2 if backtrace.find { |line| line =~ /\((haml|sass|scss)\)\:(\d+)/ } end |
- (Object) source_extract(indentation = 0)
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/staticmatic/template_error.rb', line 26 def source_extract(indentation = 0) return "" unless num = line_number num = num.to_i source_code = @source.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 = ' ' * indentation line_counter = start_on_line return unless source_code = source_code[start_on_line..end_on_line] source_code.collect do |line| line_counter += 1 "#{indent}#{line_counter}: #{line}\n" end.to_s end |