'use strict';

const GeneratorStream = require('./lib/generator-stream');
const parser = require('./lib/parser');
const partials = require('./lib/partials');
const Context = require('./lib/context');


function render(template, data, partials) {
	return string(template).render(data, partials).string();
}

function Template(templateAST) {
	this.template = templateAST;
}
Template.prototype.render = function (data, partials) {
	const r = this.template.render(new Context(data, partials));
	const reader = new GeneratorStream(r);

	return {
		string: () => {
			return new Promise((resolve, reject) => {
				const buf = [];
				reader.on('data', chunk => buf.push(chunk));
				reader.on('error', reject);
				reader.on('end', () => resolve(buf.join('')));
			});
		},
		stream: () => reader
	};
};

function string(templateString) {
	return new Template(parser(templateString));
}

module.exports = {
	render,
	string,
	partials,
	Template,
};

@@ -792,16 +792,821 @@
 %09%7D;%0A%7D;%0A%0A
+function resolver(opts) %7B%0A%09opts = opts %7C%7C %7B%7D;%0A%0A%09const partialsResolver = opts.partialsResolver %7C%7C new partials.FsWatch(opts.root, opts.suffixes);%0A%0A%09return (templateName, data) =%3E %7B%0A%09%09const context = new Context(data %7C%7C %7B%7D, partialsResolver);%0A%0A%09%09const template = partialsResolver.get(templateName);%0A%0A%09%09const iterator =%0A%09%09%09(template instanceof Promise)%0A%09%09%09%09? (function* () %7B%0A%09%09%09%09%09const ast = yield Promise.resolve(template);%0A%09%09%09%09%09yield* ast.render(context);%0A%09%09%09%09%7D)()%0A%09%09%09%09: template.render(context);%0A%0A%09%09const stream = new GeneratorStream(iterator);%0A%0A%09%09return %7B%0A%09%09%09string: () =%3E new Promise((resolve, reject) =%3E %7B%0A%09%09%09%09const buf = %5B%5D;%0A%09%09%09%09reader.on('data', chunk =%3E buf.push(chunk));%0A%09%09%09%09reader.on('error', reject);%0A%09%09%09%09reader.on('end', () =%3E resolve(buf.join('')));%0A%09%09%09%7D),%0A%09%09%09stream: () =%3E stream%0A%09%09%7D;%0A%09%7D;%0A%7D%0A%0A
 function
@@ -1739,11 +1739,22 @@
 mplate,%0A
+%09resolver,%0A
 %7D;%0A

Add resolver as a simpler entry point