All Downloads are FREE. Search and download functionalities are using the official Maven repository.

templates.ts.ingredient.liquid Maven / Gradle / Ivy

There is a newer version: 0.4.0
Show newest version
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
{% if ingredient.keyed -%}
    {%- assign superclass = 'KeyedIngredient' -%}
{%- else -%}
    {%- assign superclass = 'Ingredient' -%}
{%- endif -%}
{%- assign ingredientName = ingredient.name | append:options.ingredientPostfix -%}
const {{superclass}} = require("recipe-ts-runtime").{{superclass}};
{% for type in info.nonPrimitiveTypes -%}
const {{type}} = require("./{{type}}").{{type}};
{% endfor %}

class {{ingredientName}} extends {{superclass}} {
    constructor(...args) {
        super("{{ingredient.name}}", "{{domain}}");
        {% for initializer in ingredient.initializers %}
        {% if forloop.first %}if{% else %}else if{% endif %} (args.length === {{initializer.params.size}}
        {%- for param in initializer.params -%}
            {%- assign type = info.requiredTypes[param] -%}
            {% raw %} {% endraw %}
            {%- if type == 'string' or type == 'int' or type == 'float' or type == 'boolean' -%}
                && typeof args[{{forloop.index0}}] === "{{type | tstype}}"
            {%- else -%}
                && (args[{{forloop.index0}}] instanceof {{type}})
            {%- endif -%}
        {%- endfor -%}
        ) {
            {% for required in ingredient.required -%}
            {%- for param in initializer.params -%}
            {%- if required.name == param %}
            this.setRequired("{{required.name}}", args[{{forloop.index0}}]);
            {%- else %}
            this.setRequired("{{required.name}}", {{required.default | tsvalue:required.type}});
            {%- endif -%}
            {%- endfor -%}
            {%- endfor %}
        }
        {% endfor %}
        {% if ingredient.initializers.size == 0 %}
        {%- for required in ingredient.required %}
        this.setRequired("{{required.name}}", {{required.default | tsvalue:required.type}});
        {%- endfor %}
        {% endif %}
    }

    {% for optional in ingredient.optionals %}
    with{{optional.name | capitalize}}(
        {%- if optional.compound != true -%}
            {%- if optional.type != 'flag' -%}
            {{ optional | jsparam }}
            {%- endif -%}
        {%- else -%}
            {%- for param in optional.params -%}
                {{ param | jsparam }}
                {%- unless forloop.last -%}, {% endunless -%}
            {%- endfor -%}
        {%- endif -%}
    ) {
        {%- if optional.compound != true -%}
            {%- if optional.type != 'flag' %}
        this.setOptional("{{optional.name}}", {{optional.repeatable}}, {{optional.name}});
            {%- else %}
        this.setOptional("{{optional.name}}", {{optional.repeatable}}, true);
            {%- endif -%}
        {%- else %}
        this.setCompoundOptional("{{optional.name}}", {{optional.repeatable}}
        {%- for param in optional.params -%}
        , "{{param.name}}", {{param.name}}
        {%- endfor -%});
        {%- endif %}
        return this;
    }
    {% endfor %}
}

exports.{{ingredientName}} = {{ingredientName}};




© 2015 - 2024 Weber Informatics LLC | Privacy Policy