handlebars4code
Version:
library and NPM module that extends Handlebars with Helpers for Code Generation in a specific programming language (e.g. Javascript)
34 lines (28 loc) • 762 B
HTML
<script language="javascript">
function el(pID) {
return document.getElementById(pID)
}
function convert(pTplID)
{
var vTplID = pTplID || "javascript";
var vJSON;
var vString = document.fconvert.jsonstring.value;
if(vString) {
try {
vJSON = JSON.parse(vString);
} catch(e) {
alert("JSON Parsing Error: "+e); // error in the above string (in this case, yes)!
};
if (vJSON) {
setTemplate(pTplID);
document.fconvert.output.value = Handlebars4Code.compile_code(vTplID,vJSON);
} else {
alert("ERROR: Could not parse JSON")
}
}
}
function setTemplate(pTplID) {
//convert(pTpl);
el("tTemplate").value = vDataJSON.tpl[pTplID];
}
</script>