docs: add a basic example Lua plugin
This commit is contained in:
parent
0a56365672
commit
e09a837569
1 changed files with 19 additions and 0 deletions
19
docs/example-lua-plugin/main.lua
Normal file
19
docs/example-lua-plugin/main.lua
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
-- 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
|
||||||
|
koushin.on_render("mailbox.html", function(data)
|
||||||
|
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
|
||||||
|
koushin.set_route("GET", "/example", function(ctx)
|
||||||
|
ctx:String(200, "This is an example page.")
|
||||||
|
end)
|
||||||
|
|
||||||
|
-- Set a filter function that can be used from templates
|
||||||
|
koushin.set_filter("example_and", function(a, b)
|
||||||
|
return a .. " and " .. b
|
||||||
|
end)
|
Loading…
Reference in a new issue