pub const CRATE_VERSION: &str = env!("CARGO_PKG_VERSION");
pub const CRATE_NAME: &str = "alia-foundry";
pub fn foundry_dep_line(local_crate_path: Option<&str>) -> String {
match local_crate_path {
Some(path) => format!(
"foundry_runtime = {{ package = \"{}\", path = \"{}\" }}",
CRATE_NAME,
path.replace('\\', "/")
),
None => format!(
"foundry_runtime = {{ package = \"{}\", version = \"{}\" }}",
CRATE_NAME, CRATE_VERSION
),
}
}
pub fn generate_cargo_toml(bin_name: &str, dep_line: &str) -> String {
format!(
r#"[package]
name = "{name}"
version = "0.1.0"
edition = "2021"
[dependencies]
{dep}
env_logger = "0.11"
[profile.release]
opt-level = "z"
lto = true
codegen-units = 1
strip = true
panic = "abort"
"#,
name = bin_name,
dep = dep_line,
)
}
pub fn escape_html_literal(html: &str) -> String {
html.replace('\\', "\\\\")
.replace('"', "\\\"")
.replace('\n', "\\n")
.replace('\r', "\\r")
.replace('\t', "\\t")
}
pub fn generate_main_rs(html: &str, title: &str) -> String {
format!(
r#"fn main() {{
foundry_runtime::run_embedded(
"{html}",
"{title}",
);
}}
"#,
html = escape_html_literal(html),
title = escape_html_literal(title),
)
}