dust.js + enyo example

by Ryan Duffy

HTML

<script src="https://cdn.jsdelivr.net/dustjs/2.0.2/dust-full.min.js"></script>

JavaScript

enyo.kind({
    name: "dust.Template",
    kind: "Control",
    allowHtml: true,
    
    template: "",
    properties: "",
    
    observers: {
        compile: ["template"],
        renderDust: ["properties"]
    },
    
    compile: function() {
        if(this.template) {
            var compiled = dust.compile(this.template, this.id);
            dust.loadSource(compiled);
            this.renderDust();
        }
    },
    renderDust: function() {
        if(this.template) {
            dust.render(this.id, this.properties || {}, this.bindSafely(function(err, out) {
                this.setContent(out);
            }));
        }
    }
});

var t = new dust.Template();
t.renderInto(document.body);

t.set("template", "Hello, {name}");
t.set("properties", {name:"Patrick"});