<commit_before>'use strict';

var ejs     = require('ejs'),
    path    = require('path'),
    gutil   = require('gulp-util'),
    through = require('through2');

module.exports = function (options, settings) {
    options = options || {};
    settings = settings || {};

    return through.obj(function (file, enc, cb) {
        if (file.isNull()) {
            this.push(file);
            return cb();
        }

        if (file.isStream()) {
            this.emit(
                'error',
                new gutil.PluginError('gulp-ejs', 'Streaming not supported')
            );
        }

        options = file.data || options;
        options.filename = file.path;

        try {
            var out = ejs.compile(file.contents.toString(), options).toString();
            if (settings.namespace) {
                var templateName = ((path.sep === '/') ? file.relative : file.relative.replace(path.sep, '/'))
                    .slice(0, -path.extname(file.path).length);
                out = settings.namespace + '["' + templateName + '"]=' + out + ';';
            }
            file.contents = new Buffer(out);

            if (typeof settings.ext !== 'undefined') {
                file.path = gutil.replaceExtension(file.path, settings.ext);
            }
        } catch (err) {
            this.emit('error', new gutil.PluginError('gulp-ejs', err.toString()));
        }

        this.push(file);
        cb();
    });
};


<commit_msg>Incluimos la posibilidad de especificar una función como namespace para una asignación avanzada de la función resultante: function(name, code) {}<commit_after>'use strict';

var ejs     = require('ejs'),
    path    = require('path'),
    gutil   = require('gulp-util'),
    through = require('through2');

module.exports = function (options, settings) {
    options = options || {};
    settings = settings || {};

    return through.obj(function (file, enc, cb) {
        if (file.isNull()) {
            this.push(file);
            return cb();
        }

        if (file.isStream()) {
            this.emit(
                'error',
                new gutil.PluginError('gulp-ejs', 'Streaming not supported')
            );
        }

        options = file.data || options;
        options.filename = file.path;

        try {
            var codeString = ejs.compile(file.contents.toString(), options).toString();
            if (settings.namespace) {
                var templateName = ((path.sep === '/') ? file.relative : file.relative.replace(path.sep, '/'))
                    .slice(0, -path.extname(file.path).length);
                if (typeof(settings.namespace) === 'function') {
                    codeString = settings.namespace(templateName, codeString);
                } else {
                    codeString = settings.namespace + '["' + templateName + '"]=' + out + ';';
                }
            }
            file.contents = new Buffer(out);

            if (typeof settings.ext !== 'undefined') {
                file.path = gutil.replaceExtension(file.path, settings.ext);
            }
        } catch (err) {
            this.emit('error', new gutil.PluginError('gulp-ejs', err.toString()));
        }

        this.push(file);
        cb();
    });
};



{'fraction_non_alphanumeric': 0.1519532451553368, 'fraction_numerical': 0.0012303906490310674, 'mean_word_length': 1.7535986452159187, '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': '4948183', 'n_tokens_mistral': 913, 'n_tokens_neox': 881, 'n_words': 184}