handlebars4code
Version:
library and NPM module that extends Handlebars with Helpers for Code Generation in a specific programming language (e.g. Javascript)
127 lines (110 loc) • 4.87 kB
HTML
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<meta http-equiv="content-language" content="de">
<meta http-equiv="desktop-type" content="tasks">
<title>Handlebars4Code</title>
<meta http-equiv="author" content="Engelbert Niehaus">
<script language="javascript">
// vDataJSON is the main JSON storage for the privacy friendly WebApp
// File Loaded into vDataJSON by script tag
var vDataJSON = {};
vDataJSON.tpl = {};
/* TEMPLATES
vDataJSON.tpl contains the following templates:
* vDataJSON.tpl["javascript"] File: tpl/javascript_tpl.js
for creating the the Source Code for the UML class in javascript
* vDataJSON.tpl["docu4github"] File: tpl/docu4github_tpl.js
for creating the GitHub documentation from the UML source of the class
*/
vDataJSON.out = {};
/* HANDLEBARS COMPILERS
vDataJSON.tpl contains the Handlebars compilers:
* vDataJSON.out["javascript"] Compiler for template: tpl/javascript_tpl.js
This compiler is used in the compileCode() method
var mySource = vJSONEditor.compileCode.javascript(pJSON)
creates the source code for the UML class in javascript
* vDataJSON.out["docu4github"] Compiler for template: tpl/docu4github_tpl.js
This compiler is used in the compileCode() method
var mySource = vJSONEditor.compileCode.docu4github(pJSON)
*/
</script>
<!-- ### Handelbars4Code Init JSON ############### -->
<script src="db/umljs.js"></script>
<!-- ### HANDLEBARS TEMPLATE #####################
Template ID: "javascript"
Template: vDataJSON["tpl"]["javascript"]
-->
<script src="tpl/javascript_tpl.js"></script>
<!-- ### COMPILE HANDLEBARS TEMPLATES ############
Template ID: "docu4github"
Template: vDataJSON["tpl"]["docu4github"]
-->
<script src="tpl/docu4github_tpl.js"></script>
<script src="js/handlebars4code.js"></script>
<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>
</head>
<body style="font-family:Arial,Verdana; font-size:12pt; color:black" bgcolor="#CACACA">
<h1>Handelbars4Code Demo</h1>
<h4>Demo JSON Source as input for was <tt>Handelbars4Code</tt> was generated with <a href="https://niebert/github.io/ClassEditorUML" target="_blank">ClassEditorUML</a></h4>
The library <tt>Handlebars4Code</tt> is a library and NPM module that extends Handlebars with Helpers for Code Generation in a specific programming language (e.g. Javascript).
The source code of Handlebars4Code can be downloaded as <a href="https://github.com/niebert/Handlebars4Code/archive/master.zip" target="_blank">ZIP-file handlebars4code.zip</a>
<form name="fconvert">
<b>JSON Input:</b><br>
<textarea id="jsonstring" name="jsonstring" cols="125" rows="10">This is a
</textarea><br>
<b>Output of Handlebars4Code</b>
<select id="sTemplate" onchange="setTemplate(this.value)">
<option value="javascript" selected="selected">Javascript Code</option>
<option value="docu4github">Documentation for GitHub</option>
</select>
<input name="bConvert" value=" Create Output " onclick="convert(el('sTemplate').value);return false" type="button">
<br>
<textarea id="output" name="output" cols="125" rows="10"></textarea><br>
</form>
<hr>
<b>Used Template of Handlebars4Code (readonly)</b><br>
<textarea id="tTemplate" name="tTemplate" cols="125" rows="10" readonly></textarea><br>
</form>
</body>
<!-- BEGIN: src/html_tail.html -->
<center style="font-size: 10px;">
<a href="https://www.github.com/niebert/Handlebars4Code" target="_blank"> GitHub Sources Handlebars4Code</a> - <a href="https://github.com/niebert/Handlebars4Code/archive/master.zip" target="_blank">Download Handlebars4Code ZIP</a>
<br>
Version: 1.1.1 Date: 2018/12/12 8:18:43 Author: Engelbert Niehaus
</center>
<!-- END: src/html_tail.html -->
<script language="javascript">
el("jsonstring").value = JSON.stringify(vDataJSON["umljs"],null,2);
Handlebars4Code.create_compiler(vDataJSON.tpl);
vDataJSON.out = Handlebars4Code.get_compiler();
</script>
</body>
</html>