From b8cf943fb17a750aaf9f567fb97e7392d9cfb455 Mon Sep 17 00:00:00 2001 From: EuAndreh Date: Sun, 30 May 2021 19:40:02 -0300 Subject: WIP init Rust --- .gitignore | 1 + Cargo.lock | 50 ++++++++++++++++++++++++++++ Cargo.toml | 14 ++++++++ TODOs.md | 16 +++++++-- etc/gistatic/templates/html/commit.tmpl | 0 etc/gistatic/templates/html/head.html.tmpl | 12 ------- etc/gistatic/templates/html/header.html.tmpl | 46 ------------------------- etc/gistatic/templates/html/log.html.tmpl | 34 ------------------- src/cli/main.rs | 4 +++ src/lib/lib.rs | 19 +++++++++++ src/templates/commit.html | 0 src/templates/head.html | 12 +++++++ src/templates/header.html | 46 +++++++++++++++++++++++++ src/templates/log.html | 34 +++++++++++++++++++ 14 files changed, 193 insertions(+), 95 deletions(-) create mode 100644 Cargo.lock create mode 100644 Cargo.toml delete mode 100644 etc/gistatic/templates/html/commit.tmpl delete mode 100644 etc/gistatic/templates/html/head.html.tmpl delete mode 100644 etc/gistatic/templates/html/header.html.tmpl delete mode 100644 etc/gistatic/templates/html/log.html.tmpl create mode 100644 src/cli/main.rs create mode 100644 src/lib/lib.rs create mode 100644 src/templates/commit.html create mode 100644 src/templates/head.html create mode 100644 src/templates/header.html create mode 100644 src/templates/log.html diff --git a/.gitignore b/.gitignore index 87174b6..81df051 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ /public/ +/target/ diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..77103a3 --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,50 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "gistatic" +version = "0.1.0" +dependencies = [ + "mustache", +] + +[[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 = "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 = "serde" +version = "1.0.126" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec7505abeacaec74ae4778d9d9328fe5a5d04253220a85c4ee022239fc996d03" diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..bc5875a --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "gistatic" +version = "0.1.0" +edition = "2018" + +[lib] +path = "src/lib/lib.rs" + +[[bin]] +name = "gistatic" +path = "src/cli/main.rs" + +[dependencies] +mustache = "*" diff --git a/TODOs.md b/TODOs.md index ae05dc6..21dda0a 100644 --- a/TODOs.md +++ b/TODOs.md @@ -7,7 +7,7 @@ - [ ] hierarquical tree view, per branch and per commit - [ ] show notes in commit -- [ ] `tarballs/` folder, with `.tar.gz`, `.tar.gz.sha256` and `.tar.gz.sig` files +- [ ] `tarballs/` folder, with `.tar.xz` and `.tar.xz.asc` files - [ ] generate tarballs for all tags and all branches - [ ] SHA in log - [ ] `.patch` files (with `git format-patch --stdout -1 $SHA`), raw view @@ -33,12 +33,22 @@ Benchmark on (stagit): # Decisions -## TODO Perl vs C {#decision-d349b5be-3e00-4e00-a110-0eb7f402d4ab} +## DONE Perl vs C {#decision-d349b5be-3e00-4e00-a110-0eb7f402d4ab} +- DONE in 2021-05-28 - TODO in 2021-03-06 --- -FIXME +Instead of Perl vs C, it became Perl vs Rust, and I've chosen Rust. + +I choose Rust over C because it is a higher-level language than C is. +It allows me to produce binaries and libraries without extra dependencies (unlike C++'s `libstdc++`), and I can deal with memory management without reference counting (unlike Nim) or garbage collection (unlike D). + +I'm favoring Rust as a C-like tool because it allows me to write code that transcends the language barries: with C/Rust code, a `.so` library can be consumed by any programming language on any environment. +The binary application that will be the CLI could be written in any language, also, but it is done so in Rust for convenience. + +So the question of Perl vs C now is becoming applicable only on more specific scenarios: when having a `libsomething.so` isn't worth anything. +This isn't the case for this library. # Resources diff --git a/etc/gistatic/templates/html/commit.tmpl b/etc/gistatic/templates/html/commit.tmpl deleted file mode 100644 index e69de29..0000000 diff --git a/etc/gistatic/templates/html/head.html.tmpl b/etc/gistatic/templates/html/head.html.tmpl deleted file mode 100644 index 7f036d5..0000000 --- a/etc/gistatic/templates/html/head.html.tmpl +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - - - Log - {{ name }} - {{ description }} - - - diff --git a/etc/gistatic/templates/html/header.html.tmpl b/etc/gistatic/templates/html/header.html.tmpl deleted file mode 100644 index bbad31a..0000000 --- a/etc/gistatic/templates/html/header.html.tmpl +++ /dev/null @@ -1,46 +0,0 @@ - - - - - - - - - - - - - -
- - Logo of the project {{ name }}. - - -

{{ name }}

- {{ description }} -
- - - git clone - - {{ clone-prefix }}/{{ name }} - -
- - - - summary - - | - - files - - | - - log - - | - - refs - -
diff --git a/etc/gistatic/templates/html/log.html.tmpl b/etc/gistatic/templates/html/log.html.tmpl deleted file mode 100644 index 7caa079..0000000 --- a/etc/gistatic/templates/html/log.html.tmpl +++ /dev/null @@ -1,34 +0,0 @@ - - - {{ > head.html.tmpl }} - - {{ > header.html.tmpl }} -
- -
- - - - - - - - - - - - - {{ #commits }} - - - - - - - - {{ /commits }} - -
DateCommit messageAuthorFilesLines
{{ date }}{{ message_title }}{{ author }}{{ files }}-{{ removed }}/+{{ added }}
-
- - diff --git a/src/cli/main.rs b/src/cli/main.rs new file mode 100644 index 0000000..cdb964d --- /dev/null +++ b/src/cli/main.rs @@ -0,0 +1,4 @@ +pub fn main() { + println!("Hello, World!"); + println!("a_fn(): {}", gistatic::a_fn()); +} diff --git a/src/lib/lib.rs b/src/lib/lib.rs new file mode 100644 index 0000000..311a11f --- /dev/null +++ b/src/lib/lib.rs @@ -0,0 +1,19 @@ +const t: &'static str = include_str!("../templates/log.html"); + +pub fn a_fn() -> i32 { + // println!("log.html.tmpl: {}", t); + let template = mustache::compile_str(t).unwrap(); + let _data = mustache::MapBuilder::new() + .insert_str("name", "Venus") + .build(); + + let mut d2 = std::collections::HashMap::new(); + d2.insert("a", "b"); + template.render(&mut std::io::stdout(), &d2). unwrap(); + + 0 +} + +#[test] +fn a_test() { +} diff --git a/src/templates/commit.html b/src/templates/commit.html new file mode 100644 index 0000000..e69de29 diff --git a/src/templates/head.html b/src/templates/head.html new file mode 100644 index 0000000..e6988ec --- /dev/null +++ b/src/templates/head.html @@ -0,0 +1,12 @@ + + + + + + + + + Log - {{ name }} - {{ description }} + + + diff --git a/src/templates/header.html b/src/templates/header.html new file mode 100644 index 0000000..bbad31a --- /dev/null +++ b/src/templates/header.html @@ -0,0 +1,46 @@ + + + + + + + + + + + + + +
+ + Logo of the project {{ name }}. + + +

{{ name }}

+ {{ description }} +
+ + + git clone + + {{ clone-prefix }}/{{ name }} + +
+ + + + summary + + | + + files + + | + + log + + | + + refs + +
diff --git a/src/templates/log.html b/src/templates/log.html new file mode 100644 index 0000000..7caa079 --- /dev/null +++ b/src/templates/log.html @@ -0,0 +1,34 @@ + + + {{ > head.html.tmpl }} + + {{ > header.html.tmpl }} +
+ +
+ + + + + + + + + + + + + {{ #commits }} + + + + + + + + {{ /commits }} + +
DateCommit messageAuthorFilesLines
{{ date }}{{ message_title }}{{ author }}{{ files }}-{{ removed }}/+{{ added }}
+
+ + -- cgit v1.2.3