<commit_before>/**
 *   fis.baidu.com
 */
var fs = require('fs');
var crox = require('crox.mod');
var helper = require('crox.mod/bin/helper');
var precompiler = require('crox.mod/lib/precompile-node').precompile;
var jsBeautify = require('js-beautify').js_beautify;

function doJsBeautify(str) {
    var opts = {
        "indent_size": 4,
        "indent_char": " ",
        "indent_level": 0,
        "indent_with_tabs": false,
        "preserve_newlines": true,
        "max_preserve_newlines": 10,
        "jslint_happy": false,
        "brace_style": "collapse",
        "keep_array_indentation": false,
        "keep_function_indentation": false,
        "space_before_conditional": true,
        "break_chained_methods": false,
        "eval_code": false,
        "unescape_strings": false
    };
    return jsBeautify(str, opts);
}

var compilers = {
    vm: crox.compileToVM,
    php: crox.compileToPhp,
    js: function(tpl) {return crox.compile(tpl, getOptions()).toString()},
    cmd: function(tpl) {return helper.compileToCMD(tpl, getOptions())},
    amd: function(tpl) {return helper.compileToAMD(tpl, getOptions())},
    commonjs: function(tpl) {return helper.compileToCommonJS(tpl, getOptions())}
};

compilers.commonjs = compilers.commonjs;
compilers.seajs = compilers.cmd;
compilers.requirejs = compilers.amd;
compilers.vm2 = compilers.vm;

function getOptions() {
    return {
        htmlEncode: outHtmlEncode,
        modulePrefix: outModulePrefix
    }
}


module.exports = function (content, file, opts) {
    var opts = opts || {};
    var target = opts.target || 'commonjs',
        target = target.trim();
        var htmlEncode = opts.htmlEncode || '';
        var flatten = !!opts.flatten;
        var filepath = file.realpath;
        var outHtmlEncode = opts.htmlEncode;

        var compiler = compilers[target];
        var isJs = target != 'vm' && target != 'vm2' && target != 'php';
        var compiled;

        if (isJs && target != 'js') {
            if (opts.flatten) {
                fs.writeFileSync(filepath, precompiler(file.realpath));
                compiled = compiler(filepath);
                fs.writeFileSync(filepath, content);
            } else {
                compiled = compiler(filepath);
            }
        } else {
            if (opts.flatten) {
                content = precompiler(filepath);
            }
            compiled = compiler(content);
        }
        if (isJs) {
            compiled = doJsBeautify(compiled);
        }
        if (target == 'vm2') {
            compiled = compiled.replace(/#\{end\}/g, '#end');
        }


        return compiled;
};<commit_msg>fix htmlEncode function<commit_after>/**
 *   fis.baidu.com
 */
var fs = require('fs');
var crox = require('crox.mod');
var helper = require('crox.mod/bin/helper');
var precompiler = require('crox.mod/lib/precompile-node').precompile;
var jsBeautify = require('js-beautify').js_beautify;

function doJsBeautify(str) {
    var opts = {
        "indent_size": 4,
        "indent_char": " ",
        "indent_level": 0,
        "indent_with_tabs": false,
        "preserve_newlines": true,
        "max_preserve_newlines": 10,
        "jslint_happy": false,
        "brace_style": "collapse",
        "keep_array_indentation": false,
        "keep_function_indentation": false,
        "space_before_conditional": true,
        "break_chained_methods": false,
        "eval_code": false,
        "unescape_strings": false
    };
    return jsBeautify(str, opts);
}

var compilers = {
    vm: crox.compileToVM,
    php: crox.compileToPhp,
    js: function(tpl) {return crox.compile(tpl, getOptions()).toString()},
    cmd: function(tpl) {return helper.compileToCMD(tpl, getOptions())},
    amd: function(tpl) {return helper.compileToAMD(tpl, getOptions())},
    commonjs: function(tpl) {return helper.compileToCommonJS(tpl, getOptions())}
};

compilers.commonjs = compilers.commonjs;
compilers.seajs = compilers.cmd;
compilers.requirejs = compilers.amd;
compilers.vm2 = compilers.vm;

function getOptions() {
    return {
        htmlEncode: outHtmlEncode,
        modulePrefix:''
    }
}

var outHtmlEncode = '';

module.exports = function (content, file, opts) {
    var opts = opts || {};
    var target = (opts.target || 'commonjs').trim();
    var htmlEncode = outHtmlEncode = opts.htmlEncode || '';
    var flatten = !!opts.flatten;
    var filepath = file.realpath;

    var compiler = compilers[target];
    var isJs = target != 'vm' && target != 'vm2' && target != 'php';
    var compiled;

    if (isJs && target != 'js') {
        if (opts.flatten) {
            fs.writeFileSync(filepath, precompiler(file.realpath));
            compiled = compiler(filepath);
            fs.writeFileSync(filepath, content);
        } else {
            compiled = compiler(filepath);
        }
    } else {
        if (opts.flatten) {
            content = precompiler(filepath);
        }
        compiled = compiler(content);
    }
    if (isJs) {
        compiled = doJsBeautify(compiled);
    }
    if (target == 'vm2') {
        compiled = compiled.replace(/#\{end\}/g, '#end');
    }


    return compiled;
};
{'fraction_non_alphanumeric': 0.14119472459270752, 'fraction_numerical': 0.0027152831652443757, 'mean_word_length': 2.596234309623431, 'pattern_counts': {'":': 28, '<': 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': '2778609', 'n_tokens_mistral': 1633, 'n_tokens_neox': 1614, 'n_words': 329}