<commit_before>#!/usr/bin/env node

'use strict';

var fs     = require('fs'),
    path   = require('path'),

    pastry = require('../../build/nodejs.js'),
    utils  = require('./utils.js'),
    prefix = 'src/pastry/template/',

    RE_acceptSuffix = /\.(html|htm|ptmpl)$/;

function getFilename (path) {
    var result = path.replace(RE_acceptSuffix, '');
    return result.match(/(\w*)$/)[0];
}

function compileTemplates () {
    try {
        utils.walkFiles(prefix, function (file) {
            if (!RE_acceptSuffix.test(file)) { // 只接受 template 文件
                return;
            }
            var content = fs.readFileSync(file).toString(),

                outputFilename = file
                    .replace(RE_acceptSuffix, function (/* suffix */) {
                        return '.js';
                    }),

                outputFileId = prefix.replace('src/', '') + getFilename(file),

                moduleStr = '/* jshint ignore:start */\n' +
                    'define("%s", [' +
                        '"pastry/pastry",' +
                        '"pastry/html/escape"' +
                    '], function (' +
                        'helper' +
                    ') {' +
                        'return %s' +
                    '});' +
                    '\n/* jshint ignore:end */',
                resultStr = pastry.template.compile(content).toString()
                    .replace(/^\s*function\s+anonymous\(\s*obj\,\s*helper\s*\,\s*ne\s*\)\s*\{/, 'function(obj, ne){')
                    .replace(/\\n\s*/g, '');

            console.log(
                file,
                outputFilename// ,
                // outputFileId,
                // content,<commit_msg>bugfix for template compiling with nodejs above version 0.12.0<commit_after>#!/usr/bin/env node

'use strict';

var fs     = require('fs'),
    path   = require('path'),

    pastry = require('../../build/nodejs.js'),
    utils  = require('./utils.js'),
    prefix = 'src/pastry/template/',

    RE_acceptSuffix = /\.(html|htm|ptmpl)$/;

function getFilename (path) {
    var result = path.replace(RE_acceptSuffix, '');
    return result.match(/(\w*)$/)[0];
}

function compileTemplates () {
    try {
        utils.walkFiles(prefix, function (file) {
            if (!RE_acceptSuffix.test(file)) { // 只接受 template 文件
                return;
            }
            var content = fs.readFileSync(file).toString(),

                outputFilename = file
                    .replace(RE_acceptSuffix, function (/* suffix */) {
                        return '.js';
                    }),

                outputFileId = prefix.replace('src/', '') + getFilename(file),

                moduleStr = '/* jshint ignore:start */\n' +
                    'define("%s", [' +
                        '"pastry/pastry",' +
                        '"pastry/html/escape"' +
                    '], function (' +
                        'helper' +
                    ') {' +
                        'return %s' +
                    '});' +
                    '\n/* jshint ignore:end */',

                // bugfix for node.js version 0.12.0 {
                //     * new Function(){} => toString() :
                //         * additional line break;
                //         * additional `/**/`;
                // }
                resultStr = pastry.template.compile(content).toString()
                    .replace(/function\s+anonymous\s*\([^){]*\)\s*\{/, 'function(obj, ne){')
                    .replace(/\\n\s+/g, '')
                    .replace(/\/\*\*\//g, '');

            console.log(
                file,
                outputFilename// ,
                // outputFileId,
                // content,
{'fraction_non_alphanumeric': 0.16662187583982802, 'fraction_numerical': 0.0026874496103198066, 'mean_word_length': 1.2181168057210965, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, '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': '2100073', 'n_tokens_mistral': 1078, 'n_tokens_neox': 993, 'n_words': 170}