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}}");
        const constructorSignatures = [
            {% for initializer in ingredient.initializers -%}
            [{%- for param in initializer.params -%}"{{info.requiredTypes[param]}}"{%- unless forloop.last %},{% endunless -%}{% endfor %}]
            {%- unless forloop.last %},
            {% endunless -%}
            {%- endfor %}
        ];
        {% for initializer in ingredient.initializers %}
        {% if forloop.first %}if{% else %}else if{% endif %} (this.argsMatchSignature(args, constructorSignatures[{{forloop.index0}}])) {
            {% for required in ingredient.required -%}
            {% if initializer.params contains required.name %}
            {% for param in initializer.params %}
                {% if param == required.name %}
                    {% assign paramIndex = forloop.index0 %}
                {% endif %}
            {% endfor %}
            {%- if info.isVararg[required.name] == true %}
            this.setRequired("{{required.name}}", args.slice({{paramIndex}}));
            {%- else %}
            this.setRequired("{{required.name}}", args[{{paramIndex}}]);
            {%- endif -%}
            {%- else %}
            this.setRequired("{{required.name}}", {{required.default | tsvalue:required.type}});
            {%- endif -%}
            {%- endfor %}
        }
        {% endfor %}
        {% if ingredient.initializers.size == 0 %}
        {%- for required in ingredient.required %}
        this.setRequired("{{required.name}}", {{required.default | tsvalue:required.type}});
        {%- endfor %}
        {% endif %}
        {% if ingredient.keyed and ingredient.defaultKey %}
        this.setKey(this.properties.get("{{ingredient.defaultKey}}"));
        {% 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 -%}
    ) {
        const copy = this.duplicate();
        {%- if optional.compound != true -%}
            {%- if optional.type != 'flag' %}
        copy.setOptional("{{optional.name}}", {{optional.repeatable}}, {{optional.name}});
            {%- else %}
        copy.setOptional("{{optional.name}}", {{optional.repeatable}}, true);
            {%- endif -%}
        {%- else %}
        copy.setCompoundOptional("{{optional.name}}", {{optional.repeatable}}
        {%- for param in optional.params -%}
        , "{{param.name}}", {{param.name}}
        {%- endfor -%});
        {%- endif %}
        return copy;
    }
    {% endfor %}
}
{% for key in info.constantKeys %}
{{ingredientName}}.{{key}} = "{{info.constantValues[forloop.index0]}}";
{% endfor %}
exports.{{ingredientName}} = {{ingredientName}};




© 2015 - 2024 Weber Informatics LLC | Privacy Policy