class Qwik::PrettyBacktrace
Constants
- MARGIN
- MIN_MARGIN
- POS_NUM
Public Class Methods
get_excerpt(file, linenum, margin)
click to toggle source
# File vendor/qwik/lib/qwik/common-backtrace.rb, line 41 def self.get_excerpt(file, linenum, margin) margin = MIN_MARGIN if margin < MIN_MARGIN return '' if margin < 0 f = file.path return '' unless f.exist? str = f.read b = linenum - margin - 1 # beginning ar = str.to_a[b, margin*2+1] table = [] ar.each_with_index {|line, num| line = " \n" if line == "\n" # only for visual effect n = b + num + 1 attr = {:class=>'even'} attr = {:class=>'odd'} if n % 2 == 1 attr = {:class=>'target'} if n == linenum table << [:tr, attr, [:th, n.to_s], [:td, [:pre, line]]] } return [:table, table] end
get_pos(sourcefile, sourceline)
click to toggle source
# File vendor/qwik/lib/qwik/common-backtrace.rb, line 35 def self.get_pos(sourcefile, sourceline) ar = sourcefile.split('/') ar = ar[-POS_NUM, POS_NUM] if POS_NUM < ar.length return ar.join('/') end
to_html(e)
click to toggle source
# File vendor/qwik/lib/qwik/common-backtrace.rb, line 20 def self.to_html(e) margin = MARGIN trs = e.backtrace.map {|str| sf, sl, method = str.split(':', 3) margin -= 1 [[:tr, [:td, {:class=>'file'}, get_pos(sf, sl)+':', [:strong, sl]], [:td, {:class=>'method'}, method.to_s]], [:tr, [:td, {:class=>'excerpt', :colspan=>'3'}, get_excerpt(sf, sl.to_i, margin)]]] } return [[:h3, e.to_s], [:table, {:class=>'exception'}, trs]] end