How to use the nunjucks.env function in nunjucks

To help you get started, we’ve selected a few nunjucks examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github WikiWatershed / model-my-watershed / src / mmw / js / src / core / filters.js View on Github external
return new Date(date).getFullYear();
});

nunjucks.env.addFilter('toDateWithoutTime', function(date) {
    var fullDate = new Date(date);

    return (fullDate.getUTCMonth() + 1) + '/' +
           fullDate.getUTCDate() + '/' +
           fullDate.getUTCFullYear();
});

nunjucks.env.addFilter('toTimeAgo', function(date) {
    return moment(date).fromNow();
});

nunjucks.env.addFilter('split', function(str, splitChar, indexToReturn) {
    var items = str.split(splitChar);

    return items[indexToReturn];
});

nunjucks.env.addFilter('toFriendlyBytes', function(bytes) {
    var roundToOneDecimal = function(x) { return Math.round(x * 10) / 10; };

    if (bytes < 1024) {
        return bytes + ' Bytes';
    }

    bytes /= 1024;

    if (bytes < 1024) {
        return roundToOneDecimal(bytes) + ' KB';
github WikiWatershed / model-my-watershed / src / mmw / js / src / modeling / filters.js View on Github external
"use strict";

var nunjucks = require('nunjucks'),
    modUtils = require('./modificationConfigUtils');

nunjucks.env.addFilter('modName', function(val) {
    return modUtils.getHumanReadableName(val);
});

nunjucks.env.addFilter('modShortName', function(val) {
    return modUtils.getHumanReadableShortName(val);
});

nunjucks.env.addFilter('modSummary', function(val) {
    return modUtils.getHumanReadableSummary(val);
});

nunjucks.env.addFilter('modFill', function(val) {
    return modUtils.getDrawOpts(val).fillColor;
});
github WikiWatershed / model-my-watershed / src / mmw / js / src / modeling / analyze / filters.js View on Github external
"use strict";

var nunjucks = require('nunjucks');

nunjucks.env.addFilter('toFixed', function(val, digits) {
    return val.toFixed(digits);
});
github WikiWatershed / model-my-watershed / src / mmw / js / src / modeling / filters.js View on Github external
"use strict";

var nunjucks = require('nunjucks'),
    modUtils = require('./modificationConfigUtils');

nunjucks.env.addFilter('modName', function(val) {
    return modUtils.getHumanReadableName(val);
});

nunjucks.env.addFilter('modShortName', function(val) {
    return modUtils.getHumanReadableShortName(val);
});

nunjucks.env.addFilter('modSummary', function(val) {
    return modUtils.getHumanReadableSummary(val);
});

nunjucks.env.addFilter('modFill', function(val) {
    return modUtils.getDrawOpts(val).fillColor;
});