Start using addon api

This commit is contained in:
Robin Malley 2023-02-20 04:32:37 +00:00
parent 87bccb959d
commit 66b48f06a4
4 changed files with 20 additions and 11 deletions

View File

@ -17,9 +17,9 @@ function configure(...)
end
local oldspec = api.get.page_owner
function api.get.page_owner = function(env)
local ret = oldspec()
table.insert(oldret,{
api.get.page_owner = function(env)
local ret = oldspec(env)
table.insert(ret,{
endpoint = string.format("https://%s/_delete",env.domain),
method = "POST",
fields = {story = env.short},

View File

@ -18,9 +18,9 @@ function configure(...)
end
local oldspec = api.get.page_owner
function api.get.page_owner = function(env)
local ret = oldspec()
table.insert(oldret,{
api.get.page_owner = function(env)
local ret = oldspec(env)
table.insert(ret,{
endpoint = string.format("https://%s/_edit",env.domain),
method = "GET",
fields = {story = env.short},

View File

@ -26,9 +26,17 @@ for k,v in pairs(pagenames) do
local parser = et.Parser()
local f = assert(io.open(path,"r"))
local fdata = assert(f:read("*a"))
local code = assert(parser:parse(fdata))
local func = assert(parser:load(parser:chunks_to_lua(),path))
local e,code = assert(xpcall(function()
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()
assert(func, "Failed to load " .. path)
pages[v] = function(...)
local buf = assert(parser:run(func,...))
return table.concat(buf)

View File

@ -1,12 +1,13 @@
<{system cat src/pages/parts/header.etlua}>
<% local api = require("hooks") %>
<nav>
<a href="https://<%= domain %>"><%= domain %></a>/<a href="https://<%= domain %>/<%= short %>"><%= short %></a>
</nav>
<% if owner then -%>
<div class="row">
<% for _, spec in ipairs(api.get.page_owner(_ENV)) do %>
<form action="<%= spec.endpoint %>" method="<%= spec.method %=>"><fieldset>
<% for key, value in pairs(spec.fields) %>
<% for _, spec in ipairs(api.get.page_owner(getfenv(1))) do %>
<form action="<%= spec.endpoint %>" method="<%= spec.method %>"><fieldset>
<% for key, value in pairs(spec.fields) do %>
<input type="hidden" name="<%= key %>" value="<%= value %>"/>
<% end %>
<input type="submit" value="<%= spec.text %>" class="button column column-0"/>