webmcp
diff framework/env/trace/_render_sub_tree.lua @ 0:9fdfb27f8e67
Version 1.0.0
author | jbe/bsw |
---|---|
date | Sun Oct 25 12:00:00 2009 +0100 (2009-10-25) |
parents | |
children | 0b7e87f2dc91 |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/framework/env/trace/_render_sub_tree.lua Sun Oct 25 12:00:00 2009 +0100 1.3 @@ -0,0 +1,154 @@ 1.4 +local function open(class) 1.5 + slot.put('<li class="trace_' .. class .. '">') 1.6 +end 1.7 +local function open_head() 1.8 + slot.put('<div class="trace_head">') 1.9 +end 1.10 +local function close_head() 1.11 + slot.put('</div>') 1.12 +end 1.13 +local function close() 1.14 + slot.put('</li>') 1.15 +end 1.16 +function trace._render_sub_tree(node) 1.17 + local function render_children(tail) 1.18 + if #node > 0 then 1.19 + slot.put('<ul class="trace_list">') 1.20 + for idx, child in ipairs(node) do 1.21 + trace._render_sub_tree(child) 1.22 + end 1.23 + if tail then 1.24 + slot.put(tail) 1.25 + end 1.26 + slot.put("</ul>") 1.27 + end 1.28 + end 1.29 + local function close_with_children() 1.30 + close_head() 1.31 + render_children() 1.32 + close() 1.33 + end 1.34 + local node_type = node.type 1.35 + if node_type == "root" then 1.36 + render_children() 1.37 + elseif node_type == "debug" then 1.38 + open("debug") 1.39 + slot.put(encode.html(node.message)) 1.40 + close() 1.41 + elseif node_type == "request" then 1.42 + open("request") 1.43 + open_head() 1.44 + slot.put("REQUESTED") 1.45 + if node.view then 1.46 + slot.put(" VIEW") 1.47 + elseif node.action then 1.48 + slot.put(" ACTION") 1.49 + end 1.50 + slot.put( 1.51 + ": ", 1.52 + encode.html(node.module), 1.53 + "/", 1.54 + encode.html(node.view or node.action) 1.55 + ) 1.56 + close_with_children() 1.57 + elseif node_type == "config" then 1.58 + open("config") 1.59 + open_head() 1.60 + slot.put('Configuration "', encode.html(node.name), '"') 1.61 + close_with_children() 1.62 + elseif node_type == "filter" then 1.63 + open("filter") 1.64 + open_head() 1.65 + slot.put(encode.html(node.path)) 1.66 + close_with_children() 1.67 + elseif node_type == "view" then 1.68 + open("view") 1.69 + open_head() 1.70 + slot.put( 1.71 + "EXECUTE VIEW: ", 1.72 + encode.html(node.module), 1.73 + "/", 1.74 + encode.html(node.view) 1.75 + ) 1.76 + close_with_children() 1.77 + elseif node_type == "action" then 1.78 + if 1.79 + node.status and ( 1.80 + node.status == "ok" or 1.81 + string.find(node.status, "^ok_") 1.82 + ) 1.83 + then 1.84 + open("action_success") 1.85 + elseif 1.86 + node.status and ( 1.87 + node.status == "error" or 1.88 + string.find(node.status, "^error_") 1.89 + ) 1.90 + then 1.91 + open("action_softfail") 1.92 + else 1.93 + open("action_neutral") 1.94 + end 1.95 + open_head() 1.96 + slot.put( 1.97 + "EXECUTE ACTION: ", 1.98 + encode.html(node.module), 1.99 + "/", 1.100 + encode.html(node.action) 1.101 + ) 1.102 + close_head() 1.103 + if node.status == "softfail" then 1.104 + render_children( 1.105 + '<li class="trace_action_status">Status code: "' .. 1.106 + encode.html(node.failure_code) .. 1.107 + '"</li>' 1.108 + ) 1.109 + else 1.110 + render_children() 1.111 + end 1.112 + close() 1.113 + elseif node_type == "redirect" then 1.114 + open("redirect") 1.115 + open_head() 1.116 + slot.put("303 REDIRECT TO VIEW: ", encode.html(node.module), "/", encode.html(node.view)) 1.117 + close_with_children() 1.118 + elseif node_type == "forward" then 1.119 + open("forward") 1.120 + open_head() 1.121 + slot.put("INTERNAL FORWARD TO VIEW: ", encode.html(node.module), "/", encode.html(node.view)) 1.122 + close_with_children() 1.123 + elseif node_type == "exectime" then 1.124 + open("exectime") 1.125 + open_head() 1.126 + slot.put( 1.127 + "Finished after " .. 1.128 + string.format("%.1f", os.monotonic_hires_time() * 1000) .. 1.129 + ' ms (' .. 1.130 + string.format("%.1f", os.clock() * 1000) .. 1.131 + ' ms CPU)' 1.132 + ) 1.133 + close_with_children() 1.134 + elseif node_type == "sql" then 1.135 + open("sql") 1.136 + if node.error_position then 1.137 + -- error position starts counting with 1 1.138 + local part1 = string.sub(node.command, 1, node.error_position - 1) 1.139 + --local part2 = string.sub(node.command, node.error_position - 1, node.error_position + 1) 1.140 + local part2 = string.sub(node.command, node.error_position) 1.141 + slot.put(encode.html(part1)) 1.142 + slot.put('<span class="trace_error_position">⇒</span>') 1.143 + slot.put(encode.html(part2)) 1.144 + --slot.put('</span>') 1.145 + --slot.put(encode.html(part3)) 1.146 + else 1.147 + slot.put(encode.html(node.command)) 1.148 + end 1.149 + close(); 1.150 + elseif node_type == "error" then 1.151 + open("error") 1.152 + open_head() 1.153 + slot.put("UNEXPECTED ERROR") 1.154 + close_head() 1.155 + close() 1.156 + end 1.157 +end