-- Markdown includes
local ptn = '%{%(([^%(%)]+%.md)%)%}'
while true do
- local p1,p2,inc = content:find(ptn)
- if p1 == nil then break end
- local inc_content = self:readall(root .. '/' .. inc)
- if ishtml then
- inc_content = self:md2html(inc_content)
- inc_content = inc_content:gsub('^%s*<p>%s*',''):gsub('%s*</p>%s*$','')
- -- class = inc:gsub('/index%.[%w]+$',''):match('^.*/([^/%.%?&]+)')
- -- id = inc:gsub('/index%.[%w]+$','')
- local name = self:filepath2name(inc)
- if false then
- inc_content = '<div'
- .. ' id="inc-' .. name .. '"'
- .. ' class="' .. name .. '"'
- .. '>' .. inc_content .. '</div>'
- end
- end
- content = ''
- .. content:sub(0,p1-1)
- .. inc_content
- .. (content:sub(p2+1))
+ local p1,p2,inc = content:find(ptn)
+ if p1 == nil then break end
+ local inc_content = self:readall(root .. '/' .. inc)
+ if ishtml then
+ inc_content = self:md2html(inc_content)
+ inc_content = inc_content:gsub('^%s*<p>%s*',''):gsub('%s*</p>%s*$','')
+ -- class = inc:gsub('/index%.[%w]+$',''):match('^.*/([^/%.%?&]+)')
+ -- id = inc:gsub('/index%.[%w]+$','')
+ local name = self:filepath2name(inc)
+ if false then
+ inc_content = '<div'
+ .. ' id="inc-' .. name .. '"'
+ .. ' class="' .. name .. '"'
+ .. '>' .. inc_content .. '</div>'
+ end
+ end
+ content = ''
+ .. content:sub(0,p1-1)
+ .. inc_content
+ .. (content:sub(p2+1))
end
content = self:html_fix(content)
return content
end
+function nb:api(url,fmt)
+ local res = ngx.location.capture(url)
+ local rows = json.decode(res.body)
+
+ local fct
+
+ -- Function
+ if type(fmt) == "function" then
+ fct = fmt
+
+ -- Table
+ elseif 0
+ or fmt == "table"
+ or fmt == "table-th"
+ or fmt == "table-td"
+ then
+ fct = function(r,i)
+ if i == 1 and (fmt == "table" or fmt == "table-th") then
+ ngx.print('<tr>')
+ for k,v in pairs(r) do
+ ngx.print('<th class="' .. k .. '">' .. k .. '</th>')
+ end
+ ngx.print('</tr>')
+ end
+ ngx.print('<tr>')
+ for k,v in pairs(r) do
+ ngx.print('<td>' .. v .. '</td>')
+ end
+ ngx.print('<tr>\n')
+ end
+
+ -- Default
+ else
+ fct = function(r,i)
+ for k,v in pairs(r) do
+ ngx.print(string.format(fmt,v))
+ -- ngx.say(v)
+ end
+ end
+
+ end
+
+ -- Run
+ if fmt == "table" then ngx.print('<table>\n') end
+ for i,r in pairs(rows) do
+ fct(r,i)
+ end
+ if fmt == "table" then ngx.print('</table>\n') end
+end
+
return nb