summaryrefslogtreecommitdiff
path: root/subplot
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2022-06-13 09:35:52 +0300
committerLars Wirzenius <liw@liw.fi>2022-06-24 11:12:07 +0300
commit796da8edcc2541a5343bdc53ae21e12c04419f52 (patch)
treefbb22a30082073774f8f6c90ac6e1bf0eb138a95 /subplot
parentf5fe497d7f55b31d47be59771649c2019b0265a2 (diff)
downloadriki-796da8edcc2541a5343bdc53ae21e12c04419f52.tar.gz
feat: rudimentary HTML generation
This handles paragraphs and h1 headings, for now. More to come later. There's also some testing. Sponsored-by: author
Diffstat (limited to 'subplot')
-rw-r--r--subplot/rikiwiki.rs77
-rw-r--r--subplot/rikiwiki.yaml9
2 files changed, 86 insertions, 0 deletions
diff --git a/subplot/rikiwiki.rs b/subplot/rikiwiki.rs
new file mode 100644
index 0000000..3b73393
--- /dev/null
+++ b/subplot/rikiwiki.rs
@@ -0,0 +1,77 @@
+use pandoc_ast::Pandoc;
+use std::path::Path;
+use subplotlib::steplibrary::runcmd::Runcmd;
+use subplotlib::steplibrary::datadir::Datadir;
+
+#[step]
+#[context(Runcmd)]
+fn install_rikiwiki(context: &ScenarioContext) {
+ // The RIKIWIKI_DIR variable can be set to test an installed
+ // rikiwiki rather than the one built from the source tree.
+ if let Some(bindir) = std::env::var_os("RIKIWIKI_DIR") {
+ println!("Found RIKIWIKI_DIR environment variable, using that");
+ context.with_mut(
+ |rc: &mut Runcmd| {
+ rc.prepend_to_path(bindir);
+ Ok(())
+ },
+ false,
+ )?;
+ } else {
+ let target_exe = env!("CARGO_BIN_EXE_rikiwiki");
+ let target_path = Path::new(target_exe);
+ let target_path = target_path.parent().ok_or("No parent?")?;
+
+ context.with_mut(
+ |context: &mut Runcmd| {
+ context.prepend_to_path(target_path);
+ Ok(())
+ },
+ false,
+ )?;
+ }
+}
+
+#[step]
+#[context(Datadir)]
+fn asts_match(context: &Datadir, first: &str, second: &str) {
+ let first = context.canonicalise_filename(first).unwrap();
+ let second = context.canonicalise_filename(second).unwrap();
+ println!("ast_match on {} and {}", first.display(), second.display());
+ let first = ast(first);
+ let second = ast(second);
+ println!();
+ println!("first: {:?}", first);
+ println!("second: {:?}", second);
+ assert!(first == second);
+}
+
+fn ast<P: AsRef<Path>>(filename: P) -> Pandoc {
+ let filename = filename.as_ref();
+ println!("ast on {} (is_file: {})", filename.display(), filename.is_file());
+ println!("cwd={:?}", std::env::current_dir());
+ let dir = filename.parent().unwrap();
+ println!("dir={} (exists: {})", dir.display(), dir.exists());
+ println!("filename={} (is_file: {})", filename.display(), filename.is_file());
+ for x in dir.read_dir().unwrap() {
+ println!("- {}", x.unwrap().path().display());
+ }
+ println!("that's all folks");
+ assert!(filename.exists());
+
+ let mut pandoc = pandoc::new();
+ pandoc.add_input(&filename);
+ pandoc.set_output_format(pandoc::OutputFormat::Json, vec![]);
+ pandoc.set_output(pandoc::OutputKind::Pipe);
+ let pandoc = pandoc.execute().unwrap();
+ println!("exexuted pandoc");
+ let json = match pandoc {
+ pandoc::PandocOutput::ToFile(x) => panic!("to file: {:?}", x),
+ pandoc::PandocOutput::ToBuffer(x) => x,
+ pandoc::PandocOutput::ToBufferRaw(x) => panic!("to raw buffer: {:?}", x),
+ };
+ println!("got JSON: {:.20?}", json);
+ let json = serde_json::from_str(&json).unwrap();
+ println!("JSON: {:?}", json);
+ json
+}
diff --git a/subplot/rikiwiki.yaml b/subplot/rikiwiki.yaml
new file mode 100644
index 0000000..15181af
--- /dev/null
+++ b/subplot/rikiwiki.yaml
@@ -0,0 +1,9 @@
+- given: "an installed rikiwiki"
+ impl:
+ rust:
+ function: install_rikiwiki
+
+- then: "AST of {first} matches that of {second}"
+ impl:
+ rust:
+ function: asts_match