]> git.nbdom.net Git - nb.git/commitdiff
lib/lua/nb.lua
authorNicolas Boisselier <nicolas.boisselier@gmail.com>
Mon, 6 Aug 2018 18:59:31 +0000 (19:59 +0100)
committerNicolas Boisselier <nicolas.boisselier@gmail.com>
Mon, 6 Aug 2018 18:59:31 +0000 (19:59 +0100)
lib/lua/nb.lua

index 7bf304a458cba36893bb508246385fbc22fc9a5b..1cad64de153372e53450415c8ca303f6e8e2038b 100644 (file)
@@ -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)