Skip to content

Commit 1848890

Browse files
authored
Add hot reloading (#51)
1 parent 2b1877f commit 1848890

File tree

22 files changed

+724
-307
lines changed

22 files changed

+724
-307
lines changed

.github/workflows/ci.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ jobs:
3939
- run: |
4040
cargo test --all
4141
cargo test --all --features axum
42+
cargo test --all --features reload
4243
4344
lint:
4445
runs-on: ubuntu-latest

Cargo.lock

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,30 @@ license = "CC0-1.0"
1818
repository = "https://github.com/casey/boilerplate"
1919

2020
[dependencies]
21-
boilerplate-macros = { version = "0.0.0", path = "boilerplate-macros" }
21+
boilerplate-macros = { version = "0.0.0", path = "crates/boilerplate-macros" }
22+
boilerplate-parser = { version = "0.0.0", path = "crates/boilerplate-parser", optional = true }
2223

2324
[dev-dependencies]
2425
axum = "0.8.7"
25-
html-escaper = { path = "html-escaper" }
26+
html-escaper = { path = "crates/html-escaper" }
2627

2728
[features]
2829
axum = ["boilerplate-macros/axum"]
30+
reload = ["boilerplate-macros/reload", "dep:boilerplate-parser"]
31+
32+
[lints]
33+
workspace = true
2934

3035
[workspace]
31-
members = [".", "boilerplate-macros", "html-escaper"]
36+
members = [".", "crates/*"]
37+
38+
[workspace.lints.rust]
39+
mismatched-lifetime-syntaxes = "allow"
40+
41+
[workspace.lints.clippy]
42+
all = { level = "deny", priority = -1 }
43+
missing-errors-doc = "allow"
44+
missing-panics-doc = "allow"
45+
needless-pass-by-value = "allow"
46+
pedantic = { level = "deny", priority = -1 }
47+
wildcard-imports = "allow"

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ println!("The output is: {}", MyTemplateTxt { foo: false, bar: Err("hello".into(
9292

9393
`boilerplate`'s implementation is exceedingly simple. Try using
9494
[cargo-expand](https://github.com/dtolnay/cargo-expand) to expand the
95-
`Boilerplate` macro and inspect derived `Display` implementations and debug
95+
`Boilerplate` macro, inspect derived `Display` implementations, and debug
9696
template issues.
9797

9898
Quick Start

boilerplate-macros/src/template.rs

Lines changed: 0 additions & 170 deletions
This file was deleted.

boilerplate-macros/src/token.rs

Lines changed: 0 additions & 84 deletions
This file was deleted.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ repository.workspace = true
1313
proc-macro = true
1414

1515
[dependencies]
16+
boilerplate-parser = { version = "0.0.0", path = "../boilerplate-parser" }
1617
darling = "0.21.3"
1718
mime = "0.3.17"
1819
new_mime_guess = "4.0.1"
@@ -26,3 +27,7 @@ unindent = "0.2.3"
2627

2728
[features]
2829
axum = []
30+
reload = []
31+
32+
[lints]
33+
workspace = true

boilerplate-macros/src/boilerplate.rs renamed to crates/boilerplate-macros/src/boilerplate.rs

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -15,29 +15,27 @@ impl Boilerplate {
1515
.filename
1616
.unwrap_or_else(|| Self::filename_from_ident(&self.ident.to_string()));
1717

18-
let source = match self.text {
19-
Some(text) => Source::Literal(text),
20-
None => {
21-
let manifest_dir = std::env::var("CARGO_MANIFEST_DIR")
22-
.expect("Failed to get `CARGO_MANIFEST_DIR` environment variable");
23-
24-
let path = Path::new(&manifest_dir).join("templates").join(&filename);
25-
26-
let path = path.to_str().unwrap_or_else(|| {
27-
panic!(
28-
"Path to template `{}` was not valid unicode",
29-
path.display()
30-
)
31-
});
32-
33-
Source::Path(path.into())
34-
}
18+
let source = if let Some(text) = self.text {
19+
Source::Literal(text)
20+
} else {
21+
let manifest_dir = std::env::var("CARGO_MANIFEST_DIR")
22+
.expect("Failed to get `CARGO_MANIFEST_DIR` environment variable");
23+
24+
let path = Path::new(&manifest_dir).join("templates").join(&filename);
25+
26+
let path = path.to_str().unwrap_or_else(|| {
27+
panic!(
28+
"Path to template `{}` was not valid unicode",
29+
path.display(),
30+
)
31+
});
32+
33+
Source::Path(path.into())
3534
};
3635

37-
let escape = Path::new(&filename)
38-
.extension()
39-
.map(|extension| ["html", "htm", "xml"].contains(&extension.to_string_lossy().as_ref()))
40-
.unwrap_or(false);
36+
let escape = Path::new(&filename).extension().is_some_and(|extension| {
37+
["html", "htm", "xml"].contains(&extension.to_string_lossy().as_ref())
38+
});
4139

4240
let guess = new_mime_guess::from_path(&filename).first_or_text_plain();
4341

0 commit comments

Comments
 (0)