<commit_before>'use strict';

const util     = require('util');
const path     = require('path');
const HTMLRenderer = require('./HTMLRenderer');
const render   = require('./render');
const akasha   = require('./index');
const co       = require('co');
const mahaPartial = require('mahabhuta/maha/partial');

const log   = require('debug')('akasha:jsonRenderer');
const error = require('debug')('akasha:error-jsonRenderer');

class JSONRenderer extends HTMLRenderer {
    constructor() {
        super(".html.json", /^(.*\.html)\.(json)$/);
    }

    renderSync(text, metadata) {
        var json = JSON.parse(text);
        return mahaPartial.doPartialSync(metadata.JSONFormatter, { data: json });
        // return akasha.partialSync(config, metadata.JSONFormatter, { data: json });
    }

    render(text, metadata) {
        return co(function* () {
            var json = JSON.parse(text);
            // console.log(`JSONRenderer ${text} ==> ${util.inspect(json)}`);
            // console.log(`JSONRenderer JSONFormatter ${metadata.JSONFormatter}`);
            return yield mahaPartial.doPartialAsync(metadata.JSONFormatter, { data: json });
            // return yield akasha.partial(config, metadata.JSONFormatter, { data: json });
        })
        .catch(e => {
            var docpath = metadata.document ? metadata.document.path : "unknown";
            var errstack = e.stack ? e.stack : e;
            throw "Error with JSON in file "+ docpath +" "+ errstack;
        });
        /* return new Promise((resolve, reject) => {
            try {
                var json = JSON.parse(text);
                resolve(akasha.partial(metadata.JSONFormatter, { data: json }));
            } catch(e) {
                var docpath = metadata.document ? metadata.document.path : "unknown";
                var errstack = e.stack ? e.stack : e;
                reject("Error with EJS in file "+ docpath +" "+ errstack);
            }
        }); */
    }

    /**
     * We cannot allow PHP code to run through Mahabhuta.
     * /
    doMahabhuta(fpath) {
        if (/\.php\.ejs$/.test(fpath))
            return false;
        else
            return true;
    } */
}

module.exports = new JSONRenderer();<commit_msg>Cleanup<commit_after>'use strict';

const util     = require('util');
const path     = require('path');
const HTMLRenderer = require('./HTMLRenderer');
const render   = require('./render');
const akasha   = require('./index');
const co       = require('co');
const mahaPartial = require('mahabhuta/maha/partial');

const log   = require('debug')('akasha:jsonRenderer');
const error = require('debug')('akasha:error-jsonRenderer');

class JSONRenderer extends HTMLRenderer {
    constructor() {
        super(".html.json", /^(.*\.html)\.(json)$/);
    }

    renderSync(text, metadata) {
        var json = JSON.parse(text);
        return mahaPartial.doPartialSync(metadata.JSONFormatter, { data: json });
    }

    render(text, metadata) {
        return co(function* () {
            var json = JSON.parse(text);
            // console.log(`JSONRenderer ${text} ==> ${util.inspect(json)}`);
            // console.log(`JSONRenderer JSONFormatter ${metadata.JSONFormatter}`);
            return yield mahaPartial.doPartialAsync(metadata.JSONFormatter, { data: json });
        })
        .catch(e => {
            var docpath = metadata.document ? metadata.document.path : "unknown";
            var errstack = e.stack ? e.stack : e;
            throw "Error with JSON in file "+ docpath +" "+ errstack;
        });
    }
}

module.exports = new JSONRenderer();
{'fraction_non_alphanumeric': 0.15380328782390637, 'fraction_numerical': 0.0, 'mean_word_length': 2.4321223709369026, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 8, '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': '295141', 'n_tokens_mistral': 995, 'n_tokens_neox': 983, 'n_words': 227}