Browse Source

initial exploration

Getty Ritter 3 years ago
commit
2985a770cf
6 changed files with 180 additions and 0 deletions
  1. 1 0
      .gitignore
  2. 110 0
      Cargo.lock
  3. 11 0
      Cargo.toml
  4. 1 0
      example/simple/source.md
  5. 5 0
      example/simple/vdg.lua
  6. 52 0
      src/main.rs

+ 1 - 0
.gitignore

@@ -0,0 +1 @@
+/target

+ 110 - 0
Cargo.lock

@@ -0,0 +1,110 @@
+# This file is automatically @generated by Cargo.
+# It is not intended for manual editing.
+[[package]]
+name = "autocfg"
+version = "1.0.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a"
+
+[[package]]
+name = "bitflags"
+version = "1.2.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693"
+
+[[package]]
+name = "bstr"
+version = "0.2.15"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a40b47ad93e1a5404e6c18dec46b628214fee441c70f4ab5d6942142cc268a3d"
+dependencies = [
+ "memchr",
+]
+
+[[package]]
+name = "cc"
+version = "1.0.66"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "4c0496836a84f8d0495758516b8621a622beb77c0fed418570e50764093ced48"
+
+[[package]]
+name = "cfg-if"
+version = "1.0.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
+
+[[package]]
+name = "libc"
+version = "0.2.86"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "b7282d924be3275cec7f6756ff4121987bc6481325397dde6ba3e7802b1a8b1c"
+
+[[package]]
+name = "log"
+version = "0.3.9"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "e19e8d5c34a3e0e2223db8e060f9e8264aeeb5c5fc64a4ee9965c062211c024b"
+dependencies = [
+ "log 0.4.14",
+]
+
+[[package]]
+name = "log"
+version = "0.4.14"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "51b9bbe6c47d51fc3e1a9b945965946b4c44142ab8792c50835a980d362c2710"
+dependencies = [
+ "cfg-if",
+]
+
+[[package]]
+name = "memchr"
+version = "2.3.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "0ee1c47aaa256ecabcaea351eae4a9b01ef39ed810004e298d2511ed284b1525"
+
+[[package]]
+name = "mustache"
+version = "0.9.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "51956ef1c5d20a1384524d91e616fb44dfc7d8f249bf696d49c97dd3289ecab5"
+dependencies = [
+ "log 0.3.9",
+ "serde",
+]
+
+[[package]]
+name = "num-traits"
+version = "0.2.14"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "9a64b1ec5cda2586e284722486d802acf1f7dbdc623e2bfc57e65ca1cd099290"
+dependencies = [
+ "autocfg",
+]
+
+[[package]]
+name = "rlua"
+version = "0.17.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "25fa5b2c667bae0b6218361e96d365e414fe4a0fa80f476b9631aa2dea2c6881"
+dependencies = [
+ "bitflags",
+ "bstr",
+ "cc",
+ "libc",
+ "num-traits",
+]
+
+[[package]]
+name = "serde"
+version = "1.0.123"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "92d5161132722baa40d802cc70b15262b98258453e85e5d1d365c757c73869ae"
+
+[[package]]
+name = "van-de-graaf"
+version = "0.1.0"
+dependencies = [
+ "mustache",
+ "rlua",
+]

+ 11 - 0
Cargo.toml

@@ -0,0 +1,11 @@
+[package]
+name = "van-de-graaf"
+version = "0.1.0"
+authors = ["Getty Ritter <samothes@infinitenegativeutility.com>"]
+edition = "2018"
+
+# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
+
+[dependencies]
+rlua = "*"
+mustache = "*"

+ 1 - 0
example/simple/source.md

@@ -0,0 +1 @@
+Hello, **world**!

+ 5 - 0
example/simple/vdg.lua

@@ -0,0 +1,5 @@
+config {
+   template_dir = "."
+}
+
+out["index.html"] = template("main.mustache", {content = markdown("source.md")})

+ 52 - 0
src/main.rs

@@ -0,0 +1,52 @@
+use std::collections::BTreeMap;
+
+struct VDG {
+    template_dir: Option<String>,
+}
+
+pub struct Config {
+    lua: rlua::Lua,
+}
+
+impl Config {
+    fn new() -> Config {
+        let cfg = Config { lua: rlua::Lua::new() };
+        cfg.lua.context(|ctx| {
+            if let Err(msg) = Config::setup(&ctx) {
+                eprintln!("Error setting up context: {:?}", msg);
+            }
+        });
+        cfg
+    }
+
+    fn setup(ctx: &rlua::Context) -> Result<(), rlua::Error> {
+        ctx.globals().set("out", ctx.create_table()?)?;
+        ctx.globals().set("template", ctx.create_function(|_ctx, (path, params): (String, BTreeMap<String, String>)| {
+            println!("template of {} and {:?}!", path, params);
+            Ok(())
+        })?)?;
+        ctx.globals().set("markdown", ctx.create_function(|_ctx, path: String| {
+            println!("markdown of {}!", path);
+            Ok(format!("markdown({})", path))
+        })?)?;
+        ctx.globals().set("config", ctx.create_function(|_ctx, params: BTreeMap<String, String>| {
+            println!("config of {:?}!", params);
+            Ok(())
+        })?)?;
+        Ok(())
+    }
+
+    fn load(&mut self, path: &str) -> VDG {
+        let buf = std::fs::read_to_string(path).unwrap();
+        self.lua.context(|ctx| {
+            ctx.load(&buf).exec().unwrap();
+        });
+        VDG {
+            template_dir: None,
+        }
+    }
+}
+
+fn main() {
+    Config::new().load("example/simple/vdg.lua");
+}