Search code examples
javascriptdust.js

Dust.js @sep example not working


I tried using Dust.js template engine with the first page hello world and it failed to use the {@sep} markings, the template was compiled and produced output, but not the commas {@sep},{/sep}

http://jsfiddle.net/t1qh9abw/

$(document).ready(function () {

    var template = "Dust does {#features}{name}{@sep},{/sep}{/features}!"

    var compiled = dust.compile(template, "test");
    dust.loadSource(compiled);

    dust.render("test", {
      features: [
        {name: "async"},
        {name: "helpers"},
        {name: "filters"},
        {name: "a little bit of logic"},
        {name: "and more"}
      ]
    },
    function (err, out) {
        document.getElementById('container').textContent = out;
    });
});

The {@sep},{/sep} does not seem to produce anything, the output is

Dust does asynchelpersfiltersa little bit of logicand more!

While the example output from the actual home page http://www.dustjs.com/ seems to be working just fine, which suggest there is something fishy in my own code or the version I am using.

Then I thought the CDN may be serving an outdated file, so I tried using directly the latest release from GitHub using rawgit.com link

http://rawgit.com/linkedin/dustjs/master/dist/dust-full.js

The example is here : http://jsfiddle.net/5apgp1sf/ and it still does not output the @sep tag contents.

What went wrong? I can't see the commas, so should I go shopping glasses or file a bug report?


Solution

  • Ok, I will answer this question myself. I did some research on the Dustjs homepage and figured it out.

    It was not obvious, that even if there were packages like

    • dust-core
    • dust-full

    The full package does not seem to actually contain the @sepdefinition, even if that is the frontpage example.

    So, importing the file dust-helpers.js solved this problem for me.