15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
# File 'lib/jsdebug/processor.rb', line 15
def evaluate(context, locals, &block)
log_methods = %w[log debug info warn error].
map{|c| Regexp.escape "debug.#{c}"}
block_methods = %w[start end].
map{|c| Regexp.escape "debug_#{c}"}
pass_methods = %w[assert clear count dir dirxml exception group groupCollapsed groupEnd profile profileEnd table time timeEnd trace].
map{|c| Regexp.escape "debug.#{c}"}
log_regex = Regexp.new log_methods.map{|c| "#{c}#{Regexp.escape '('}"}.join("|")
debug_regex = Regexp.new (log_methods + pass_methods).join("|")
any_debug_regex = Regexp.new (log_methods + pass_methods + block_methods).join("|")
if %w[jsdebug jquery jquery_ujs jquery-ui].include? name || !data =~ any_debug_regex
return data
end
new_data = []
index = 0
debug_block = false
data.each_line do |line|
index += 1
if(is_jsdebug_allowed? && line.match(debug_regex))
if line.match(log_regex)
cmd = line.scan(log_regex).first
new_data << line.gsub(cmd, "#{cmd}'[#{name}::#{index}]', ")
else
new_data << line
end
else
if (!is_jsdebug_allowed?)
if line.match(/debug_start/)
debug_block = true
elsif line.match(/debug_end/)
debug_block = false
next
end
next if debug_block
end
new_data << line if !line.match(debug_regex)
end
end
return new_data.join("")
end
|