Skip to content

Commit d0d19f4

Browse files
committed
Version 1.1 with minor changes (no need to update from 1.0).
1 parent 6eb3c2a commit d0d19f4

File tree

3 files changed

+38
-12
lines changed

3 files changed

+38
-12
lines changed

CHANGES

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
2+
Changes with lua-resty-template 1.1 10 Sep 2014
3+
4+
*) Feature: Added _VERSION information to the module.
5+
6+
*) Change: Lua > 5.1 uses _ENV instead of _G (Lua 5.1 uses _G).
7+
Future Proofing if Lua is deprecating _G in Lua 5.3.
8+
9+
*) Feature: Added CHANGES file to the project (this file).
10+
11+
12+
Changes with lua-resty-template 1.0 28 Aug 2014
13+
14+
*) Feature: LuaRocks Support via MoonRocks.

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ template.render([[
6767
* [FAQ](#faq)
6868
* [Alternatives](#alternatives)
6969
* [Benchmarks](#benchmarks)
70+
* [Changes](#changes)
7071
* [License](#license)
7172

7273
## Template Syntax
@@ -818,6 +819,10 @@ Compilation Time: 0.000077 (template cached)
818819

819820
I have not yet compared the results against the alternatives.
820821

822+
## Changes
823+
824+
The changes of every release of this module is recorded in [CHANGES](https://github.com/bungle/lua-resty-template/blob/master/CHANGES) file.
825+
821826
## License
822827

823828
`lua-resty-template` uses three clause BSD license (because it was originally forked from one that uses it).

lib/resty/template.lua

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ local CODE_ENTITIES = {
2222
}
2323

2424
local caching, ngx_var, ngx_capture, ngx_null = true
25-
local template = { cache = {}, concat = concat }
25+
local template = { _VERSION = "1.1", cache = {}, concat = concat }
2626

2727
local function read_file(path)
2828
local file = open(path, "rb")
@@ -58,21 +58,28 @@ else
5858
template.load = load_lua
5959
end
6060

61-
local context = setmetatable({ context = {}, blocks = {}, template = template }, {
62-
__index = function(t, k)
63-
return t.context[k] or t.template[k] or _G[k]
64-
end
65-
})
66-
61+
local context = { context = {}, blocks = {}, template = template }
6762
local load_chunk
6863

69-
if _VERSION == "Lua 5.1" and type(jit) ~= "table" then
70-
load_chunk = function(view)
71-
local func = assert(loadstring(view))
72-
setfenv(func, context)
73-
return func
64+
if _VERSION == "Lua 5.1" then
65+
setmetatable(context, { __index = function(t, k)
66+
return t.context[k] or t.template[k] or _G[k]
67+
end })
68+
if jit then
69+
load_chunk = function(view)
70+
return assert(load(view, nil, "tb", context))
71+
end
72+
else
73+
load_chunk = function(view)
74+
local func = assert(loadstring(view))
75+
setfenv(func, context)
76+
return func
77+
end
7478
end
7579
else
80+
setmetatable(context, { __index = function(t, k)
81+
return t.context[k] or t.template[k] or _ENV[k]
82+
end })
7683
load_chunk = function(view)
7784
return assert(load(view, nil, "tb", context))
7885
end

0 commit comments

Comments
 (0)