pub fn new<P: AsRef<Path>>(theme_dir: P) -> Self {
        let theme_dir = theme_dir.as_ref();
        let mut theme = Theme::default();

        // If the theme directory doesn't exist there's no point continuing...
        if !theme_dir.exists() || !theme_dir.is_dir() {
            return theme;
        }

        // Check for individual files, if they exist copy them across
        {
            let files = vec![
                (theme_dir.join("index.hbs"), &mut theme.index),
                (theme_dir.join("head.hbs"), &mut theme.head),
                (theme_dir.join("redirect.hbs"), &mut theme.redirect),
                (theme_dir.join("header.hbs"), &mut theme.header),
                (theme_dir.join("book.js"), &mut theme.js),
                (theme_dir.join("css/chrome.css"), &mut theme.chrome_css),
                (theme_dir.join("css/general.css"), &mut theme.general_css),
                (theme_dir.join("css/print.css"), &mut theme.print_css),
                (
                    theme_dir.join("css/variables.css"),
                    &mut theme.variables_css,
                ),
                (theme_dir.join("highlight.js"), &mut theme.highlight_js),
                (theme_dir.join("clipboard.min.js"), &mut theme.clipboard_js),
                (theme_dir.join("highlight.css"), &mut theme.highlight_css),
                (
                    theme_dir.join("tomorrow-night.css"),
                    &mut theme.tomorrow_night_css,
                ),
                (
                    theme_dir.join("ayu-highlight.css"),
                    &mut theme.ayu_highlight_css,
                ),
            ];

            let load_with_warn = |filename: &Path, dest| {
                if !filename.exists() {
                    // Don't warn if the file doesn't exist.
                    return false;
                }
                if let Err(e) = load_file_contents(filename, dest) {
                    warn!("Couldn't load custom file, {}: {}", filename.display(), e);
                    false
                } else {
                    true
                }
            };

            for (filename, dest) in files {
                load_with_warn(&filename, dest);
            }

            // If the user overrides one favicon, but not the other, do not
            // copy the default for the other.
            let favicon_png = &mut theme.favicon_png.as_mut().unwrap();
            let png = load_with_warn(&theme_dir.join("favicon.png"), favicon_png);
            let favicon_svg = &mut theme.favicon_svg.as_mut().unwrap();
            let svg = load_with_warn(&theme_dir.join("favicon.svg"), favicon_svg);
            match (png, svg) {
                (true, true) | (false, false) => {}
                (true, false) => {
                    theme.favicon_svg = None;
                }
                (false, true) => {
                    theme.favicon_png = None;
                }
            }
        }

        theme
    }
/// Creates a `Theme` from the given `theme_dir`.
/// If a file is found in the theme dir, it will override the default version.
Creates a `Theme` from the given `theme_dir`.
If a file is found in the theme dir, it will override the default version.
Creates a ` Theme ` from the given ` theme_dir ` . If a file is found in the theme dir it will override the default version .
pub fn new<P: AsRef<Path>>(theme_dir: P) -> Self {
        let theme_dir = theme_dir.as_ref();
        let mut theme = Theme::default();
        // If the theme directory doesn't exist there's no point continuing...
        if !theme_dir.exists() || !theme_dir.is_dir() {
            return theme;
        }
        // Check for individual files, if they exist copy them across
        {
            let files = vec![
                (theme_dir.join("index.hbs"), &mut theme.index),
                (theme_dir.join("head.hbs"), &mut theme.head),
                (theme_dir.join("redirect.hbs"), &mut theme.redirect),
                (theme_dir.join("header.hbs"), &mut theme.header),
                (theme_dir.join("book.js"), &mut theme.js),
                (theme_dir.join("css/chrome.css"), &mut theme.chrome_css),
                (theme_dir.join("css/general.css"), &mut theme.general_css),
                (theme_dir.join("css/print.css"), &mut theme.print_css),
                (
                    theme_dir.join("css/variables.css"),
                    &mut theme.variables_css,
                ),
                (theme_dir.join("highlight.js"), &mut theme.highlight_js),
                (theme_dir.join("clipboard.min.js"), &mut theme.clipboard_js),
                (theme_dir.join("highlight.css"), &mut theme.highlight_css),
                (
                    theme_dir.join("tomorrow-night.css"),
                    &mut theme.tomorrow_night_css,
                ),
                (
                    theme_dir.join("ayu-highlight.css"),
                    &mut theme.ayu_highlight_css,
                ),
            ];
            let load_with_warn = |filename: &Path, dest| {
                if !filename.exists() {
                    // Don't warn if the file doesn't exist.
                    return false;
                }
                if let Err(e) = load_file_contents(filename, dest) {
                    warn!("Couldn't load custom file, {}: {}", filename.display(), e);
                    false
                } else {
                    true
                }
            };
            for (filename, dest) in files {
                load_with_warn(&filename, dest);
            }
            // If the user overrides one favicon, but not the other, do not
            // copy the default for the other.
            let favicon_png = &mut theme.favicon_png.as_mut().unwrap();
            let png = load_with_warn(&theme_dir.join("favicon.png"), favicon_png);
            let favicon_svg = &mut theme.favicon_svg.as_mut().unwrap();
            let svg = load_with_warn(&theme_dir.join("favicon.svg"), favicon_svg);
            match (png, svg) {
                (true, true) | (false, false) => {}
                (true, false) => {
                    theme.favicon_svg = None;
                }
                (false, true) => {
                    theme.favicon_png = None;
                }
            }
        }
        theme
    }
pub fn new < P : AsRef < Path > > ( theme_dir : P ) -> Self { let theme_dir = theme_dir . as_ref ( ) ; let mut theme = Theme :: default ( ) ; // If the theme directory doesn't exist there's no point continuing... if ! theme_dir . exists ( ) || ! theme_dir . is_dir ( ) { return theme ; } // Check for individual files, if they exist copy them across { let files = vec ! [ ( theme_dir join ( " " ) mut theme index ) ( theme_dir join ( " " ) mut theme head ) ( theme_dir join ( " " ) mut theme redirect ) ( theme_dir join ( " " ) mut theme header ) ( theme_dir join ( " " ) mut theme js ) ( theme_dir join ( " " ) mut theme chrome_css ) ( theme_dir join ( " " ) mut theme general_css ) ( theme_dir join ( " " ) mut theme print_css ) ( theme_dir join ( " " ) mut theme variables_css ) ( theme_dir join ( " " ) mut theme highlight_js ) ( theme_dir join ( " " ) mut theme clipboard_js ) ( theme_dir join ( " " ) mut theme highlight_css ) ( theme_dir join ( " " ) mut theme tomorrow_night_css ) ( theme_dir join ( " " ) mut theme ayu_highlight_css ) ] ; let load_with_warn = | filename : & Path , dest | { if ! filename . exists ( ) { // Don't warn if the file doesn't exist. return false ; } if let Err ( e ) = load_file_contents ( filename , dest ) { warn ! ( " " filename display ( ) e ) ; false } else { true } } ; for ( filename , dest ) in files { load_with_warn ( & filename , dest ) ; } // If the user overrides one favicon, but not the other, do not // copy the default for the other. let favicon_png = & mut theme . favicon_png . as_mut ( ) . unwrap ( ) ; let png = load_with_warn ( & theme_dir . join ( " " ) , favicon_png ) ; let favicon_svg = & mut theme . favicon_svg . as_mut ( ) . unwrap ( ) ; let svg = load_with_warn ( & theme_dir . join ( " " ) , favicon_svg ) ; match ( png , svg ) { ( true , true ) | ( false , false ) => { } ( true , false ) => { theme . favicon_svg = None ; } ( false , true ) => { theme . favicon_png = None ; } } } theme }
Creates a `Theme` from the given `theme_dir`.
Creates a ` Theme ` from the given ` theme_dir ` .
theme_dir
P
theme_dir
P