added example
This commit is contained in:
parent
d33c5cb16a
commit
09e44c0e28
6 changed files with 76 additions and 0 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -1,3 +1,5 @@
|
||||||
/target
|
/target
|
||||||
prod
|
prod
|
||||||
tarpaulin-report.html
|
tarpaulin-report.html
|
||||||
|
actix-example/target
|
||||||
|
actix-example/prod
|
||||||
|
|
8
Cargo.lock
generated
8
Cargo.lock
generated
|
@ -2,6 +2,14 @@
|
||||||
# It is not intended for manual editing.
|
# It is not intended for manual editing.
|
||||||
version = 3
|
version = 3
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "actix-example"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"cache-buster",
|
||||||
|
"mime",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "block-buffer"
|
name = "block-buffer"
|
||||||
version = "0.9.0"
|
version = "0.9.0"
|
||||||
|
|
|
@ -6,6 +6,11 @@ edition = "2018"
|
||||||
license = "MIT OR Apache-2.0"
|
license = "MIT OR Apache-2.0"
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
[workspace]
|
||||||
|
members = [
|
||||||
|
".",
|
||||||
|
"actix-example"
|
||||||
|
]
|
||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
name = "cache_buster"
|
name = "cache_buster"
|
||||||
|
|
15
actix-example/Cargo.toml
Normal file
15
actix-example/Cargo.toml
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
[package]
|
||||||
|
name = "actix-example"
|
||||||
|
version = "0.1.0"
|
||||||
|
authors = ["realaravinth <realaravinth@batsense.net>"]
|
||||||
|
edition = "2018"
|
||||||
|
build = "build.rs"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
cache-buster = { path = "../"}
|
||||||
|
|
||||||
|
[build-dependencies]
|
||||||
|
cache-buster = { path = "../"}
|
||||||
|
mime = "0.3.16"
|
22
actix-example/build.rs
Normal file
22
actix-example/build.rs
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
use cache_buster::BusterBuilder;
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let types = vec![
|
||||||
|
mime::IMAGE_PNG,
|
||||||
|
mime::IMAGE_SVG,
|
||||||
|
mime::IMAGE_JPEG,
|
||||||
|
mime::IMAGE_GIF,
|
||||||
|
];
|
||||||
|
|
||||||
|
let config = BusterBuilder::default()
|
||||||
|
.source("../dist")
|
||||||
|
.result("./prod")
|
||||||
|
.mime_types(types)
|
||||||
|
.copy(true)
|
||||||
|
.follow_links(true)
|
||||||
|
.build()
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
config.init().unwrap();
|
||||||
|
config.hash().unwrap().to_env();
|
||||||
|
}
|
24
actix-example/src/main.rs
Normal file
24
actix-example/src/main.rs
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
use cache_buster::Files;
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let files = Files::load();
|
||||||
|
|
||||||
|
assert!(file_exists("../dist/log-out.svg", &files));
|
||||||
|
assert!(file_exists(
|
||||||
|
"../dist/a/b/c/d/s/d/svg/credit-card.svg",
|
||||||
|
&files
|
||||||
|
));
|
||||||
|
|
||||||
|
assert!(!file_exists("dist/log-out.svg", &files));
|
||||||
|
assert!(!file_exists("dist/a/b/c/d/s/d/svg/credit-card.svg", &files));
|
||||||
|
}
|
||||||
|
|
||||||
|
fn file_exists(path: &str, files: &Files) -> bool {
|
||||||
|
use std::path::Path;
|
||||||
|
|
||||||
|
if let Some(file) = files.get(path) {
|
||||||
|
Path::new(file).exists()
|
||||||
|
} else {
|
||||||
|
false
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue