From b46047ca3c8fb30f8c3fb3de8d9146acbfc904c6 Mon Sep 17 00:00:00 2001 From: Nicolas Boisselier Date: Mon, 6 Aug 2018 19:59:31 +0100 Subject: [PATCH] lib/lua/nb.lua --- lib/lua/nb.lua | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) 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) -- 2.47.3