Start using addon api
This commit is contained in:
parent
87bccb959d
commit
66b48f06a4
|
@ -17,9 +17,9 @@ function configure(...)
|
||||||
end
|
end
|
||||||
|
|
||||||
local oldspec = api.get.page_owner
|
local oldspec = api.get.page_owner
|
||||||
function api.get.page_owner = function(env)
|
api.get.page_owner = function(env)
|
||||||
local ret = oldspec()
|
local ret = oldspec(env)
|
||||||
table.insert(oldret,{
|
table.insert(ret,{
|
||||||
endpoint = string.format("https://%s/_delete",env.domain),
|
endpoint = string.format("https://%s/_delete",env.domain),
|
||||||
method = "POST",
|
method = "POST",
|
||||||
fields = {story = env.short},
|
fields = {story = env.short},
|
||||||
|
|
|
@ -18,9 +18,9 @@ function configure(...)
|
||||||
end
|
end
|
||||||
|
|
||||||
local oldspec = api.get.page_owner
|
local oldspec = api.get.page_owner
|
||||||
function api.get.page_owner = function(env)
|
api.get.page_owner = function(env)
|
||||||
local ret = oldspec()
|
local ret = oldspec(env)
|
||||||
table.insert(oldret,{
|
table.insert(ret,{
|
||||||
endpoint = string.format("https://%s/_edit",env.domain),
|
endpoint = string.format("https://%s/_edit",env.domain),
|
||||||
method = "GET",
|
method = "GET",
|
||||||
fields = {story = env.short},
|
fields = {story = env.short},
|
||||||
|
|
|
@ -26,9 +26,17 @@ for k,v in pairs(pagenames) do
|
||||||
local parser = et.Parser()
|
local parser = et.Parser()
|
||||||
local f = assert(io.open(path,"r"))
|
local f = assert(io.open(path,"r"))
|
||||||
local fdata = assert(f:read("*a"))
|
local fdata = assert(f:read("*a"))
|
||||||
local code = assert(parser:parse(fdata))
|
local e,code = assert(xpcall(function()
|
||||||
local func = assert(parser:load(parser:chunks_to_lua(),path))
|
return parser:compile_to_lua(fdata)
|
||||||
|
end,function(err)
|
||||||
|
return debug.traceback(string.format("Failed to parse %s: %s",path, err))
|
||||||
|
end))
|
||||||
|
local func, err = parser:load(code)
|
||||||
|
if not func then
|
||||||
|
error(string.format("Failed to load %s: %s",path, err))
|
||||||
|
end
|
||||||
f:close()
|
f:close()
|
||||||
|
assert(func, "Failed to load " .. path)
|
||||||
pages[v] = function(...)
|
pages[v] = function(...)
|
||||||
local buf = assert(parser:run(func,...))
|
local buf = assert(parser:run(func,...))
|
||||||
return table.concat(buf)
|
return table.concat(buf)
|
||||||
|
|
|
@ -1,12 +1,13 @@
|
||||||
<{system cat src/pages/parts/header.etlua}>
|
<{system cat src/pages/parts/header.etlua}>
|
||||||
|
<% local api = require("hooks") %>
|
||||||
<nav>
|
<nav>
|
||||||
<a href="https://<%= domain %>"><%= domain %></a>/<a href="https://<%= domain %>/<%= short %>"><%= short %></a>
|
<a href="https://<%= domain %>"><%= domain %></a>/<a href="https://<%= domain %>/<%= short %>"><%= short %></a>
|
||||||
</nav>
|
</nav>
|
||||||
<% if owner then -%>
|
<% if owner then -%>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<% for _, spec in ipairs(api.get.page_owner(_ENV)) do %>
|
<% for _, spec in ipairs(api.get.page_owner(getfenv(1))) do %>
|
||||||
<form action="<%= spec.endpoint %>" method="<%= spec.method %=>"><fieldset>
|
<form action="<%= spec.endpoint %>" method="<%= spec.method %>"><fieldset>
|
||||||
<% for key, value in pairs(spec.fields) %>
|
<% for key, value in pairs(spec.fields) do %>
|
||||||
<input type="hidden" name="<%= key %>" value="<%= value %>"/>
|
<input type="hidden" name="<%= key %>" value="<%= value %>"/>
|
||||||
<% end %>
|
<% end %>
|
||||||
<input type="submit" value="<%= spec.text %>" class="button column column-0"/>
|
<input type="submit" value="<%= spec.text %>" class="button column column-0"/>
|
||||||
|
|
Loading…
Reference in New Issue