diff options
author | Thomas Letan <contact@thomasletan.fr> | 2020-02-08 14:23:50 +0100 |
---|---|---|
committer | Thomas Letan <contact@thomasletan.fr> | 2020-02-08 14:27:05 +0100 |
commit | 04a22b78dde91a9b5a3c5aab2d71abd6473cefaf (patch) | |
tree | 019ae84171e2634d4391bbeafb44c65a241da87f | |
parent | feature: Add options `output` and `body-only` to celtchar-static (diff) |
chore: Add a pre-commit hook script to check formatting
This script shall be installed manually with eg., a symbolic link.
-rw-r--r-- | app/src/main.rs | 8 | ||||
-rwxr-xr-x | hooks/pre-commit | 3 | ||||
-rw-r--r-- | lib/src/lib.rs | 2 | ||||
-rw-r--r-- | lib/src/wstatic.rs | 34 |
4 files changed, 21 insertions, 26 deletions
diff --git a/app/src/main.rs b/app/src/main.rs index 1ae254d..0b888ab 100644 --- a/app/src/main.rs +++ b/app/src/main.rs @@ -105,13 +105,11 @@ fn main() -> Result<(), Error> { match matches.subcommand() { ("epub", _) => build_epub(&assets)?, - ("static",Some(args)) => { + ("static", Some(args)) => { let body_only = args.is_present("body-only"); - let output_dir = PathBuf::from( - args.value_of("output").unwrap_or("out") - ); + let output_dir = PathBuf::from(args.value_of("output").unwrap_or("out")); build_static(&assets, body_only, &output_dir)? - }, + } ("deps", _) => deps()?, _ => unimplemented!(), } diff --git a/hooks/pre-commit b/hooks/pre-commit new file mode 100755 index 0000000..5732760 --- /dev/null +++ b/hooks/pre-commit @@ -0,0 +1,3 @@ +#!/bin/bash + +cargo +nightly fmt -- --check
\ No newline at end of file diff --git a/lib/src/lib.rs b/lib/src/lib.rs index dbcceea..6d313d6 100644 --- a/lib/src/lib.rs +++ b/lib/src/lib.rs @@ -12,8 +12,8 @@ mod render; mod writer; mod wstatic; -pub use writer::BookWriter; pub use epub::{EpubWriter, Zip}; pub use error::{Error, Raise}; pub use project::{Chapter, Cover, Loader, Project}; +pub use writer::BookWriter; pub use wstatic::Static; diff --git a/lib/src/wstatic.rs b/lib/src/wstatic.rs index a38e8f5..a957f85 100644 --- a/lib/src/wstatic.rs +++ b/lib/src/wstatic.rs @@ -1,12 +1,12 @@ -use std::path::PathBuf; -use std::fs::{create_dir, read_to_string}; use serde_json::json; -use tera::{Tera, Context}; +use std::fs::{create_dir, read_to_string}; +use std::path::PathBuf; +use tera::{Context, Tera}; -use crate::error::{Raise, Error}; -use crate::project::{Cover, Project, Language, Chapter}; -use crate::BookWriter; use crate::assets::template_dir; +use crate::error::{Error, Raise}; +use crate::project::{Chapter, Cover, Language, Project}; +use crate::BookWriter; pub struct Static { base : PathBuf, @@ -15,7 +15,6 @@ pub struct Static { impl BookWriter for Static { fn write_bytes(&mut self, dst : &PathBuf, input : &[u8]) -> Result<(), Error> { - std::fs::write(&self.base.join(dst), input) .or_raise(&format!("Could not write content to file {:?}", dst))?; @@ -23,8 +22,8 @@ impl BookWriter for Static { } fn write_file(&mut self, dst : &PathBuf, src : &PathBuf) -> Result<(), Error> { - let input = read_to_string(src) - .or_raise(&format!("Could not read content of file {:?}", src))?; + let input = + read_to_string(src).or_raise(&format!("Could not read content of file {:?}", src))?; self.write_bytes(dst, input.as_bytes())?; @@ -40,12 +39,14 @@ impl Static { if base.is_dir() { Ok(Static { - base : base.to_owned() base : base.to_owned(), body_only : body_only, }) } else { - Err(Error::new(&format!("{:?} already exists and is not a directory", base))) + Err(Error::new(&format!( + "{:?} already exists and is not a directory", + base + ))) } } @@ -105,19 +106,13 @@ impl Static { let path : PathBuf = PathBuf::from(format!("{}.html", idx)); - self.write_template( - &path, - tera, - "static/chapter.html", - &ctx, - )?; + self.write_template(&path, tera, "static/chapter.html", &ctx)?; Ok(()) }) .collect::<Result<Vec<()>, Error>>()?; Ok(()) - } pub fn generate_static_website( @@ -126,8 +121,7 @@ impl Static { assets : &PathBuf, ) -> Result<(), Error> { let tera = - Tera::new(template_dir(assets)?.as_str()) - .or_raise("Could not build templates")?; + Tera::new(template_dir(assets)?.as_str()).or_raise("Could not build templates")?; self.generate_index(project, &tera)?; self.generate_chapters( |