<commit_before>'use strict';

/******************
 *  Dependencies  *
 ******************/

var readDirFiles = require('read-dir-files');
var handlebars = require('handlebars');
var path = require('path');
var extend = require('extend');
var cheerio = require('cheerio');
var del = require('del');
var fs = require('fs');
var mkdirp = require('mkdirp');
var browserify = require('browserify');
var hbsfy = require('hbsfy');
var debowerify = require('debowerify');
var installify = require('installify');
var envify = require('envify');
var sass = require('node-sass');
var chokidar = require('chokidar');
var staticServer = require('node-static');
var http = require('http');
var tinylr = require('tiny-lr');
var watchify = require('watchify');
var normalizeSettings = require('./normalize-settings');
var uglifyjs = require('uglify-js');
var neat = require('node-neat');
var bourbon = require('node-bourbon');
var ncp = require('ncp');
var log = require('./logger');
var zlib = require('zlib');
var postcss = require('postcss');
var cssgrace = require('cssgrace');
var autoprefixer = require('autoprefixer-core');

/***************
 *  Variables  *
 ***************/

var settings;
var lrSnippet = '<script>document.write(\'<script src=\"http://\' + (location.host || \'localhost\').split(\':\')[0] + \':35729/livereload.js?snipver=1\"></\' + \'script>\')</script>';

/**************
 *  Partials  *
 **************/

/**
 * Recursively registers all partials in the given /partials folder
 * @param {Object} partials A list of loaded partials files
 * @param {Array} [varname] [description]
 */
function registerPartials(partials, partialPath) {
    var name;

    partialPath = partialPath || [];

    for (var item in partials) {
        
        // Register a partial
        if (path.extname(item) === '.hbs') {
            partialPath.push(path.basename(item));
            name = partialPath.join('/');
            name = path.basename(name, '.hbs');
            handlebars.registerPartial(name, partials[item]);
            partialPath.pop();
        }

        // Continue traversing directory
        else if (partials[item] === Object(partials[item])) {
            partialPath.push(item);
            registerPartials(partials[item], partialPath);
        }
    }

    partialPath.pop();
}

/**********
 *  Site  *
 **********/

/**
 * Tries to compile the given handlebars hbs
 * @param {String} content The hbs to template
 */
function handlebarsCompile(content) {
    var result;

    try {
        result = handlebars.compile(content);
    } catch (err) {
        log('Handlebars', err, 'error');
        result = handlebars.compile('<span></span>');
    }

    return result;
}

/**
 * 
 * @param {type} [name] [description]
 */
function processSite(files, site, sitePath) {
    var key, pageFile, pages, templateFn, sass;
    var defaults = {};
    var keys = Object.keys(files);

    sitePath = sitePath || [];
    site = site || {};

    // Establish site entry
    if (files['index.hbs']) {

        // Key by the file's path
        sitePath.push('index.html');
        key = sitePath.join('/');
        site[key] = {
            key: key,
            template: handlebarsCompile(files['index.hbs']),
            modules: []
        };
        sitePath.pop();

        // Remove the index.hbs key
        keys.splice(keys.indexOf('index.hbs'), 1);

        // Add style
        if (files['main.scss']) {
            sass = site[key].sass = files['main.scss'];

            // Remove the main.scss key
            keys.splice(keys.indexOf('main.scss'), 1);
        }

        // Add scripts
        if (files['index.js']) {
            site[key].script = files['index.js'];
            keys.splice(keys.indexOf('index.js'), 1);
        }
    }

    // Get default data
    if (files['defaults.json']) {
        defaults = JSON.parse(files['defaults.json']);
        if (site[key]) { site[key].data = defaults; }
    }

    // Populate based on pages.json
    if (files['pages.json']) {
        pageFile = JSON.parse(files['pages.json']);

        // Get the template key
        for (var template in pageFile) {
            pages = pageFile[template];
            templateFn = handlebarsCompile(files[template]);

            // Add additional pages to site
            for (var page in pages) {
                sitePath.push(page + '.html');
                key = sitePath.join('/');
                site[key] = {
                    key: key,
                    generated: true,
                    template: templateFn,
                    data: extend({}, defaults, pages[page]),
                    sass: sass,
                    modules: [],
                    script: files['index.js']
                };
                sitePath.pop();
            }
        }

        keys.splice(keys.indexOf('pages.json'), 1);
    }

    // Continue recursing with remaining keys
    keys.forEach(function(key) {
        
        // Only recurse directories
        if (!path.extname(key)) {
            sitePath.push(key);
            processSite(files[key], site, sitePath);
            sitePath.pop();
        }
    });

    return site;
}

/****************
 *  Templating  *
 ****************/

/**
 * 
 * @param {type} [name] [description]
 */
function moduleHelper(module, object) {
    var html, doc, template;
    var data = object.data;<commit_msg>Ignore dotfiles<commit_after>'use strict';

/******************
 *  Dependencies  *
 ******************/

var readDirFiles = require('read-dir-files');
var handlebars = require('handlebars');
var path = require('path');
var extend = require('extend');
var cheerio = require('cheerio');
var del = require('del');
var fs = require('fs');
var mkdirp = require('mkdirp');
var browserify = require('browserify');
var hbsfy = require('hbsfy');
var debowerify = require('debowerify');
var installify = require('installify');
var envify = require('envify');
var sass = require('node-sass');
var chokidar = require('chokidar');
var staticServer = require('node-static');
var http = require('http');
var tinylr = require('tiny-lr');
var watchify = require('watchify');
var normalizeSettings = require('./normalize-settings');
var uglifyjs = require('uglify-js');
var neat = require('node-neat');
var bourbon = require('node-bourbon');
var ncp = require('ncp');
var log = require('./logger');
var zlib = require('zlib');
var postcss = require('postcss');
var cssgrace = require('cssgrace');
var autoprefixer = require('autoprefixer-core');

/***************
 *  Variables  *
 ***************/

var settings;
var lrSnippet = '<script>document.write(\'<script src=\"http://\' + (location.host || \'localhost\').split(\':\')[0] + \':35729/livereload.js?snipver=1\"></\' + \'script>\')</script>';

/**************
 *  Partials  *
 **************/

/**
 * Recursively registers all partials in the given /partials folder
 * @param {Object} partials A list of loaded partials files
 * @param {Array} [varname] [description]
 */
function registerPartials(partials, partialPath) {
    var name;

    partialPath = partialPath || [];

    for (var item in partials) {
        
        // Register a partial
        if (path.extname(item) === '.hbs') {
            partialPath.push(path.basename(item));
            name = partialPath.join('/');
            name = path.basename(name, '.hbs');
            handlebars.registerPartial(name, partials[item]);
            partialPath.pop();
        }

        // Continue traversing directory
        else if (partials[item] === Object(partials[item])) {
            partialPath.push(item);
            registerPartials(partials[item], partialPath);
        }
    }

    partialPath.pop();
}

/**********
 *  Site  *
 **********/

/**
 * Tries to compile the given handlebars hbs
 * @param {String} content The hbs to template
 */
function handlebarsCompile(content) {
    var result;

    try {
        result = handlebars.compile(content);
    } catch (err) {
        log('Handlebars', err, 'error');
        result = handlebars.compile('<span></span>');
    }

    return result;
}

/**
 * 
 * @param {type} [name] [description]
 */
function processSite(files, site, sitePath) {
    var key, pageFile, pages, templateFn, sass;
    var defaults = {};
    var keys = Object.keys(files);

    sitePath = sitePath || [];
    site = site || {};

    // Establish site entry
    if (files['index.hbs']) {

        // Key by the file's path
        sitePath.push('index.html');
        key = sitePath.join('/');
        site[key] = {
            key: key,
            template: handlebarsCompile(files['index.hbs']),
            modules: []
        };
        sitePath.pop();

        // Remove the index.hbs key
        keys.splice(keys.indexOf('index.hbs'), 1);

        // Add style
        if (files['main.scss']) {
            sass = site[key].sass = files['main.scss'];

            // Remove the main.scss key
            keys.splice(keys.indexOf('main.scss'), 1);
        }

        // Add scripts
        if (files['index.js']) {
            site[key].script = files['index.js'];
            keys.splice(keys.indexOf('index.js'), 1);
        }
    }

    // Get default data
    if (files['defaults.json']) {
        defaults = JSON.parse(files['defaults.json']);
        if (site[key]) { site[key].data = defaults; }
    }

    // Populate based on pages.json
    if (files['pages.json']) {
        pageFile = JSON.parse(files['pages.json']);

        // Get the template key
        for (var template in pageFile) {
            pages = pageFile[template];
            templateFn = handlebarsCompile(files[template]);

            // Add additional pages to site
            for (var page in pages) {
                sitePath.push(page + '.html');
                key = sitePath.join('/');
                site[key] = {
                    key: key,
                    generated: true,
                    template: templateFn,
                    data: extend({}, defaults, pages[page]),
                    sass: sass,
                    modules: [],
                    script: files['index.js']
                };
                sitePath.pop();
            }
        }

        keys.splice(keys.indexOf('pages.json'), 1);
    }

    // Continue recursing with remaining keys
    keys.forEach(function(key) {
        
        // Only recurse directories (ignore dotfiles)
        if (!path.extname(key) && key.indexOf('.') !== 0) {
            sitePath.push(key);
            processSite(files[key], site, sitePath);
            sitePath.pop();
        }
    });

    return site;
}

/****************
 *  Templating  *
 ****************/

/**
 * 
 * @param {type} [name] [description]
 */
function moduleHelper(module, object) {
    var html, doc, template;
    var data = object.data;
{'fraction_non_alphanumeric': 0.18064814814814814, 'fraction_numerical': 0.0021296296296296298, 'mean_word_length': 2.307103490508267, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, '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': '4957743', 'n_tokens_mistral': 3218, 'n_tokens_neox': 3118, 'n_words': 726}