summaryrefslogtreecommitdiff
path: root/share/rust/template/macros.rs.tera
blob: 7a65e0fd894dbd5300e8543c9552399e9de3217b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
{%- macro builder(stepfn, step) -%}
{{stepfn}}::Builder::default()
    {% for part in step.parts %}{% if part.CapturedText is defined -%}
        {%- set name = part.CapturedText.name -%}
        {%- set text = part.CapturedText.text -%}
        {%- set type = step.types[name] | default(value='text') -%}
        .{{name}}(
            {% if type in ['number', 'int', 'uint'] %}{{text}}
            {%- elif type in ['text', 'word']%}
            // "{{text | commentsafe }}"
            &base64_decode("{{text | base64}}"
        )
            {%- elif type in ['file'] %}
            {
                use std::path::PathBuf;
                // {{ text | commentsafe }}
                let target_name: PathBuf = base64_decode("{{ text | base64 }}").into();
                SUBPLOT_EMBEDDED_FILES
                    .iter()
                    .find(|df| df.name() == target_name)
                    .expect("Unable to find file at runtime")
                    .clone()
            }
            {%- else %} /* WOAH unknown type {{step.types[name]}} */ {{text}}
            {%- endif %}
        )
    {% endif -%}
    {% endfor -%}
        .build(format!("{} {}", "{{step.kind | lower}}", base64_decode("{{step.text | base64}}")))
{%- endmacro builder -%}