import CACHE from './cache';
import UTILS from './utils';
import Compiler from './compiler';
import Render from './render';

function getTemplateContent(possibleSelectorOrHTMLOrNode) {
	if (UTILS.isDOM(possibleSelectorOrHTMLOrNode)) {
		return possibleSelectorOrHTMLOrNode.innerHTML;
	}

	if (typeof possibleSelectorOrHTMLOrNode == 'string' && possibleSelectorOrHTMLOrNode[0] == '#') {
		let element = document.querySelector(possibleSelectorOrHTMLOrNode);
		if (element) {
			return element.innerHTML;
		}
	}

	// Hitting this return means that it is probably HTML
	return possibleSelectorOrHTMLOrNode;
}

function JTML() {
}

JTML.compile = function (possibleSelectorOrHTMLOrNode) {
	let templateContent = getTemplateContent(possibleSelectorOrHTMLOrNode);

	let operationalFunction = CACHE[templateContent];

	if (!operationalFunction) {
		operationalFunction = Compiler(templateContent);
		CACHE[templateContent] = operationalFunction;
	}

	return new Render(operationalFunction);
};

export default JTML;

import Compiler from './compiler';
import Render from './render';
import Templates from './templates';
import Cache from './cache';

class JTML {
	static compile(possibleSelectorOrHTMLOrDomNode) {

		let templateContent = Templates.getTemplateContent(possibleSelectorOrHTMLOrDomNode);

		let compiledTemplate = Compiler.compile(templateContent);

		return new Render(compiledTemplate);
	}

	static clearCache() {
		Cache.clearCache();
	}

	static registerHelper() {
		console.log('TODO');
	}

	static config() {
		console.log('TODO');
	}
}

export default JTML;

Simplify initial exposed static class methods
Simplify initial exposed static class methods
