pub fn new(
        shell: String,
        root_id: &str,
        render_cfg: &HashMap<String, String>,
        path_prefix: &str,
    ) -> Self {
        let mut head_before_boundary = Vec::new();
        let mut scripts_before_boundary = Vec::new();

        // Define the render config as a global variable
        let render_cfg = format!(
            "window.__PERSEUS_RENDER_CFG = '{render_cfg}';",
            // It's safe to assume that something we just deserialized will serialize again in this case
            render_cfg = serde_json::to_string(render_cfg).unwrap()
        );
        scripts_before_boundary.push(render_cfg.into());

        // Inject a global variable to identify whether we are testing (picked up by app shell to trigger helper DOM events)
        if env::var("PERSEUS_TESTING").is_ok() {
            scripts_before_boundary.push("window.__PERSEUS_TESTING = true;".into());
        }

        // Define the script that will load the Wasm bundle (inlined to avoid unnecessary extra requests)
        let load_wasm_bundle = format!(
            r#"
        import init, {{ run }} from "{path_prefix}/.perseus/bundle.js";
        async function main() {{
            await init("{path_prefix}/.perseus/bundle.wasm");
            run();
        }}
        main();
        "#,
            path_prefix = path_prefix
        );
        scripts_before_boundary.push(load_wasm_bundle.into());

        // Add in the `<base>` element at the very top so that it applies to everything in the HTML shell
        // Otherwise any stylesheets loaded before it won't work properly
        //
        // We add a trailing `/` to the base URL (https://stackoverflow.com/a/26043021)
        // Note that it's already had any pre-existing ones stripped away
        let base = format!(r#"<base href="{}/" />"#, path_prefix);
        head_before_boundary.push(base.into());

        Self {
            shell,
            head_before_boundary,
            scripts_before_boundary,
            head_after_boundary: Vec::new(),
            scripts_after_boundary: Vec::new(),
            content: "".into(),
            root_id: root_id.into(),
            path_prefix: path_prefix.into(),
        }
    }
/// Initializes the HTML shell by interpolating necessary scripts into it and adding the render configuration.
Initializes the HTML shell by interpolating necessary scripts into it and adding the render configuration.
Initializes the HTML shell by interpolating necessary scripts into it and adding the render configuration .
pub fn new(
        shell: String,
        root_id: &str,
        render_cfg: &HashMap<String, String>,
        path_prefix: &str,
    ) -> Self {
        let mut head_before_boundary = Vec::new();
        let mut scripts_before_boundary = Vec::new();
        // Define the render config as a global variable
        let render_cfg = format!(
            "window.__PERSEUS_RENDER_CFG = '{render_cfg}';",
            // It's safe to assume that something we just deserialized will serialize again in this case
            render_cfg = serde_json::to_string(render_cfg).unwrap()
        );
        scripts_before_boundary.push(render_cfg.into());
        // Inject a global variable to identify whether we are testing (picked up by app shell to trigger helper DOM events)
        if env::var("PERSEUS_TESTING").is_ok() {
            scripts_before_boundary.push("window.__PERSEUS_TESTING = true;".into());
        }
        // Define the script that will load the Wasm bundle (inlined to avoid unnecessary extra requests)
        let load_wasm_bundle = format!(
            r#"
        import init, {{ run }} from "{path_prefix}/.perseus/bundle.js";
        async function main() {{
            await init("{path_prefix}/.perseus/bundle.wasm");
            run();
        }}
        main();
        "#,
            path_prefix = path_prefix
        );
        scripts_before_boundary.push(load_wasm_bundle.into());
        // Add in the `<base>` element at the very top so that it applies to everything in the HTML shell
        // Otherwise any stylesheets loaded before it won't work properly
        //
        // We add a trailing `/` to the base URL (https://stackoverflow.com/a/26043021)
        // Note that it's already had any pre-existing ones stripped away
        let base = format!(r#"<base href="{}/" />"#, path_prefix);
        head_before_boundary.push(base.into());
        Self {
            shell,
            head_before_boundary,
            scripts_before_boundary,
            head_after_boundary: Vec::new(),
            scripts_after_boundary: Vec::new(),
            content: "".into(),
            root_id: root_id.into(),
            path_prefix: path_prefix.into(),
        }
    }
pub fn new ( shell : String , root_id : & str , render_cfg : & HashMap < String , String > , path_prefix : & str , ) -> Self { let mut head_before_boundary = Vec :: new ( ) ; let mut scripts_before_boundary = Vec :: new ( ) ; // Define the render config as a global variable let render_cfg = format ! ( " " // It's safe to assume that something we just deserialized will serialize again in this case render_cfg serde_json to_string ( render_cfg ) unwrap ( ) ) ; scripts_before_boundary . push ( render_cfg . into ( ) ) ; // Inject a global variable to identify whether we are testing (picked up by app shell to trigger helper DOM events) if env :: var ( " " ) . is_ok ( ) { scripts_before_boundary . push ( " " . into ( ) ) ; } // Define the script that will load the Wasm bundle (inlined to avoid unnecessary extra requests) let load_wasm_bundle = format ! ( r#"
        import init, {{ run }} from "{path_prefix}/.perseus/bundle.js";
        async function main() {{
            await init("{path_prefix}/.perseus/bundle.wasm");
            run();
        }}
        main();
        "# path_prefix path_prefix ) ; scripts_before_boundary . push ( load_wasm_bundle . into ( ) ) ; // Add in the `<base>` element at the very top so that it applies to everything in the HTML shell // Otherwise any stylesheets loaded before it won't work properly // // We add a trailing `/` to the base URL (https://stackoverflow.com/a/26043021) // Note that it's already had any pre-existing ones stripped away let base = format ! ( r#"<base href="{}/" />"# path_prefix ) ; head_before_boundary . push ( base . into ( ) ) ; Self { shell , head_before_boundary , scripts_before_boundary , head_after_boundary : Vec :: new ( ) , scripts_after_boundary : Vec :: new ( ) , content : " " . into ( ) , root_id : root_id . into ( ) , path_prefix : path_prefix . into ( ) , } }
Initializes the HTML shell by interpolating necessary scripts into it and adding the render configuration.
Initializes the HTML shell by interpolating necessary scripts into it and adding the render configuration .
shell
String
root_id
&str
render_cfg
&HashMap<String, String>
path_prefix
&str
shell
String
root_id
&str
render_cfg
&HashMap<String, String>
path_prefix
&str