Sha256: c1e40de452ada8b56bd4be4195505cef89c73665530334b2a0ffe91bc9ba2350

Contents?: true

Size: 1.45 KB

Versions: 5

Compression:

Stored size: 1.45 KB

Contents

require 'mega/orm_support'

module Nitro

class ActionCompileError < SyntaxError
  SOURCE_CODE_RADIUS = 5

  attr_accessor :original_excpetion
    
  def initialize(source_code, filename, original_exception)
    @source_code = source_code.split("\n")
    @filename = filename
    @original_exception = original_exception
  end
  
  def line_number
    trace = @original_exception.backtrace.join

    if trace.include?(":in `class_eval'")
      trace.scan(/:([0-9]*):in `class_eval'/).first.first.to_i
    else
      1
    end
  end
  
  def source_extract(indent = 0)
    ln = line_number
    start_line = [ln - SOURCE_CODE_RADIUS, 0].max
    end_line = [ln + SOURCE_CODE_RADIUS - 1, @source_code.length].min

    number = start_line
    extract = @source_code[start_line..end_line].collect do |line| 
      number += 1
      line = line.gsub(/; @out << %\^/, ' ?>').gsub(/\^;/, '<?r ')
      if number == line_number
        "#{' ' * indent}#{number}: #{line}"
      else
        "#{' ' * indent}#{number}: #{line}"
      end
    end

    return extract.join("\n")
  end

  def backtrace  
    @original_exception.backtrace.collect do |line|
      line.gsub("#{Nitro::LibPath}/", '')
    end.compact
  end

  def to_s
    "#{self.class.to_s.demodulize} (#{@original_exception.class}): '#@filename' at line ##{line_number}"
  end
  
  def message
    "#{to_s}\n#{source_extract}"
  end
end
  
class TemplateCompileError < ActionCompileError
end

end

# * George Moschovitis <gm@navel.gr>

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
nitro-0.23.0 lib/nitro/compiler/errors.rb
nitro-0.24.0 lib/nitro/compiler/errors.rb
nitro-0.25.0 lib/nitro/compiler/errors.rb
nitro-0.26.0 lib/nitro/compiler/errors.rb
nitro-0.27.0 lib/nitro/compiler/errors.rb