added example

This commit is contained in:
Aravinth Manivannan 2021-04-08 22:08:21 +05:30
parent d33c5cb16a
commit 09e44c0e28
Signed by: realaravinth
GPG key ID: AD9F0F08E855ED88
6 changed files with 76 additions and 0 deletions

2
.gitignore vendored
View file

@ -1,3 +1,5 @@
/target /target
prod prod
tarpaulin-report.html tarpaulin-report.html
actix-example/target
actix-example/prod

8
Cargo.lock generated
View file

@ -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"

View file

@ -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
View 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
View 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
View 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
}
}