Trait HtmlTemplatingDataTrait

Source
pub trait HtmlTemplatingDataTrait {
    // Required methods
    fn data_model_name(&self) -> String;
    fn replace_with_string(
        &self,
        placeholder: &str,
        subtemplate_name: &str,
        row_number: usize,
    ) -> String;

    // Provided methods
    fn replace_with_url(
        &self,
        placeholder: &str,
        _subtemplate_name: &str,
        _pos_cursor: usize,
    ) -> UrlUtf8EncodedString { ... }
    fn exists_next_node_or_attribute(&self, placeholder: &str) -> bool { ... }
    fn replace_with_nodes(&self, placeholder: &str) -> Vec<Node> { ... }
    fn process_sub_template(
        &self,
        template_name: &str,
        _sub_templates: &Vec<SubTemplate>,
    ) -> Vec<Node> { ... }
}
Expand description

the trait has only methods that can be implemented (overridden) It is not possible to define a method as “override forbidden” because the data model is always different and is known only to the project. if not implemented, the default functions below will be used.

Required Methods§

Source

fn data_model_name(&self) -> String

name of data model for debugging

Source

fn replace_with_string( &self, placeholder: &str, subtemplate_name: &str, row_number: usize, ) -> String

returns a String to replace the next text-node or attribute value use macro s!() for a normal string

Provided Methods§

Source

fn replace_with_url( &self, placeholder: &str, _subtemplate_name: &str, _pos_cursor: usize, ) -> UrlUtf8EncodedString

same as replace_with_string, but return url exclusively for attributes value of href and src the url must be encoded in the beginning because it encodes segments of url prior to being composed together. use macro url_u!() to create an url, very like format! I try to avoid String here to force the developer to not forget to url_encode

Source

fn exists_next_node_or_attribute(&self, placeholder: &str) -> bool

boolean : is the next node existing or not: “wb_” or “sb_”

Source

fn replace_with_nodes(&self, placeholder: &str) -> Vec<Node>

returns a vector of Nodes to replace the next Node

Source

fn process_sub_template( &self, template_name: &str, _sub_templates: &Vec<SubTemplate>, ) -> Vec<Node>

process sub-template

Implementors§