<commit_before>var req = require;
var onLoad = require('./onLoad');

// dust.debugLevel = 'DEBUG';

module.exports = function createEngine(config, viewEngine) {
    var dust = config.dust || req('dustjs-linkedin');
    config.dust = dust;

    var onLoadFunc = onLoad(config);
    if (onLoadFunc) {
        dust.onLoad = onLoadFunc;
    }

    return {
        stream: function(path, templateData) {
            if (!templateData) {
                templateData = {};
            }

            return dust.stream(path, templateData);
        },
        buildTemplateData: function(path, templateData, context) {
            var parentDustContext = context.dustContext;
            if (parentDustContext) {
                templateData = parentDustContext.push(templateData);
            }
            templateData.templateName = path;
            templateData.stream = context.stream; // Keep a reference to the underlying stream that we are writing to
            return templateData;
        }
    };
};<commit_msg>use dust global to keep a reference to the stream<commit_after>var req = require;
var onLoad = require('./onLoad');

// dust.debugLevel = 'DEBUG';

module.exports = function createEngine(config, viewEngine) {
    var dust = config.dust || req('dustjs-linkedin');
    config.dust = dust;

    var onLoadFunc = onLoad(config);
    if (onLoadFunc) {
        dust.onLoad = onLoadFunc;
    }

    return {
        stream: function(path, templateData) {
            if (!templateData) {
                templateData = {};
            }

            return dust.stream(path, templateData);
        },
        buildTemplateData: function(path, templateData, context) {
            var base = context.dustContext || dust.makeBase({
                stream: context.stream
            });

            templateData = base.push(templateData);
            templateData.templateName = path;
            return templateData;
        }
    };
};
{'fraction_non_alphanumeric': 0.10734463276836158, 'fraction_numerical': 0.0, 'mean_word_length': 2.0822784810126582, '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': '4517948', 'n_tokens_mistral': 527, 'n_tokens_neox': 507, 'n_words': 124}