🔥 Quita código incluido ahora en [pagetop-build]

This commit is contained in:
Manuel Cillero 2023-01-23 20:41:02 +01:00
parent 5bef90600f
commit 7ed2d37e52
3 changed files with 5 additions and 103 deletions

View file

@ -70,7 +70,7 @@ postgres = ["database", "sea-orm/sqlx-postgres"]
sqlite = ["database", "sea-orm/sqlx-sqlite"]
[build-dependencies]
static-files = "0.2.3"
pagetop-build = { path = "../pagetop-build", version = "0.0" }
[dev-dependencies]
tokio = { version = "1.21.2", features = ["macros", "rt-multi-thread"] }

View file

@ -1,19 +1,6 @@
use std::path::Path;
fn main() -> std::io::Result<()> {
bundle_resources("./static/theme", "theme")?;
bundle_resources("./static/aliner", "aliner")?;
bundle_resources("./static/bootsier", "bootsier")?;
bundle_resources("./static/bulmix", "bulmix")
}
/// This function is a simplified version of `pagetop::util::bundle_resources()`.
pub fn bundle_resources(from_dir: &str, with_name: &str) -> std::io::Result<()> {
let mut bundle = static_files::resource_dir(from_dir);
bundle.with_generated_filename(
Path::new(std::env::var("OUT_DIR").unwrap().as_str()).join(format!("{}.rs", with_name)),
);
bundle.with_module_name(format!("resources_{}", with_name));
bundle.with_generated_fn(format!("bundle_{}", with_name));
bundle.build()
pagetop_build::bundle_resources("./static/theme", "theme", None)?;
pagetop_build::bundle_resources("./static/aliner", "aliner", None)?;
pagetop_build::bundle_resources("./static/bootsier", "bootsier", None)?;
pagetop_build::bundle_resources("./static/bulmix", "bulmix", None)
}

View file

@ -1,92 +1,7 @@
pub use static_files::Resource as StaticResource;
use std::path::Path;
pub type HashMapResources = std::collections::HashMap<&'static str, StaticResource>;
/// This function uses the [static_files](https://docs.rs/static-files/latest/static_files/) library
/// to embed at compile time a bundle of static files in your binary.
///
/// Just create folder with static resources in your project (for example `static`):
///
/// ```bash
/// cd project_dir
/// mkdir static
/// echo "Hello, world" > static/hello
/// ```
///
/// Add to `Cargo.toml` the required dependencies:
///
/// ```toml
/// [dependencies]
/// pagetop = { ... }
/// static-files = "0.2.3"
///
/// [build-dependencies]
/// pagetop = { ... }
/// ```
///
/// Add `build.rs` with call to bundle resources (*guides* will be the magic word in this example):
///
/// ```rust#ignore
/// use pagetop::util::bundle_resources;
///
/// fn main() -> std::io::Result<()> {
/// bundle_resources("./static", "guides", None)
/// }
/// ```
///
/// Optionally, you can pass a function to filter those files into the `./static` folder which
/// should be included in the resources file:
///
/// ```rust#ignore
/// use pagetop::util::bundle_resources;
///
/// fn main() -> std::io::Result<()> {
/// bundle_resources("./static", "guides", Some(except_css_dir))
/// }
///
/// fn except_css_dir(p: &Path) -> bool {
/// if let Some(parent) = p.parent() {
/// !matches!(parent.to_str(), Some("/css"))
/// }
/// true
/// }
/// ```
///
/// This will create a file called `guides.rs` in the standard directory
/// [OUT_DIR](https://doc.rust-lang.org/cargo/reference/environment-variables.html) where all
/// intermediate and output artifacts are placed during compilation.
///
/// You don't need to access this file, just include it in your project source code and a module called
/// `resources_guides` will be added. Then simply reference the `bundle_guides` function to embed
/// the generated HashMap resources collection:
///
/// ```rust#ignore
/// use pagetop::prelude::*;
///
/// include!(concat!(env!("OUT_DIR"), "/guides.rs"));
/// static RESOURCES: LazyStatic<HashMapResources> = LazyStatic::new(bundle_guides);
/// ```
///
/// You can build more than one resources file to compile with your project.
pub fn bundle_resources(
from_dir: &str,
with_name: &str,
filtering: Option<fn(p: &Path) -> bool>,
) -> std::io::Result<()> {
let mut bundle = static_files::resource_dir(from_dir);
bundle.with_generated_filename(
Path::new(std::env::var("OUT_DIR").unwrap().as_str()).join(format!("{}.rs", with_name)),
);
bundle.with_module_name(format!("resources_{}", with_name));
bundle.with_generated_fn(format!("bundle_{}", with_name));
if let Some(filter_files) = filtering {
bundle.with_filter(filter_files);
}
bundle.build()
}
pub type Handle = u64;
// https://stackoverflow.com/a/71464396