From: Nicolas Boisselier Date: Mon, 6 Aug 2018 18:59:31 +0000 (+0100) Subject: lib/lua/nb.lua X-Git-Url: https://git.nbdom.net/?a=commitdiff_plain;h=b46047ca3c8fb30f8c3fb3de8d9146acbfc904c6;p=nb.git lib/lua/nb.lua --- diff --git a/lib/lua/nb.lua b/lib/lua/nb.lua index 7bf304a4..1cad64de 100644 --- a/lib/lua/nb.lua +++ b/lib/lua/nb.lua @@ -19,6 +19,25 @@ function nb:readall(file) end end +function nb:ngx_rows(url) + local json = require('json') + local rows = json.decode(ngx.location.capture(url).body) + + if not rows then rows = {} end + + local count = 0 for _,row in pairs(rows) do count = count+1 end + local langs = {} + local count = 0 for _,row in pairs(rows) do + local lang = rows.lang + --langs[lang] = rows.lang + end + + return { + data = rows, + count = count, + } +end + function nb:ngx_tmpl_file(file,fheader,ffooter) ngx.ctx.tmpl_content = self:readall(file) self:ngx_location_tmpl(fheader,ffooter)