Update some comments and formatting
This commit is contained in:
parent
82db7f5b93
commit
3978612611
1 changed files with 8 additions and 1 deletions
|
|
@ -1,3 +1,5 @@
|
||||||
|
//! Support for writing static files.
|
||||||
|
|
||||||
use log::{debug, warn};
|
use log::{debug, warn};
|
||||||
|
|
||||||
use crate::config::HtmlConfig;
|
use crate::config::HtmlConfig;
|
||||||
|
|
@ -18,7 +20,7 @@ use std::path::{Path, PathBuf};
|
||||||
/// It also writes files to their final destination, when `write_files` is called,
|
/// It also writes files to their final destination, when `write_files` is called,
|
||||||
/// and interprets the `{{ resource }}` directives to allow assets to name each other.
|
/// and interprets the `{{ resource }}` directives to allow assets to name each other.
|
||||||
///
|
///
|
||||||
/// [fingerprinting]: https://guides.rubyonrails.org/asset_pipeline.html#what-is-fingerprinting-and-why-should-i-care-questionmark
|
/// [fingerprinting]: https://guides.rubyonrails.org/asset_pipeline.html#fingerprinting-versioning-with-digest-based-urls
|
||||||
pub struct StaticFiles {
|
pub struct StaticFiles {
|
||||||
static_files: Vec<StaticFile>,
|
static_files: Vec<StaticFile>,
|
||||||
hash_map: HashMap<String, String>,
|
hash_map: HashMap<String, String>,
|
||||||
|
|
@ -154,12 +156,16 @@ impl StaticFiles {
|
||||||
|
|
||||||
Ok(this)
|
Ok(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_builtin(&mut self, filename: &str, data: &[u8]) {
|
pub fn add_builtin(&mut self, filename: &str, data: &[u8]) {
|
||||||
self.static_files.push(StaticFile::Builtin {
|
self.static_files.push(StaticFile::Builtin {
|
||||||
filename: filename.to_owned(),
|
filename: filename.to_owned(),
|
||||||
data: data.to_owned(),
|
data: data.to_owned(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Updates this [`StaticFiles`] to hash the contents for determining the
|
||||||
|
/// filename for each resource.
|
||||||
pub fn hash_files(&mut self) -> Result<()> {
|
pub fn hash_files(&mut self) -> Result<()> {
|
||||||
use sha2::{Digest, Sha256};
|
use sha2::{Digest, Sha256};
|
||||||
use std::io::Read;
|
use std::io::Read;
|
||||||
|
|
@ -218,6 +224,7 @@ impl StaticFiles {
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn write_files(self, destination: &Path) -> Result<ResourceHelper> {
|
pub fn write_files(self, destination: &Path) -> Result<ResourceHelper> {
|
||||||
use crate::utils::fs::write_file;
|
use crate::utils::fs::write_file;
|
||||||
use regex::bytes::{Captures, Regex};
|
use regex::bytes::{Captures, Regex};
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue