<commit_before>#!/usr/bin/env node
var fs = require('fs');
var http = require('http');
var express = require('express');
var hbs = require('handlebars');

var app = express();

app.use(express.logger());
app.use(express.static(process.cwd()));

app.get
(
	'/:template', function (req, res)
	{
		req.params.models = '';
		handler(req, res);
	}
);

app.get('/:template/:models', handler);

function handler (req, res)
{
	req.params.models = req.params.models.split('+');

	if (req.params.models.length === 1 && req.params.models[0] === '')
	{
		req.params.models = [];
	}

	fs.readFile(req.params.template + '.hbs', 'utf8', template_loaded);

	function template_loaded (err, template)
	{
		if (err)
		{
			res.status(500);
			res.send(err);

			return;
		}

		var final_model = {};
		var models_loaded = 0;

		(
			function load_model (err, model)
			{
				if (err)
				{
					res.status(500);
					res.send(err);

					return;
				}

				if (model !== undefined)
				{
					++models_loaded;

					model = JSON.parse(model);

					for (var key in model)
					{
						final_model[key] = model[key];
					}
				}

				if (models_loaded !== req.params.models.length)
				{
					fs.readFile(req.params.models[models_loaded] + '.json', 'utf8', load_model);
	                        }
				else
				{
					final_model_ready();
				}
			}
		)();

		function final_model_ready ()
		{
			res.send(hbs.compile(template)(final_model));
		}
	}
}

http.createServer(app).listen(4000);
<commit_msg>Automatically render outer template (if found) around the target one.<commit_after>#!/usr/bin/env node
var fs = require('fs');
var http = require('http');
var express = require('express');
var hbs = require('handlebars');

var app = express();

app.use(express.logger());
app.use(express.static(process.cwd()));

app.get
(
	'/:template', function (req, res)
	{
		req.params.models = '';
		handler(req, res);
	}
);

app.get('/:template/:models', handler);

function handler (req, res)
{
	req.params.models = req.params.models.split('+');

	if (req.params.models.length === 1 && req.params.models[0] === '')
	{
		req.params.models = [];
	}

	var outer_template;

	fs.readFile
	(
		'outer.hbs', 'utf8', function (err, template)
		{
			outer_template = template;
			fs.readFile(req.params.template + '.hbs', 'utf8', template_loaded);
		}
	);

	function template_loaded (err, template)
	{
		if (err)
		{
			res.status(500);
			res.send(err);

			return;
		}

		var final_model = {};
		var models_loaded = 0;

		(
			function load_model (err, model)
			{
				if (err)
				{
					res.status(500);
					res.send(err);

					return;
				}

				if (model !== undefined)
				{
					++models_loaded;

					model = JSON.parse(model);

					for (var key in model)
					{
						final_model[key] = model[key];
					}
				}

				if (models_loaded !== req.params.models.length)
				{
					fs.readFile(req.params.models[models_loaded] + '.json', 'utf8', load_model);
	                        }
				else
				{
					final_model_ready();
				}
			}
		)();

		function final_model_ready ()
		{
			var template_html = hbs.compile(template)(final_model);

			if (outer_template)
			{
				final_model['page-body'] = template_html;
				template_html = hbs.compile(outer_template)(final_model);
			}

			res.send(template_html);
		}
	}
}

http.createServer(app).listen(4000);

{'fraction_non_alphanumeric': 0.1742264944427756, 'fraction_numerical': 0.009312105737458696, 'mean_word_length': 2.8364055299539173, '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': '2086301', 'n_tokens_mistral': 1461, 'n_tokens_neox': 1180, 'n_words': 214}