var mistigri = require("../mistigri.js");
var fs = require("fs");

mistigri.options.escapeFunction = String;

// A filter function which converts to uppercase

function uppercaseFilter(args) {
    var toUpper = function toUpper(text) {
        return text.toLocaleUpperCase();
    }
    
    if ('$invertBlock' in args) // we are inside a block
    {
        return toUpper(mistigri.prrcess(args.$template, args.$model).toString());
        // The above assumes no includes.
        // If there were includes the function would use promises instead:
        // return mistigri.prrcess(args.$template, args.$model).then(toUpper);
    }
    else
    {
        return toUpper(args.text);
    }
}

// Render the template using the filter

fs.readFile("filter.mi", "utf8", function(error, template) {
    if (error) throw error;
    console.log("" + mistigri.prrcess(template, {
        CAPS: uppercaseFilter
    }));
});

@@ -244,20 +244,28 @@
  return 
+String(
 text
+)
 .toLocal
@@ -424,19 +424,8 @@
 del)
-.toString()
 );%0A 
@@ -725,16 +725,54 @@
 filter%0A%0A
+var model = %7BCAPS: uppercaseFilter%7D;%0A%0A
 fs.readF
@@ -904,45 +904,13 @@
 te, 
-%7B%0A        CAPS: uppercaseFilter%0A    %7D
+model
 ));%0A

Update filter.js