@@ -53,7 +53,12 @@ pub enum ContentToMinify<'a> {
5353} 
5454
5555impl < ' a >  ContentToMinify < ' a >  { 
56-     pub  fn  minified ( self )  -> Vec < u8 >  { 
56+     /// If `minification` is false, it simply returns the inner data converted into a `Vec`. 
57+      pub  fn  minified ( self ,  minification :  bool )  -> Vec < u8 >  { 
58+         if  !minification { 
59+             let  ( Self :: CSS ( data)  | Self :: JS ( data) )  = self ; 
60+             return  data. as_bytes ( ) . to_owned ( ) ; 
61+         } 
5762        let  mut  out = Vec :: new ( ) ; 
5863        self . write_into ( & mut  out) . unwrap ( ) ; 
5964        out
@@ -104,9 +109,9 @@ pub struct Theme {
104109impl  Theme  { 
105110    /// Creates a `Theme` from the given `theme_dir`. 
106111     /// If a file is found in the theme dir, it will override the default version. 
107-      pub  fn  new < P :  AsRef < Path > > ( theme_dir :  P )  -> Self  { 
112+      pub  fn  new < P :  AsRef < Path > > ( theme_dir :  P ,   minification :   bool )  -> Self  { 
108113        let  theme_dir = theme_dir. as_ref ( ) ; 
109-         let  mut  theme = Theme :: default ( ) ; 
114+         let  mut  theme = Self :: new_with_set_fields ( minification ) ; 
110115
111116        // If the theme directory doesn't exist there's no point continuing... 
112117        if  !theme_dir. exists ( )  || !theme_dir. is_dir ( )  { 
@@ -202,29 +207,27 @@ impl Theme {
202207
203208        theme
204209    } 
205- } 
206210
207- impl  Default  for  Theme  { 
208-     fn  default ( )  -> Theme  { 
211+     fn  new_with_set_fields ( minification :  bool )  -> Self  { 
209212        Theme  { 
210213            index :  INDEX . to_owned ( ) , 
211214            head :  HEAD . to_owned ( ) , 
212215            redirect :  REDIRECT . to_owned ( ) , 
213216            header :  HEADER . to_owned ( ) , 
214217            toc_js :  TOC_JS . to_owned ( ) , 
215218            toc_html :  TOC_HTML . to_owned ( ) , 
216-             chrome_css :  CHROME_CSS . minified ( ) , 
217-             general_css :  GENERAL_CSS . minified ( ) , 
218-             print_css :  PRINT_CSS . minified ( ) , 
219-             variables_css :  VARIABLES_CSS . minified ( ) , 
219+             chrome_css :  CHROME_CSS . minified ( minification ) , 
220+             general_css :  GENERAL_CSS . minified ( minification ) , 
221+             print_css :  PRINT_CSS . minified ( minification ) , 
222+             variables_css :  VARIABLES_CSS . minified ( minification ) , 
220223            fonts_css :  None , 
221224            font_files :  Vec :: new ( ) , 
222225            favicon_png :  Some ( FAVICON_PNG . to_owned ( ) ) , 
223226            favicon_svg :  Some ( FAVICON_SVG . to_owned ( ) ) , 
224-             js :  JS . minified ( ) , 
225-             highlight_css :  HIGHLIGHT_CSS . minified ( ) , 
226-             tomorrow_night_css :  TOMORROW_NIGHT_CSS . minified ( ) , 
227-             ayu_highlight_css :  AYU_HIGHLIGHT_CSS . minified ( ) , 
227+             js :  JS . minified ( minification ) , 
228+             highlight_css :  HIGHLIGHT_CSS . minified ( minification ) , 
229+             tomorrow_night_css :  TOMORROW_NIGHT_CSS . minified ( minification ) , 
230+             ayu_highlight_css :  AYU_HIGHLIGHT_CSS . minified ( minification ) , 
228231            highlight_js :  HIGHLIGHT_JS . to_owned ( ) , 
229232            clipboard_js :  CLIPBOARD_JS . to_owned ( ) , 
230233        } 
@@ -258,8 +261,9 @@ mod tests {
258261        let  non_existent = PathBuf :: from ( "/non/existent/directory/" ) ; 
259262        assert ! ( !non_existent. exists( ) ) ; 
260263
261-         let  should_be = Theme :: default ( ) ; 
262-         let  got = Theme :: new ( & non_existent) ; 
264+         let  minification = false ; 
265+         let  should_be = Theme :: new_with_set_fields ( minification) ; 
266+         let  got = Theme :: new ( & non_existent,  minification) ; 
263267
264268        assert_eq ! ( got,  should_be) ; 
265269    } 
@@ -297,7 +301,7 @@ mod tests {
297301            File :: create ( & temp. path ( ) . join ( file) ) . unwrap ( ) ; 
298302        } 
299303
300-         let  got = Theme :: new ( temp. path ( ) ) ; 
304+         let  got = Theme :: new ( temp. path ( ) ,   false ) ; 
301305
302306        let  empty = Theme  { 
303307            index :  Vec :: new ( ) , 
@@ -329,13 +333,13 @@ mod tests {
329333    fn  favicon_override ( )  { 
330334        let  temp = TempFileBuilder :: new ( ) . prefix ( "mdbook-" ) . tempdir ( ) . unwrap ( ) ; 
331335        fs:: write ( temp. path ( ) . join ( "favicon.png" ) ,  "1234" ) . unwrap ( ) ; 
332-         let  got = Theme :: new ( temp. path ( ) ) ; 
336+         let  got = Theme :: new ( temp. path ( ) ,   false ) ; 
333337        assert_eq ! ( got. favicon_png. as_ref( ) . unwrap( ) ,  b"1234" ) ; 
334338        assert_eq ! ( got. favicon_svg,  None ) ; 
335339
336340        let  temp = TempFileBuilder :: new ( ) . prefix ( "mdbook-" ) . tempdir ( ) . unwrap ( ) ; 
337341        fs:: write ( temp. path ( ) . join ( "favicon.svg" ) ,  "4567" ) . unwrap ( ) ; 
338-         let  got = Theme :: new ( temp. path ( ) ) ; 
342+         let  got = Theme :: new ( temp. path ( ) ,   false ) ; 
339343        assert_eq ! ( got. favicon_png,  None ) ; 
340344        assert_eq ! ( got. favicon_svg. as_ref( ) . unwrap( ) ,  b"4567" ) ; 
341345    } 
0 commit comments