aboutsummaryrefslogtreecommitdiff
path: root/src/get_routes.rs
diff options
context:
space:
mode:
authorMartin Fischer <martin@push-f.com>2022-07-30 20:17:25 +0200
committerMartin Fischer <martin@push-f.com>2022-07-30 22:21:23 +0200
commit56c071bb832304ba9a2ec67215b1a8ae40723840 (patch)
tree2282e1f0eafcf65e807f2e9120617401b705d75c /src/get_routes.rs
parenta920436c3af249266ff907d15755c1291737905a (diff)
implement lua scripting
Inspired by the Scribunto extension for MediaWiki.
Diffstat (limited to 'src/get_routes.rs')
-rw-r--r--src/get_routes.rs28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/get_routes.rs b/src/get_routes.rs
index 79b7cb5..5e65637 100644
--- a/src/get_routes.rs
+++ b/src/get_routes.rs
@@ -11,6 +11,7 @@ use hyper::http::request::Parts;
use serde::Deserialize;
use sputnik::html_escape;
use sputnik::request::SputnikParts;
+use std::fmt::Write;
use std::str::from_utf8;
use crate::action_links;
@@ -80,6 +81,33 @@ fn view_blob<C: Controller>(
match from_utf8(blob.content()) {
Ok(text) => {
+ #[cfg(feature = "lua")]
+ if let Some(script) = super::lua::parse_shebang(text) {
+ match script.run(&ctx) {
+ Ok(output) => {
+ write!(
+ page.body,
+ "<div>rendered with <a href='{}'>{}</a></div>",
+ html_escape(
+ controller.build_url_path(&ctx.branch, &script.module_path())
+ ),
+ html_escape(script.lua_module_name)
+ );
+ page.body.push_str(&output);
+ }
+ Err(err) => {
+ write!(
+ page.body,
+ "<div class=error><a href='{}'>{}</a>: {err}</div>",
+ html_escape(
+ controller.build_url_path(&ctx.branch, &script.module_path())
+ ),
+ html_escape(script.lua_module_name)
+ );
+ }
+ };
+ return Ok(page.into());
+ }
if let Some(renderer) = get_renderer(&ctx.path) {
renderer(text, &mut page, RenderMode::View);
} else {