webmcp
annotate framework/env/trace/_render_sub_tree.lua @ 31:1cd9e69b85cb
add execute.load_chunk(args)
load_chunk loads the content of a lua file and returns the code.
It can construct the path name easily so you can put helper code in
seperate files for DRYness.
load_chunk loads the content of a lua file and returns the code.
It can construct the path name easily so you can put helper code in
seperate files for DRYness.
author | Daniel Poelzleithner <poelzi@poelzi.org> |
---|---|
date | Tue Oct 05 02:34:04 2010 +0200 (2010-10-05) |
parents | 0b7e87f2dc91 |
children | 3c12e7dd93e0 |
rev | line source |
---|---|
jbe/bsw@0 | 1 local function open(class) |
jbe/bsw@0 | 2 slot.put('<li class="trace_' .. class .. '">') |
jbe/bsw@0 | 3 end |
jbe/bsw@0 | 4 local function open_head() |
jbe/bsw@0 | 5 slot.put('<div class="trace_head">') |
jbe/bsw@0 | 6 end |
jbe/bsw@0 | 7 local function close_head() |
jbe/bsw@0 | 8 slot.put('</div>') |
jbe/bsw@0 | 9 end |
jbe/bsw@0 | 10 local function close() |
jbe/bsw@0 | 11 slot.put('</li>') |
jbe/bsw@0 | 12 end |
jbe/bsw@0 | 13 function trace._render_sub_tree(node) |
jbe/bsw@0 | 14 local function render_children(tail) |
jbe/bsw@0 | 15 if #node > 0 then |
jbe/bsw@0 | 16 slot.put('<ul class="trace_list">') |
jbe/bsw@0 | 17 for idx, child in ipairs(node) do |
jbe/bsw@0 | 18 trace._render_sub_tree(child) |
jbe/bsw@0 | 19 end |
jbe/bsw@0 | 20 if tail then |
jbe/bsw@0 | 21 slot.put(tail) |
jbe/bsw@0 | 22 end |
jbe/bsw@0 | 23 slot.put("</ul>") |
jbe/bsw@0 | 24 end |
jbe/bsw@0 | 25 end |
jbe/bsw@0 | 26 local function close_with_children() |
jbe/bsw@0 | 27 close_head() |
jbe/bsw@0 | 28 render_children() |
jbe/bsw@0 | 29 close() |
jbe/bsw@0 | 30 end |
jbe/bsw@0 | 31 local node_type = node.type |
jbe/bsw@0 | 32 if node_type == "root" then |
jbe/bsw@0 | 33 render_children() |
jbe/bsw@0 | 34 elseif node_type == "debug" then |
jbe/bsw@0 | 35 open("debug") |
jbe/bsw@0 | 36 slot.put(encode.html(node.message)) |
jbe/bsw@0 | 37 close() |
poelzi@31 | 38 elseif node_type == "debug_table" then |
poelzi@31 | 39 open("debug") |
poelzi@31 | 40 slot.put("<table>") |
poelzi@31 | 41 if type(node.message) == "table" then |
poelzi@31 | 42 for k, v in pairs(node.message) do |
poelzi@31 | 43 slot.put("<tr><td>", encode.html(tostring(k)),"</td><td>", encode.html(tostring(v)), "</td></tr>") |
poelzi@31 | 44 end |
poelzi@31 | 45 slot.put("</table>") |
poelzi@31 | 46 else |
poelzi@31 | 47 slot.put("debug_table: not of table type") |
poelzi@31 | 48 end |
poelzi@31 | 49 close() |
poelzi@29 | 50 elseif node_type == "traceback" then |
poelzi@29 | 51 open("debug") |
poelzi@29 | 52 slot.put('<pre>') |
poelzi@29 | 53 slot.put(encode.html(node.message)) |
poelzi@29 | 54 slot.put('</pre>') |
poelzi@29 | 55 close() |
jbe/bsw@0 | 56 elseif node_type == "request" then |
jbe/bsw@0 | 57 open("request") |
jbe/bsw@0 | 58 open_head() |
jbe/bsw@0 | 59 slot.put("REQUESTED") |
jbe/bsw@0 | 60 if node.view then |
jbe/bsw@0 | 61 slot.put(" VIEW") |
jbe/bsw@0 | 62 elseif node.action then |
jbe/bsw@0 | 63 slot.put(" ACTION") |
jbe/bsw@0 | 64 end |
jbe/bsw@0 | 65 slot.put( |
jbe/bsw@0 | 66 ": ", |
jbe/bsw@0 | 67 encode.html(node.module), |
jbe/bsw@0 | 68 "/", |
jbe/bsw@0 | 69 encode.html(node.view or node.action) |
jbe/bsw@0 | 70 ) |
jbe/bsw@0 | 71 close_with_children() |
jbe/bsw@0 | 72 elseif node_type == "config" then |
jbe/bsw@0 | 73 open("config") |
jbe/bsw@0 | 74 open_head() |
jbe/bsw@0 | 75 slot.put('Configuration "', encode.html(node.name), '"') |
jbe/bsw@0 | 76 close_with_children() |
jbe/bsw@0 | 77 elseif node_type == "filter" then |
jbe/bsw@0 | 78 open("filter") |
jbe/bsw@0 | 79 open_head() |
jbe/bsw@0 | 80 slot.put(encode.html(node.path)) |
jbe/bsw@0 | 81 close_with_children() |
jbe/bsw@0 | 82 elseif node_type == "view" then |
jbe/bsw@0 | 83 open("view") |
jbe/bsw@0 | 84 open_head() |
jbe/bsw@0 | 85 slot.put( |
jbe/bsw@0 | 86 "EXECUTE VIEW: ", |
jbe/bsw@0 | 87 encode.html(node.module), |
jbe/bsw@0 | 88 "/", |
jbe/bsw@0 | 89 encode.html(node.view) |
jbe/bsw@0 | 90 ) |
jbe/bsw@0 | 91 close_with_children() |
jbe/bsw@0 | 92 elseif node_type == "action" then |
jbe/bsw@0 | 93 if |
jbe/bsw@0 | 94 node.status and ( |
jbe/bsw@0 | 95 node.status == "ok" or |
jbe/bsw@0 | 96 string.find(node.status, "^ok_") |
jbe/bsw@0 | 97 ) |
jbe/bsw@0 | 98 then |
jbe/bsw@0 | 99 open("action_success") |
jbe/bsw@0 | 100 elseif |
jbe/bsw@0 | 101 node.status and ( |
jbe/bsw@0 | 102 node.status == "error" or |
jbe/bsw@0 | 103 string.find(node.status, "^error_") |
jbe/bsw@0 | 104 ) |
jbe/bsw@0 | 105 then |
jbe/bsw@0 | 106 open("action_softfail") |
jbe/bsw@0 | 107 else |
jbe/bsw@0 | 108 open("action_neutral") |
jbe/bsw@0 | 109 end |
jbe/bsw@0 | 110 open_head() |
jbe/bsw@0 | 111 slot.put( |
jbe/bsw@0 | 112 "EXECUTE ACTION: ", |
jbe/bsw@0 | 113 encode.html(node.module), |
jbe/bsw@0 | 114 "/", |
jbe/bsw@0 | 115 encode.html(node.action) |
jbe/bsw@0 | 116 ) |
jbe/bsw@0 | 117 close_head() |
jbe/bsw@0 | 118 if node.status == "softfail" then |
jbe/bsw@0 | 119 render_children( |
jbe/bsw@0 | 120 '<li class="trace_action_status">Status code: "' .. |
jbe/bsw@0 | 121 encode.html(node.failure_code) .. |
jbe/bsw@0 | 122 '"</li>' |
jbe/bsw@0 | 123 ) |
jbe/bsw@0 | 124 else |
jbe/bsw@0 | 125 render_children() |
jbe/bsw@0 | 126 end |
jbe/bsw@0 | 127 close() |
jbe/bsw@0 | 128 elseif node_type == "redirect" then |
jbe/bsw@0 | 129 open("redirect") |
jbe/bsw@0 | 130 open_head() |
jbe/bsw@0 | 131 slot.put("303 REDIRECT TO VIEW: ", encode.html(node.module), "/", encode.html(node.view)) |
jbe/bsw@0 | 132 close_with_children() |
jbe/bsw@0 | 133 elseif node_type == "forward" then |
jbe/bsw@0 | 134 open("forward") |
jbe/bsw@0 | 135 open_head() |
jbe/bsw@0 | 136 slot.put("INTERNAL FORWARD TO VIEW: ", encode.html(node.module), "/", encode.html(node.view)) |
jbe/bsw@0 | 137 close_with_children() |
jbe/bsw@0 | 138 elseif node_type == "exectime" then |
jbe/bsw@0 | 139 open("exectime") |
jbe/bsw@0 | 140 open_head() |
jbe/bsw@0 | 141 slot.put( |
jbe/bsw@0 | 142 "Finished after " .. |
jbe/bsw@0 | 143 string.format("%.1f", os.monotonic_hires_time() * 1000) .. |
jbe/bsw@0 | 144 ' ms (' .. |
jbe/bsw@0 | 145 string.format("%.1f", os.clock() * 1000) .. |
jbe/bsw@0 | 146 ' ms CPU)' |
jbe/bsw@0 | 147 ) |
jbe/bsw@0 | 148 close_with_children() |
jbe/bsw@0 | 149 elseif node_type == "sql" then |
jbe/bsw@0 | 150 open("sql") |
jbe/bsw@0 | 151 if node.error_position then |
jbe/bsw@0 | 152 -- error position starts counting with 1 |
jbe/bsw@0 | 153 local part1 = string.sub(node.command, 1, node.error_position - 1) |
jbe/bsw@0 | 154 --local part2 = string.sub(node.command, node.error_position - 1, node.error_position + 1) |
jbe/bsw@0 | 155 local part2 = string.sub(node.command, node.error_position) |
jbe/bsw@0 | 156 slot.put(encode.html(part1)) |
jbe/bsw@0 | 157 slot.put('<span class="trace_error_position">⇒</span>') |
jbe/bsw@0 | 158 slot.put(encode.html(part2)) |
jbe/bsw@0 | 159 --slot.put('</span>') |
jbe/bsw@0 | 160 --slot.put(encode.html(part3)) |
jbe/bsw@0 | 161 else |
jbe/bsw@0 | 162 slot.put(encode.html(node.command)) |
jbe/bsw@0 | 163 end |
jbe/bsw@0 | 164 close(); |
jbe/bsw@0 | 165 elseif node_type == "error" then |
jbe/bsw@0 | 166 open("error") |
jbe/bsw@0 | 167 open_head() |
jbe/bsw@0 | 168 slot.put("UNEXPECTED ERROR") |
jbe/bsw@0 | 169 close_head() |
jbe/bsw@0 | 170 close() |
jbe/bsw@0 | 171 end |
jbe/bsw@0 | 172 end |