use crate::trait_utils_mod;
use dev_bestia_string_utils::*;
use dev_bestia_url_utf8::*;
#[derive(Clone, Debug, Default)]
pub struct ElementNode {
pub tag_name: String,
pub attributes: Vec<Attribute>,
pub children: Vec<trait_utils_mod::Node>,
pub namespace: Option<String>,
pub is_self_closing: bool,
}
#[derive(Clone, Debug)]
pub struct Attribute {
pub name: String,
pub value: String,
}
#[allow(dead_code)]
#[derive(Clone, Copy)]
pub enum ServerOrClient {
Server,
WebBrowserClient,
}
#[derive(Clone, Debug)]
pub struct PrefixForTemplateVariables {
pub text: String,
pub url: String,
pub exist: String,
pub node: String,
pub subtemplate: String,
pub subtemplate_comment: String,
pub attr_text: String,
pub attr_url: String,
pub attr_exist: String,
}
pub trait HtmlTemplatingDataTrait {
fn data_model_name(&self) -> String;
fn replace_with_string(
&self,
placeholder: &str,
subtemplate_name: &str,
row_number: usize,
) -> String;
fn replace_with_url(
&self,
placeholder: &str,
_subtemplate_name: &str,
_pos_cursor: usize,
) -> UrlUtf8EncodedString {
match placeholder {
_ => trait_utils_mod::match_else_for_replace_with_url(
&self.data_model_name(),
placeholder,
),
}
}
fn exists_next_node_or_attribute(&self, placeholder: &str) -> bool {
match placeholder {
_ => trait_utils_mod::match_else_for_exists_next_node_or_attribute(
&self.data_model_name(),
placeholder,
),
}
}
fn replace_with_nodes(&self, placeholder: &str) -> Vec<trait_utils_mod::Node> {
match placeholder {
_ => trait_utils_mod::match_else_for_replace_with_nodes(
&self.data_model_name(),
placeholder,
),
}
}
fn process_sub_template(
&self,
template_name: &str,
_sub_templates: &Vec<trait_utils_mod::SubTemplate>,
) -> Vec<trait_utils_mod::Node> {
log::info!("{}", template_name);
match template_name {
_ => trait_utils_mod::match_else_for_process_sub_template(
&self.data_model_name(),
template_name,
),
}
}
}
pub fn encode_html_script_node(input: &str) -> String {
input.replace("</script>", "\\x3c/script>")
}
pub fn decode_html_script_node(input: &str) -> String {
input.replace("\\x3c/script>", "</script>")
}
pub fn decode_5_xml_control_characters(input: &str) -> String {
input
.replace(""", "\"")
.replace("'", "'")
.replace("<", "<")
.replace(">", ">")
.replace("&", "&")
}
pub fn encode_5_xml_control_characters(input: &str) -> String {
input
.replace("&", "&")
.replace("\"", """)
.replace("'", "'")
.replace("<", "<")
.replace(">", ">")
}
#[allow(dead_code)]
fn url_s_zero_to_empty(number: usize) -> String {
if number == 0 {
s!()
} else {
s!(number)
}
}