Skip to content

Commit

Permalink
Code Generation for UML added to code export
Browse files Browse the repository at this point in the history
  • Loading branch information
Engelbert Niehaus committed May 8, 2018
1 parent 1ac46f0 commit 1435031
Show file tree
Hide file tree
Showing 6 changed files with 339 additions and 22 deletions.
58 changes: 58 additions & 0 deletions docs/db/uml_default.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
vDataJSON["uml_default"]={
"data":{
"classname": "MyClass",
"superclassname": "",
"comment": "",
"reposinfo": {
"repository": "https://www.github.com/niebert/",
"require_classes": "yes",
"author": "",
"email": "",
"created": "2017/03/05 18:13:28",
"modified": "2017/11/29 13:23:17",
"requirelist": []
},
"attributes": [],
"methods": []
},
"settings":{
"extension4code":".js",
"classlist": [
"",
"Array",
"Boolean",
"Float",
"Function",
"Hash",
"Integer",
"Object",
"RegularExp",
"String",
"App",
"AppAbstract",
"Document",
"LinkParam",
"JSONEditor"
],
"localclasslist": [
"LoadSaver",
"LinkParam"
],
"remoteclasslist": [
"JSONEditor"
],
"baseclasslist": [
"",
"Array",
"Boolean",
"Document",
"Float",
"Function",
"Hash",
"Integer",
"Object",
"RegularExp",
"String"
]
}
}
2 changes: 2 additions & 0 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
var vWinUML = null; // window, where the UML diagram is displayed, necessary for communication between windows.
var vWinCompress = null; // window, that is opened for the code compressor, necessary for exchanging code between windows.
</script>
<script language="javascript" src="db/uml_default.js"></script>
<!-- Load Schema for JSON Editor-->
<script language="javascript" src="plugins/dbedit/schema/class_schema.js"></script>
<script language="javascript" src="plugins/dbedit/schema/globallibs_schema.js"></script>
Expand Down Expand Up @@ -492,6 +493,7 @@

<input name="bCreatorDocButton" value="Doc" onclick="createDoc4Class()" type="button">
<input name="bCreatorButton" value=" Create JS " onclick="createCode4Class()" type="button">
<input name="bCreatorUMLButton" value=" Create UML " onclick="createUML4Class()" type="button">
<!--
<input name="bCompressButton" value=" Compress " onclick="compressCode4Class()" type="button">
-->
Expand Down
82 changes: 81 additions & 1 deletion docs/js/codegen.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,88 @@ function createDoc4Class(pClass) {
//};
};

function createUML4Class(pClass) {
// called when user presses [Create JS]
var vClass = pClass || getSelectedClassID();
console.log("createUML4Class() '"+vClass+"'");
var vUML = getDefaultUML(vClass);
var c = getClassJSON(vClass);
checkClassJSON(c);
var u = vUML.data;
u.classname = vClass;
u.superclassname = c.tSuperClassname;
u.reposinfo.repository += vClass;
u.reposinfo.author = c.tAuthor;
u.reposinfo.email = c.tEMail;
u.reposinfo.created = c.init_date;
u.reposinfo.modified = c.mod_date;
var vLibs = {};
var cl = vUML.settings.localclasslist;
for (var i = 0; i < cl.length; i++) {
vLibs[cl[i]] = cl[i];
};
vLibs[u.superclassname] = u.superclassname;
for (var key in c.AttribDefault) {
if (c.AttribDefault.hasOwnProperty(key)) {
u.attributes.push({
"name" : key,
"visibility": "public",
"init" : c.AttribDefault[key],
"class" : c.AttribType[key],
"comment": c.AttribComment[key]
});
};
if (c.AttribType[key] != "") {
vLibs[c.AttribType[key]] = c.AttribType[key];
};
};
var par = [];
for (var key in c.MethodCode) {
if (c.MethodCode.hasOwnProperty(key)) {
par = [];
var p = c.MethodParameter[key];
var p_split = p.split(",");
for (var i = 0; i < p_split.length; i++) {
var pvar = p_split[i].split(":");
par.push({
"name" : pvar[0],
"class" : pvar[1],
"comment" : "parameter '"+pvar[0]+"' stores ..."
})
};
u.methods.push({
"name" : key,
"visibility" : "public",
"return" : c.MethodReturn[key],
"code" : c.MethodCode[key],
"comment": c.MethodComment[key],
"parameter": par
});
if (c.MethodReturn[key] != "") {
vLibs[c.MethodReturn[key]] = c.MethodReturn[key];
};
};
};
var vLibArr = [];
for (var lib in vLibs) {
if (vLibs.hasOwnProperty(lib)) {
vLibArr.push(lib);
};
};
vUML.settings.localclasslist = vLibArr;
var vContent = JSON.stringify(vUML,null,4);
var vFileName = vClass.toLowerCase()+"_uml.json";
write2editor("Output",vContent);
saveFile2HDD(vFileName,vContent)
//if (getCheckBox("checkCompressCode")) {
// console.log("Open Compressor Window and compress class '"+pClass+"'");
// compressCode4Class();
//};
};


function getDefaultUML () {
return cloneJSON(vDataJSON["uml_default"]);
}

function compressCode4ClassWindow() {
console.log("compressCode4Class() not used in JSCC");
Expand Down
87 changes: 87 additions & 0 deletions docs/prog/classes_jscc/templateengine_jscc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
vJSCC_DB['ClassList']['TemplateEngine'] = {
"JSCC_type": "CLASS",
"JSCC_init_date": "24.1.2018",
"JSCC_mod_date": "2018/01/24 10:43:21",
"tClassname": "TemplateEngine",
"tSuperClassname": "",
"sClassType": "Default",
"tAuthor": "Engelbert Niehaus",
"tEMail": "niehaus@uni-landau.de",
"tAttributes": "",
"tMethods": "section(pData:Hash):String\nurl(pData:Hash):String\ntable(pData:Hash):String\nmath(pData:Hash):String\nhorizontal_line(pData:Hash):String\nimages(pData:Hash):String\ninline_elements(pData:Hash):String\ntoc(pData:Hash):String\ninit(pTplHash:Hash)",
"sAttribList": "",
"tAttribName": "",
"tAttribType": "",
"tAttribComment": "",
"tAttribDefault": "",
"sAttribTypeList": "",
"tMethodHeader": "init(pTplHash:Hash)",
"tMethodName": "",
"tMethodComment": "what does section_gen do?",
"sMethodList": "init",
"tMethodCode": "",
"tLoopObject": "pTplHash",
"tLoopMethod": ")",
"AttribType": {},
"AttribAccess": {},
"AttribDefault": {},
"AttribComment": {},
"MethodParameter": {
"section": "pData:Hash",
"url": "pData:Hash",
"table": "pData:Hash",
"math": "pData:Hash",
"horizontal_line": "pData:Hash",
"images": "pData:Hash",
"inline_elements": "pData:Hash",
"toc": "pData:Hash",
"init": "pTplHash:Hash"
},
"MethodReturn": {
"section": "String",
"url": "String",
"table": "String",
"math": "String",
"horizontal_line": "String",
"images": "String",
"inline_elements": "String",
"toc": "String",
"init": ""
},
"MethodCode": {
"section": "",
"url": "",
"table": "",
"math": "",
"horizontal_line": "",
"images": "",
"inline_elements": "",
"toc": "",
"init": "// Code for init\nthis.aTplHash = pTplHash;\n\nfor (var vKey in pTplHash) {\n if (pTplHash.hasOwnProperty(vKey)) {\n // with vKey = \"sections\" the replacement can be called vTplEngine.sections(pContextHash)\n this[vKey] = Handlebars.compile(pTplHash[vKey]);\n }\n};\n"
},
"MethodComment": {
"section": "Comment for section",
"url": "Comment for url",
"table": "Comment for table",
"math": "Comment for math",
"horizontal_line": "Comment for horizontal_line",
"images": "Comment for images",
"inline_elements": "Comment for inline_elements",
"toc": "Comment for toc",
"init": "Init the template engine with a template hash. And create the replace functions of the Class TemplateEngine dynamically.\nOverwrite the defined methods like 'sections(pData)'"
},
"MethodAccess": {
"section": "public",
"url": "public",
"table": "public",
"math": "public",
"horizontal_line": "public",
"images": "public",
"inline_elements": "public",
"toc": "public",
"init": "public"
},
"sClassList": "TemplateEngine",
"tMethodAccess": "public",
"JSCC_version": "1"
}

0 comments on commit 1435031

Please sign in to comment.