{"id":21558335,"url":"https://github.com/doublespout/lua-resty-aries","last_synced_at":"2025-04-10T10:42:21.276Z","repository":{"id":141858061,"uuid":"85270761","full_name":"DoubleSpout/lua-resty-aries","owner":"DoubleSpout","description":"openresty and lua multi-function template","archived":false,"fork":false,"pushed_at":"2017-04-12T06:42:13.000Z","size":53,"stargazers_count":47,"open_issues_count":0,"forks_count":5,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-04-12T04:04:13.665Z","etag":null,"topics":["html","lua","luajit","openresty","resty","template","template-engine","templates","tpl"],"latest_commit_sha":null,"homepage":null,"language":"Lua","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/DoubleSpout.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2017-03-17T04:26:24.000Z","updated_at":"2021-12-27T03:40:38.000Z","dependencies_parsed_at":"2024-01-13T09:36:00.362Z","dependency_job_id":"75bb402a-4d58-4da1-af94-2698d90da48c","html_url":"https://github.com/DoubleSpout/lua-resty-aries","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DoubleSpout%2Flua-resty-aries","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DoubleSpout%2Flua-resty-aries/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DoubleSpout%2Flua-resty-aries/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DoubleSpout%2Flua-resty-aries/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/DoubleSpout","download_url":"https://codeload.github.com/DoubleSpout/lua-resty-aries/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248199580,"owners_count":21063712,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["html","lua","luajit","openresty","resty","template","template-engine","templates","tpl"],"created_at":"2024-11-24T08:14:35.232Z","updated_at":"2025-04-10T10:42:21.252Z","avatar_url":"https://github.com/DoubleSpout.png","language":"Lua","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n# lua-resty-aries \n\n**openresty and lua multi-function template, it can correct show your error line.**\n\n[![Licence](http://img.shields.io/badge/Licence-MIT-brightgreen.svg)](LICENSE)\n[![Build Status](https://travis-ci.org/DoubleSpout/lua-resty-aries.svg?branch=master)](https://travis-ci.org/DoubleSpout/lua-resty-aries)\n[![Coverage Status](https://coveralls.io/repos/github/DoubleSpout/lua-resty-aries/badge.svg)](https://coveralls.io/github/DoubleSpout/lua-resty-aries)\n\nYou can use `lua-resty-aries` to render template and safety run lua code string.The template or code string can be from any kind of data source, such as: file, redis, mysql or mongodb, any you like. And `lua-resty-aries` can correct postion your template's error line.\n\n**support openresty1.0.6+, lua5.1+**\n\nlua-resty-aries support linux/ubantu, windows and mac.\n\nyou need install lua/luajit first [http://www.lua.org/](http://www.lua.org/ \"Lua\")\n\n## Install\n\nwith luarocks\n\n\tluarocks install lua-resty-aries\n\n## Get Started\n\n\tlocal Aries = require(\"resty.aries\")\n    local aries1 = Aries:new()\n\n    local result, err = aries1:compile([=[ \n\t\t\t\u003c% hello = \"welcome to lua-resty-aries\" %\u003e\n\t\t\t\u003ch1\u003e\u003ccenter\u003e\u003c%= hello %\u003e\u003c/center\u003e\u003c/h1\u003e\n\t ]=])\n\n    print(result)\t-- \u003ch1\u003e\u003ccenter\u003e\u003c%= hello %\u003e\u003c/center\u003e\u003c/h1\u003e\n\t   \n## Using file template\n\nWe create` index.html` file at `{workdir}/tpl/index.html`\n\n\t\u003c!DOCTYPE html\u003e\n\t\u003chtml\u003e\n\t\u003chead\u003e\n\t\t\u003ctitle\u003e\u003c%= ctx.title %\u003e\u003c/title\u003e\n\t\u003c/head\u003e\n\t\u003cbody\u003e\n\t\t\u003c% hello = \"welcome to lua-resty-aries\" %\u003e\n\t\t\u003ch1\u003e\u003ccenter\u003e\u003c%= hello %\u003e\u003c/center\u003e\u003c/h1\u003e\n\t\u003c/body\u003e\n\t\u003c/html\u003e\n\nWe can render the template like this:\n\n\tlocal Aries = require(\"resty.aries\")\n    local aries1 = Aries:new()\n\n    local result, err = aries1:render(\"index\", {\n\t\ttitle=\"lua-resty-aries title\"\n\t})\n\n    print(result)\n\n## A littel complex example\n\nWe create tpl/index2.html like this\n\n\t\u003c!DOCTYPE html\u003e\n\t\u003chtml\u003e\n\t\u003chead\u003e\n\t\t\u003ctitle\u003e\u003c%= ctx.title %\u003e\u003c/title\u003e\n\t\u003c/head\u003e\n\t\u003cbody\u003e\n\t\t\u003c% hello = \"welcome to lua-resty-aries\" %\u003e\n\t\t\u003ch1\u003e\u003ccenter\u003e\u003c%= hello %\u003e\u003c/center\u003e\u003c/h1\u003e\n\t\t\u003c% if (ctx.loop or 0) \u003e 0 then %\u003e\n\t\t\t\u003c% for i=1,ctx.loop,1 do %\u003e\n\t\t\t\t\u003c% include inc/loop %\u003e\n\t\t\t\u003c% end %\u003e\n\t\t\u003c% else %\u003e\n\t\t\t\u003c% include inc/noloop %\u003e\n\t\t\u003c% end %\u003e\n\t\u003c/body\u003e\n\t\u003c/html\u003e\n\ncreate inc/noloop.html\n\n\t\u003ch1\u003ectx noloop\u003c/h1\u003e\n\tthis must be occur an error, undefined function \u003c% ctx.error() %\u003e\n\tctx.loop=\u003c%= ctx.loop %\u003e\n\ncreate inc/loop.html\n\n\t\u003ch1\u003ectx doloop\u003c/h1\u003e\n\tctx.loop=\u003c%= ctx.loop %\u003e\n\ncreate render code:\n\n\tlocal Aries = require(\"resty.aries\")\n    local aries1 = Aries:new()\n\n    local result, err = aries1:render(\"index2\", {\n\t\ttitle=\"lua-resty-aries title\",\n        loop=10,\t--change loop to control loop times\n\t})\n\n    print(result)\n\nif we change render code like this, this must be occur an error:\n\n\tlocal Aries = require(\"resty.aries\")\n    local aries1 = Aries:new()\n\n    local result, err = aries1:render(\"index2\", {\n\t\ttitle=\"lua-resty-aries title\",\n        loop=-1,\t--not loop make an errror\n\t})\n\n    print(err)\t-- index2.html: 14 \u003e\u003e inc/noloop.html: 2 have error  attempt to call field 'error' (a nil value)\n\nwe can get error msg, correct to postion the error line, even it at include template:\n\n\tindex2.html: 14 \u003e\u003e inc/noloop.html: 2 have error  attempt to call field 'error' (a nil value)\n\n## Aries Constructor and Instance\n   \n`Aries` Constructor method. Every time, you call `Aries:new(opt)` will return a new `Aries instance`.\n\n\tlocal Aries = require(\"resty.aries\")\n\tlocal ariesInstance = Aries:new(opt)\n\n`opt` all attribute, all of these attributes are `option`:\n\n\t-- below is the default value\n\topt = {\n\t\t-- custom left half tag\n\t\tstartTag = \"\u003c%\",\n\n\t\t-- custom right half tag\n\t\tendTag = \"%\u003e\",\n\n\t\t-- custom the template file's suffix \n\t\tfileSuffix = \"html\",\n\n\t\t-- change root of template folder path\n\t\trootPath = \"./tpl\",\n\n\t\t-- works fine at linux and windows\n\t\tsep = \"/\",\n\n\t\t-- if occur error, show the error line and msg, this must set off in production to increase performance\n\t\tisShowDetailError = true,  \n\n\t\t-- tpl parse cache,default is true, \n\t\tcache = true,\n\n\t\t-- tpl parse cache time, default expire 30min, unit second\n\t\tcacheTime = 1800,\n\n\t\t-- template render timeout, unit second\n\t\t-- default not timeout\n\t\ttimeout = -1,\n\n\t\t-- instance level object to put to template\n\t\tctx = {},\n\n\t\t-- change template data source, you can get template from redis or other data source.\n\t\t-- default is from file system\n\t\tgetInclude = function(self, includeName)\n\t\t\t\t\t\t-- simple example get template from redis\n\t\t\t\t\t\t-- local data, err = redis_conn:get(includeName)\n\t\t\t\t\t\t-- return data == ngx.null and \"\" or data\n\t\t\t\t\t\treturn self.readfile(string.format(\"%s%s%s.%s\", self.rootPath, self.sep, includeName, self.fileSuffix))\n\t\t\t\t\tend,\n\n\t\t-- before return string ,you can minify the html or xml string\n\t\t-- default do nothing\n\t\tminify = function(self, renderStr)\n\t\t\t\t\t\treturn renderStr\n\t\t\t\tend,\n\n\t}\n\n`Aries Instance` Method\n\n\t-- get all the include template name by name\n\tlocal includeNameTable, err = ariesInstance:getIncludesByName(tplName string)\n\n\t-- get all the include template name by string code\n\tlocal includeNameTable, err = ariesInstance:getIncludesByContent(tplName string)\n\n\t-- render a template by name\n\t-- here ctx inherit the ariesInstance.ctx\n\tlocal renderStr, err = ariesInstance:render(tplName string, [ctx table])\n\n\t-- render a template by string code\n\t-- here ctx inherit the ariesInstance.ctx\n\tlocal renderStr, err = ariesInstance:compile(tplName string, [ctx table, tplName string])\n\n\n\t\n## Template API (using at template)\n\t\nWe can use `include {templateName}` to include other template, `lua-resty-aries` will call `ariesInstance:getInclude({templateName})` everytime.(include first we call `ariesInstance:render({templateName})`). example:\n\n\t\u003c% include inc/header %\u003e\t-- notice,default not to add file suffix\n\nprint on template example:\n\t\n\t-- will show hello world \u0026lt; \u0026gt; \u0026quot; \u0026apos;\n\t\u003c%= string.format(\"hello world %s %s %s %s\", \"\u003c\", \"\u003e\", '\"', \"'\") %\u003e\n\t\n\t-- will show hello world \u003c \u003e \" '\n\t\u003c%= string.format(\"hello world %s %s %s %s\", \"\u003c\", \"\u003e\", '\"', \"'\") %\u003e\n\n`ctx` table on template:\n\n\t-- like \u003c%= {str} %\u003e\n\tctx.print(str string)\n\n \t-- like \u003c%- {str} %\u003e \n\tctx.rawPrint(str string)\n\n\t-- lock some ctx attribute, before excute ctx.unlock({field}), you can't change such {field} value\n\t-- example:\n\t-- ctx.a = 1\n\t-- ctx.lock(a)\n\t-- ctx.a = 2 -- occur error\n\tctx.lock({field})\n\n\n\t-- unlock field\n\t-- example\n\t-- ctx.a = 1\n\t-- ctx.lock(a)\n\t-- ctx.unlock(a)\n\t-- ctx.a = 2 -- ok\n\tctx.unlock({field})\n\t\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdoublespout%2Flua-resty-aries","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdoublespout%2Flua-resty-aries","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdoublespout%2Flua-resty-aries/lists"}