aboutsummaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
authorStanisław Zagórowski <hasohasacz@gmail.com>2024-01-11 15:29:25 +0100
committerStanisław Zagórowski <hasohasacz@gmail.com>2024-01-11 15:29:25 +0100
commit8d9e00edacbc061ec5efba100e2af71be6824af8 (patch)
tree3f03f5a11a3a4e1ee804bc4b55e29a867a9db563 /src/main.rs
parent343bcfdfaaba32b7a46e1a945a4538e72d166ea8 (diff)
luax
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs24
1 files changed, 16 insertions, 8 deletions
diff --git a/src/main.rs b/src/main.rs
index f0683ae..466ffbc 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -19,6 +19,7 @@ fn table_to_html<W: std::io::Write>(table: rlua::Table, f: &mut W) -> Result<()>
write!(f, "<{}", type_name)?;
let mut children = None;
+ let mut attrs = None;
for pair in table.pairs::<String, rlua::Value>() {
let (key, value) = pair?;
if key == "tag" {
@@ -28,13 +29,19 @@ fn table_to_html<W: std::io::Write>(table: rlua::Table, f: &mut W) -> Result<()>
children = Some(value);
continue;
}
- match value {
- rlua::Value::Nil => write!(f, " {}=\"\"", key)?,
- rlua::Value::Boolean(b) => write!(f, " {}=\"{}\"", key, b)?,
- rlua::Value::Integer(i) => write!(f, " {}=\"{}\"", key, i)?,
- rlua::Value::Number(n) => write!(f, " {}=\"{}\"", key, n)?,
- rlua::Value::String(s) => write!(f, " {}=\"{}\"", key, s.to_str()?)?,
- _ => return Err(ReluaxError::LuaX(LuaXError::WrongFieldType(key)).into()),
+ if key == "attrs" {
+ attrs = Some(value);
+ continue;
+ }
+ }
+ if let Some(attrs) = attrs {
+ if let rlua::Value::Table(attrs) = attrs {
+ for pair in attrs.pairs::<String, rlua::String>() {
+ let (key, value) = pair?;
+ write!(f, " {}=\"{}\"", key, value.to_str()?)?;
+ }
+ } else {
+ return Err(ReluaxError::LuaX(LuaXError::NonTableAttrs).into());
}
}
write!(f, ">")?;
@@ -93,7 +100,8 @@ async fn main() -> color_eyre::Result<()> {
return Err(std::io::Error::new(
std::io::ErrorKind::NotFound,
format!("{} is not a file", entry.display()),
- ).into());
+ )
+ .into());
}
server::Server::serve(args.port).await?;