libify
This commit is contained in:
parent
2013b32f94
commit
3bfd3a4ad5
5 changed files with 20 additions and 55 deletions
12
Cargo.toml
12
Cargo.toml
|
@ -1,24 +1,22 @@
|
|||
[package]
|
||||
name = "stundenplaner"
|
||||
version = "0.1.0"
|
||||
edition = "2018"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[lib]
|
||||
crate-type = ["cdylib"]
|
||||
|
||||
[dependencies]
|
||||
anyhow = "1.0.44"
|
||||
structopt = "0.3.23"
|
||||
tera = "1.12.1"
|
||||
|
||||
[dependencies.minify-html]
|
||||
version = "0.8.0"
|
||||
features = ["js-esbuild"]
|
||||
|
||||
[dependencies.mlua]
|
||||
version = "0.7.3"
|
||||
features = ["luajit", "macros", "serialize"]
|
||||
features = ["luajit", "module", "macros", "serialize"]
|
||||
|
||||
[dependencies.serde]
|
||||
version = "1.0.130"
|
||||
features = ["derive"]
|
||||
|
||||
|
|
13
src/lib.rs
Normal file
13
src/lib.rs
Normal file
|
@ -0,0 +1,13 @@
|
|||
use mlua::prelude::*;
|
||||
|
||||
mod renderer;
|
||||
mod script;
|
||||
|
||||
#[mlua::lua_module]
|
||||
fn stundenplaner(lua: &Lua) -> LuaResult<LuaTable> {
|
||||
let exports = lua.create_table()?;
|
||||
|
||||
exports.set("render", lua.create_function(script::lua_render)?)?;
|
||||
|
||||
Ok(exports)
|
||||
}
|
18
src/main.rs
18
src/main.rs
|
@ -1,18 +0,0 @@
|
|||
use std::path::PathBuf;
|
||||
use structopt::StructOpt;
|
||||
|
||||
mod renderer;
|
||||
mod script;
|
||||
|
||||
#[derive(StructOpt)]
|
||||
struct Opt {
|
||||
infile: PathBuf,
|
||||
}
|
||||
|
||||
fn main() -> anyhow::Result<()> {
|
||||
let opt = Opt::from_args();
|
||||
|
||||
script::run_buildscript(opt.infile)?;
|
||||
|
||||
Ok(())
|
||||
}
|
|
@ -36,21 +36,7 @@ pub fn render(sdata: ScriptData) -> anyhow::Result<Vec<u8>> {
|
|||
)
|
||||
.context("failed to render template")?;
|
||||
|
||||
Ok(minify_html::minify(
|
||||
rendered.as_bytes(),
|
||||
&minify_html::Cfg {
|
||||
do_not_minify_doctype: true,
|
||||
ensure_spec_compliant_unquoted_attribute_values: false,
|
||||
keep_closing_tags: true,
|
||||
keep_html_and_head_opening_tags: true,
|
||||
keep_spaces_between_attributes: true,
|
||||
keep_comments: false,
|
||||
minify_css: true,
|
||||
minify_js: true,
|
||||
remove_bangs: true,
|
||||
remove_processing_instructions: false,
|
||||
},
|
||||
))
|
||||
Ok(rendered.into_bytes())
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize)]
|
||||
|
|
|
@ -4,21 +4,7 @@ use std::{fs, path::PathBuf, sync::Arc};
|
|||
|
||||
use crate::renderer;
|
||||
|
||||
pub fn run_buildscript(infile: PathBuf) -> anyhow::Result<()> {
|
||||
let script = std::fs::read(infile)?;
|
||||
|
||||
// required to allow C lua libs
|
||||
let lua = unsafe { Lua::unsafe_new() };
|
||||
|
||||
lua.globals()
|
||||
.set("render", lua.create_function(lua_render)?)?;
|
||||
|
||||
lua.load(&script).exec()?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn lua_render<'lua>(lua: &'lua Lua, args: Table<'lua>) -> Result<(), mlua::Error> {
|
||||
pub fn lua_render<'lua>(lua: &'lua Lua, args: Table<'lua>) -> Result<(), mlua::Error> {
|
||||
let args =
|
||||
lua.from_value_with::<ScriptData>(Value::Table(args), DeserializeOptions::default())?;
|
||||
let path = args.outfile.clone();
|
||||
|
|
Loading…
Reference in a new issue