<commit_before>'use strict';

var hapi = require('hapi'),
    async = require('async'),
    _ = require('lodash'),

    router = require('./lib/router'),
    renderer = require('./lib/renderer'),
    resourcesControlller = require('./lib/resourcesController'),

    server = new hapi.Server();

server.connection({port: process.env.PORT || 3333});

server.register(require('inert'), function () { return; });
server.register(require('vision'), function (err) {
    if (err) {
        console.log('Failed to load vision.');
    }
});

server.views({
    engines: {
        mustache: require('hapi-mustache')
    },
    relativeTo: __dirname,
    path: 'lib/views'
});

function populatePrimaryNav(callback, resourceType) {
    router.listResourceTypes(function (err, types) {
        types = _.map(types, function (type) {
            type.active = resourceType === type.text;

            return type;
        });

        callback(null, types);
    });
}

server.route({
    method: 'GET',
    path: '/resources/{param*}',
    handler: {
        directory: {
            path: 'resources'
        }
    }
});

server.route({
    method: 'GET',
    path: '/favicon.ico',
    handler: {
        file: {
            path: 'bower_components/travi.org-theme/img/favicon.ico'
        }
    }
});

server.route({
    method: 'GET',
    path: '/',
    handler: function (request, reply) {
        router.listResourceTypes(function (err, types) {
            renderer.render('index', {
                types: types
            }, request, reply);
        });
    }
});

server.route({
    method: 'GET',
    path: '/{resourceType}',
    handler: function (request, reply) {
        var resourceType = request.params.resourceType;

        async.parallel(
            [
                function (callback) {
                    populatePrimaryNav(callback, resourceType);
                },
                function (callback) {
                    resourcesControlller.getListOf(resourceType, callback);
                }
            ],
            function (err, results) {
                renderer.render('resourceList', {
                    resourceType: resourceType,
                    resources: results[1],
                    types: results[0]
                }, request, reply);
            }
        );
    }
});

server.route({
    method: 'GET',
    path: '/{resourceType}/{id}',
    handler: function (request, reply) {
        var resourceType = request.params.resourceType;

        async.parallel(
            [
                function (callback) {
                    populatePrimaryNav(callback, resourceType);
                },
                function (callback) {
                    resourcesControlller.getResource(
                        request.params.resourceType,
                        request.params.id,
                        callback
                    );
                }
            ],
            function (err, results) {
                renderer.render('resource', {
                    resourceType: resourceType,
                    resource: results[1],
                    types: results[0]
                }, request, reply);
            }
        );
    }
});

if (!module.parent) {
    server.start(function (err) {
        if (err) {
            return console.error(err);
        }

        server.log('Server started', server.info.uri);
    });
}

module.exports = server;<commit_msg>temporary wiring of handler<commit_after>'use strict';

var hapi = require('hapi'),
    async = require('async'),
    _ = require('lodash'),

    router = require('./lib/router'),
    renderer = require('./lib/renderer'),
    resourcesControlller = require('./lib/resourcesController'),

    server = new hapi.Server();

server.connection({port: process.env.PORT || 3333});

server.register(require('inert'), function () { return; });
server.register(require('vision'), function (err) {
    if (err) {
        console.log('Failed to load vision.');
    }
});

server.views({
    engines: {
        mustache: require('hapi-mustache')
    },
    relativeTo: __dirname,
    path: 'lib/views'
});

function populatePrimaryNav(callback, resourceType) {
    router.listResourceTypes(function (err, types) {
        types = _.map(types, function (type) {
            type.active = resourceType === type.text;

            return type;
        });

        callback(null, types);
    });
}

server.route({
    method: 'GET',
    path: '/resources/{param*}',
    handler: {
        directory: {
            path: 'resources'
        }
    }
});

server.route({
    method: 'GET',
    path: '/favicon.ico',
    handler: {
        file: {
            path: 'bower_components/travi.org-theme/img/favicon.ico'
        }
    }
});

server.route({
    method: 'GET',
    path: '/',
    handler: function (request, reply) {
        router.listResourceTypes(function (err, types) {
            renderer.render('index', {
                types: types
            }, request, reply);
        });
    }
});

server.route({
    method: 'GET',
    path: '/{resourceType}',
    handler: function (request, reply) {
        var resourceType = request.params.resourceType;

        async.parallel(
            [
                function (callback) {
                    populatePrimaryNav(callback, resourceType);
                },
                function (callback) {
                    resourcesControlller.getListOf(resourceType, callback);
                }
            ],
            function (err, results) {
                renderer.render('resourceList', {
                    resourceType: resourceType,
                    resources: results[1],
                    types: results[0]
                }, request, reply);
            }
        );
    }
});

server.route({
    method: 'GET',
    path: '/{resourceType}/{id}',
    handler: function (request, reply) {
        var resourceType = request.params.resourceType;

        async.parallel(
            [
                function (callback) {
                    populatePrimaryNav(callback, resourceType);
                },
                function (callback) {
                    resourcesControlller.getResource(
                        request.params.resourceType,
                        request.params.id,
                        callback
                    );
                }
            ],
            function (err, results) {
                renderer.render('resource', {
                    resourceType: resourceType,
                    resource: results[1],
                    types: results[0]
                }, request, reply);
            }
        );
    }
});

//require('./lib/server/renderingHandler').configureHandlerFor(server);

if (!module.parent) {
    server.start(function (err) {
        if (err) {
            return console.error(err);
        }

        server.log('Server started', server.info.uri);
    });
}

module.exports = server;
{'fraction_non_alphanumeric': 0.13440782846452726, 'fraction_numerical': 0.00230248956684415, 'mean_word_length': 1.6118000751597144, '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': '4340278', 'n_tokens_mistral': 1881, 'n_tokens_neox': 1808, 'n_words': 347}