use include_dir::{include_dir, Dir};
#[allow(unused_imports)]
use pax_runtime::api::serde::{Deserialize, Serialize};
#[allow(unused_imports)]
use serde_json;
use std::collections::HashMap;
use tera::{Context, Tera};
use pax_manifest::{
cartridge_generation::{CommonProperty, ComponentInfo},
TypeTable,
};
static TEMPLATE_DIR: Dir<'_> = include_dir!("$CARGO_MANIFEST_DIR/templates/cartridge_generation");
static CARTRIDGE_TEMPLATE: &str = "cartridge.tera";
static MACROS_TEMPLATE: &str = "macros.tera";
#[serde_with::serde_as]
#[derive(Serialize)]
pub struct TemplateArgsCodegenCartridgeSnippet {
pub cartridge_struct_id: String,
pub definition_to_instance_traverser_struct_id: String,
pub components: Vec<ComponentInfo>,
pub common_properties: Vec<CommonProperty>,
#[serde_as(as = "HashMap<serde_with::json::JsonString, _>")]
pub type_table: TypeTable,
pub is_designtime: bool,
pub userland_manifest_json: String,
pub designer_manifest_json: String,
pub engine_import_path: String,
}
#[allow(unused)]
static TEMPLATE_CODEGEN_CARTRIDGE_SNIPPET: &str =
include_str!("../../templates/cartridge_generation/cartridge.tera");
pub fn press_template_codegen_cartridge_snippet(
args: TemplateArgsCodegenCartridgeSnippet,
) -> String {
let mut tera = Tera::default();
tera.add_raw_template(
MACROS_TEMPLATE,
TEMPLATE_DIR
.get_file(MACROS_TEMPLATE)
.unwrap()
.contents_utf8()
.unwrap(),
)
.expect("Failed to add macros.tera");
tera.add_raw_template(
CARTRIDGE_TEMPLATE,
TEMPLATE_DIR
.get_file(CARTRIDGE_TEMPLATE)
.unwrap()
.contents_utf8()
.unwrap(),
)
.expect("Failed to add cartridge.tera");
tera.render(CARTRIDGE_TEMPLATE, &Context::from_serialize(args).unwrap())
.expect("Failed to render template")
}