alps/docs/example-lua-plugin/main.lua

20 lines
658 B
Lua
Raw Normal View History

2020-02-11 16:56:15 +00:00
-- This message will be printed when the plugin is loaded
print("Hi, this is an example Lua plugin")
-- Setup a function called when the mailbox view is rendered
2020-05-13 12:07:44 +00:00
alps.on_render("mailbox.html", function(data)
2020-02-11 16:56:15 +00:00
print("The mailbox view for " .. data.Mailbox.Name .. " is being rendered")
-- Set extra data that can be accessed from the mailbox.html template
data.Extra.Example = "Hi from Lua"
end)
-- Wire up a new route
2020-05-13 12:07:44 +00:00
alps.set_route("GET", "/example", function(ctx)
2020-02-11 16:56:15 +00:00
ctx:String(200, "This is an example page.")
end)
-- Set a filter function that can be used from templates
2020-05-13 12:07:44 +00:00
alps.set_filter("example_and", function(a, b)
2020-02-11 16:56:15 +00:00
return a .. " and " .. b
end)