<commit_before>/**
 * Router module.
 */
var config = require('./config'),
    urlLib = require('url'),
    http = require('http'),
    fs = require('fs'),
    dust = require('dustjs-linkedin'),
    dive = require('dive'),
    path = require('path'),
    routes = {
        get: {},
        post: {}
    },
    varRoutes = {
        get: [],
        post: []
    };

/**
 * Compile dust templates.
 */
dive(config.viewPath, {
    all: false,
    directories: false,
    files: true,
    recursive: true
}, function(err, file) {
    if (err) throw err;

    var filename, ext;
    ext = path.extname(file);
    if (ext === '.dust') {
        filename = path.basename(file, '.dust');

        fs.readFile(file, function(err, data) {
            if (err) {
                throw err;
            } else {
                dust.loadSource(dust.compile(data.toString(), filename));
                console.log('Compiling template: ' + filename);
            }
        });
    }
});

/**
 * Extending http response object to be able to send view files.
 */
http.ServerResponse.prototype.sendView = function(view, tplVars) {
    var res = this;
    dust.render(view, tplVars, function(err, out) {
        if (err) {
            console.error(err);
        } else {
            res.end(out);<commit_msg>Adding base context for dust<commit_after>/**
 * Router module.
 */
var config = require('./config'),
    urlLib = require('url'),
    http = require('http'),
    fs = require('fs'),
    dust = require('dustjs-linkedin'),
    dive = require('dive'),
    path = require('path'),
    routes = {
        get: {},
        post: {}
    },
    varRoutes = {
        get: [],
        post: []
    };

// Set up a base context with a global helper function
var base = dust.makeBase(config);

/**
 * Compile dust templates.
 */
dive(config.viewPath, {
    all: false,
    directories: false,
    files: true,
    recursive: true
}, function(err, file) {
    if (err) throw err;

    var filename, ext;
    ext = path.extname(file);
    if (ext === '.dust') {
        filename = path.basename(file, '.dust');

        fs.readFile(file, function(err, data) {
            if (err) {
                throw err;
            } else {
                dust.loadSource(dust.compile(data.toString(), filename));
                console.log('Compiling template: ' + filename);
            }
        });
    }
});

/**
 * Extending http response object to be able to send view files.
 */
http.ServerResponse.prototype.sendView = function(view, tplVars) {
    var res = this;
    dust.render(view, base.push(tplVars)config.js, function(err, out) {
        if (err) {
            console.error(err);
        } else {
            res.end(out);
{'fraction_non_alphanumeric': 0.1566531514928124, 'fraction_numerical': 0.0, 'mean_word_length': 1.9824175824175825, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '160777', 'n_tokens_mistral': 841, 'n_tokens_neox': 830, 'n_words': 200}