1
+ //! Support for writing static files.
2
+
1
3
use log:: { debug, warn} ;
2
4
3
5
use crate :: config:: HtmlConfig ;
@@ -18,7 +20,7 @@ use std::path::{Path, PathBuf};
18
20
/// It also writes files to their final destination, when `write_files` is called,
19
21
/// and interprets the `{{ resource }}` directives to allow assets to name each other.
20
22
///
21
- /// [fingerprinting]: https://guides.rubyonrails.org/asset_pipeline.html#what-is- fingerprinting-and-why-should-i-care-questionmark
23
+ /// [fingerprinting]: https://guides.rubyonrails.org/asset_pipeline.html#fingerprinting-versioning-with-digest-based-urls
22
24
pub struct StaticFiles {
23
25
static_files : Vec < StaticFile > ,
24
26
hash_map : HashMap < String , String > ,
@@ -154,12 +156,16 @@ impl StaticFiles {
154
156
155
157
Ok ( this)
156
158
}
159
+
157
160
pub fn add_builtin ( & mut self , filename : & str , data : & [ u8 ] ) {
158
161
self . static_files . push ( StaticFile :: Builtin {
159
162
filename : filename. to_owned ( ) ,
160
163
data : data. to_owned ( ) ,
161
164
} ) ;
162
165
}
166
+
167
+ /// Updates this [`StaticFiles`] to hash the contents for determining the
168
+ /// filename for each resource.
163
169
pub fn hash_files ( & mut self ) -> Result < ( ) > {
164
170
use sha2:: { Digest , Sha256 } ;
165
171
use std:: io:: Read ;
@@ -218,6 +224,7 @@ impl StaticFiles {
218
224
}
219
225
Ok ( ( ) )
220
226
}
227
+
221
228
pub fn write_files ( self , destination : & Path ) -> Result < ResourceHelper > {
222
229
use crate :: utils:: fs:: write_file;
223
230
use regex:: bytes:: { Captures , Regex } ;
0 commit comments