Differences From
Artifact [ad44dd6129]:
27 27 local segs = {}
28 28 local constlen = 0
29 29 -- strip out all irrelevant whitespace to tidy things up
30 30 -- TODO: find way to exclude <pre> tags?
31 31 str = str:gsub('[\n^]%s+','')
32 32 str = str:gsub('%s+[\n$]','')
33 33 str = str:gsub('\n','')
34 + str = str:gsub('</a><a ','</a> <a ') -- keep nav links from getting smooshed
34 35 for start, key, stop in string.gmatch(str,'()'..tplchar..'(%w+)()') do
35 36 if string.sub(str,start-1,start-1) ~= '\\' then
36 37 segs[#segs+1] = string.sub(str,last,start-1)
37 38 fields[#segs] = key
38 39 last = stop
39 40 end
40 41 end
................................................................................
65 66 [runningtally] = [runningtally] + lib.str.sz([symself].[key])*fac
66 67 end
67 68 end
68 69 end
69 70
70 71 local copiers = {}
71 72 local senders = {}
73 + local appenders = {}
72 74 local symtxt = symbol(lib.mem.ptr(int8))
73 75 local cpypos = symbol(&opaque)
76 + local accumulator = symbol(&lib.str.acc)
74 77 local destcon = symbol(&lib.net.mg_connection)
75 78 for idx, seg in ipairs(segs) do
76 79 copiers[#copiers+1] = quote [cpypos] = lib.mem.cpy([cpypos], [&opaque]([seg]), [#seg]) end
77 80 senders[#senders+1] = quote lib.net.mg_send([destcon], [seg], [#seg]) end
81 + appenders[#appenders+1] = quote [accumulator]:push([seg], [#seg]) end
78 82 if fields[idx] then
79 83 copiers[#copiers+1] = quote
80 84 [cpypos] = lib.mem.cpy([cpypos],
81 85 [&opaque](symself.[fields[idx]]),
82 86 lib.str.sz(symself.[fields[idx]]))
83 87 end
84 88 senders[#senders+1] = quote
................................................................................
94 98 lib.dbg(['compiling template ' .. tid])
95 99 [tallyup]
96 100 var [symtxt] = lib.mem.heapa(int8, [runningtally])
97 101 var [cpypos] = [&opaque](symtxt.ptr)
98 102 [copiers]
99 103 @[&int8](cpypos) = 0
100 104 return symtxt
105 + end
106 + rec.methods.append = terra([symself], [accumulator])
107 + lib.dbg(['appending template ' .. tid])
108 + [tallyup]
109 + accumulator:cue([runningtally])
110 + [appenders]
111 + return accumulator
101 112 end
102 113 rec.methods.send = terra([symself], [destcon], code: uint16, hd: lib.mem.ptr(lib.http.header))
103 114 lib.dbg(['transmitting template ' .. tid])
104 115 [tallyup]
105 116 lib.net.mg_printf([destcon], 'HTTP/1.1 %s', lib.http.codestr(code))
106 117 for i = 0, hd.ct do
107 118 lib.net.mg_printf([destcon], '%s: %s\r\n', hd.ptr[i].key, hd.ptr[i].value)