Method: Exception.source_extract

Defined in:
lib/nitro/compiler/errors.rb

.source_extract(step, indent = 0) ⇒ Object

Extract the source arround the error line.



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/nitro/compiler/errors.rb', line 42

def source_extract(step, indent = 0)
  begin
    file, no = file_and_line_no(step)        
    source = File.read(file)

    if file =~ /\.xhtml$/
      source = Compiler.new(Nitro::Controller).transform_template(:action, source)
      no -= 2
    end

    source = source.split("\n")
    start = (no-1) - SOURCE_RADIUS
    finish = (no-1) + SOURCE_RADIUS
    start = 0 if start < 0
    finish = source.size if finish > source.size
  
    number = start
    extract = source[start..finish].collect do |line| 
      number += 1
      line = line.gsub(/; @out #{Nitro::TemplateMixin::START_DELIM}/, ' ?>').gsub(/#{Nitro::TemplateMixin::END_DELIM}/, '<?r ')
      "#{' ' * indent}#{number}: #{line}"
    end  

    return extract.join("\n")
  rescue Object => ex
    ''
  end
end