tsain-pattern 0.1.0

Chain TypeScript and Rust in fast and secure way
Documentation
use crate::*;

/// Format List of (Comment, Script) into a Script
pub(crate) fn format_script(head: String, list: Vec<(String, String)>) -> String {
    let mut script = head;
    linebreak(&mut script);

    for (comment, part) in list {
        if !part.trim().is_empty() {
            if !comment.is_empty() {
                script.push_str(&comment);
                linebreak(&mut script);
            }
            script.push_str(&part);
            linebreak2(&mut script);
        }
    }

    script
}

pub(crate) trait PropsFormatter {
    fn props_head_script(&self, props: &PropsPattern, var_id: Option<u32>) -> String;

    /// List of (Comment, Script) by parts
    fn props_script_list(&self, props: &PropsPattern, var_id: Option<u32>)
        -> Vec<(String, String)>;

    fn format_type_script(&self, props: &PropsPattern, var_id: Option<u32>) -> String {
        format_script(
            self.props_head_script(props, var_id),
            self.props_script_list(props, var_id),
        )
    }

    fn as_variant_script(
        &self,
        props: &PropsPattern,
        enum_ts_name: &str,
        enum_type_args: &str,
        var_id: u32,
    ) -> String;
}

pub(crate) struct DefaultPropsFormatter;