Skip to content

Commit 1435031

Browse files
author
Engelbert Niehaus
committed
Code Generation for UML added to code export
1 parent 1ac46f0 commit 1435031

File tree

6 files changed

+339
-22
lines changed

6 files changed

+339
-22
lines changed

docs/db/uml_default.js

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
vDataJSON["uml_default"]={
2+
"data":{
3+
"classname": "MyClass",
4+
"superclassname": "",
5+
"comment": "",
6+
"reposinfo": {
7+
"repository": "https://www.github.com/niebert/",
8+
"require_classes": "yes",
9+
"author": "",
10+
"email": "",
11+
"created": "2017/03/05 18:13:28",
12+
"modified": "2017/11/29 13:23:17",
13+
"requirelist": []
14+
},
15+
"attributes": [],
16+
"methods": []
17+
},
18+
"settings":{
19+
"extension4code":".js",
20+
"classlist": [
21+
"",
22+
"Array",
23+
"Boolean",
24+
"Float",
25+
"Function",
26+
"Hash",
27+
"Integer",
28+
"Object",
29+
"RegularExp",
30+
"String",
31+
"App",
32+
"AppAbstract",
33+
"Document",
34+
"LinkParam",
35+
"JSONEditor"
36+
],
37+
"localclasslist": [
38+
"LoadSaver",
39+
"LinkParam"
40+
],
41+
"remoteclasslist": [
42+
"JSONEditor"
43+
],
44+
"baseclasslist": [
45+
"",
46+
"Array",
47+
"Boolean",
48+
"Document",
49+
"Float",
50+
"Function",
51+
"Hash",
52+
"Integer",
53+
"Object",
54+
"RegularExp",
55+
"String"
56+
]
57+
}
58+
}

docs/index.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
var vWinUML = null; // window, where the UML diagram is displayed, necessary for communication between windows.
4545
var vWinCompress = null; // window, that is opened for the code compressor, necessary for exchanging code between windows.
4646
</script>
47+
<script language="javascript" src="db/uml_default.js"></script>
4748
<!-- Load Schema for JSON Editor-->
4849
<script language="javascript" src="plugins/dbedit/schema/class_schema.js"></script>
4950
<script language="javascript" src="plugins/dbedit/schema/globallibs_schema.js"></script>
@@ -492,6 +493,7 @@
492493

493494
<input name="bCreatorDocButton" value="Doc" onclick="createDoc4Class()" type="button">
494495
<input name="bCreatorButton" value=" Create JS " onclick="createCode4Class()" type="button">
496+
<input name="bCreatorUMLButton" value=" Create UML " onclick="createUML4Class()" type="button">
495497
<!--
496498
<input name="bCompressButton" value=" Compress " onclick="compressCode4Class()" type="button">
497499
-->

docs/js/codegen.js

Lines changed: 81 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,88 @@ function createDoc4Class(pClass) {
2323
//};
2424
};
2525

26+
function createUML4Class(pClass) {
27+
// called when user presses [Create JS]
28+
var vClass = pClass || getSelectedClassID();
29+
console.log("createUML4Class() '"+vClass+"'");
30+
var vUML = getDefaultUML(vClass);
31+
var c = getClassJSON(vClass);
32+
checkClassJSON(c);
33+
var u = vUML.data;
34+
u.classname = vClass;
35+
u.superclassname = c.tSuperClassname;
36+
u.reposinfo.repository += vClass;
37+
u.reposinfo.author = c.tAuthor;
38+
u.reposinfo.email = c.tEMail;
39+
u.reposinfo.created = c.init_date;
40+
u.reposinfo.modified = c.mod_date;
41+
var vLibs = {};
42+
var cl = vUML.settings.localclasslist;
43+
for (var i = 0; i < cl.length; i++) {
44+
vLibs[cl[i]] = cl[i];
45+
};
46+
vLibs[u.superclassname] = u.superclassname;
47+
for (var key in c.AttribDefault) {
48+
if (c.AttribDefault.hasOwnProperty(key)) {
49+
u.attributes.push({
50+
"name" : key,
51+
"visibility": "public",
52+
"init" : c.AttribDefault[key],
53+
"class" : c.AttribType[key],
54+
"comment": c.AttribComment[key]
55+
});
56+
};
57+
if (c.AttribType[key] != "") {
58+
vLibs[c.AttribType[key]] = c.AttribType[key];
59+
};
60+
};
61+
var par = [];
62+
for (var key in c.MethodCode) {
63+
if (c.MethodCode.hasOwnProperty(key)) {
64+
par = [];
65+
var p = c.MethodParameter[key];
66+
var p_split = p.split(",");
67+
for (var i = 0; i < p_split.length; i++) {
68+
var pvar = p_split[i].split(":");
69+
par.push({
70+
"name" : pvar[0],
71+
"class" : pvar[1],
72+
"comment" : "parameter '"+pvar[0]+"' stores ..."
73+
})
74+
};
75+
u.methods.push({
76+
"name" : key,
77+
"visibility" : "public",
78+
"return" : c.MethodReturn[key],
79+
"code" : c.MethodCode[key],
80+
"comment": c.MethodComment[key],
81+
"parameter": par
82+
});
83+
if (c.MethodReturn[key] != "") {
84+
vLibs[c.MethodReturn[key]] = c.MethodReturn[key];
85+
};
86+
};
87+
};
88+
var vLibArr = [];
89+
for (var lib in vLibs) {
90+
if (vLibs.hasOwnProperty(lib)) {
91+
vLibArr.push(lib);
92+
};
93+
};
94+
vUML.settings.localclasslist = vLibArr;
95+
var vContent = JSON.stringify(vUML,null,4);
96+
var vFileName = vClass.toLowerCase()+"_uml.json";
97+
write2editor("Output",vContent);
98+
saveFile2HDD(vFileName,vContent)
99+
//if (getCheckBox("checkCompressCode")) {
100+
// console.log("Open Compressor Window and compress class '"+pClass+"'");
101+
// compressCode4Class();
102+
//};
103+
};
26104

27-
105+
function getDefaultUML () {
106+
return cloneJSON(vDataJSON["uml_default"]);
107+
}
28108

29109
function compressCode4ClassWindow() {
30110
console.log("compressCode4Class() not used in JSCC");
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
vJSCC_DB['ClassList']['TemplateEngine'] = {
2+
"JSCC_type": "CLASS",
3+
"JSCC_init_date": "24.1.2018",
4+
"JSCC_mod_date": "2018/01/24 10:43:21",
5+
"tClassname": "TemplateEngine",
6+
"tSuperClassname": "",
7+
"sClassType": "Default",
8+
"tAuthor": "Engelbert Niehaus",
9+
"tEMail": "[email protected]",
10+
"tAttributes": "",
11+
"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)",
12+
"sAttribList": "",
13+
"tAttribName": "",
14+
"tAttribType": "",
15+
"tAttribComment": "",
16+
"tAttribDefault": "",
17+
"sAttribTypeList": "",
18+
"tMethodHeader": "init(pTplHash:Hash)",
19+
"tMethodName": "",
20+
"tMethodComment": "what does section_gen do?",
21+
"sMethodList": "init",
22+
"tMethodCode": "",
23+
"tLoopObject": "pTplHash",
24+
"tLoopMethod": ")",
25+
"AttribType": {},
26+
"AttribAccess": {},
27+
"AttribDefault": {},
28+
"AttribComment": {},
29+
"MethodParameter": {
30+
"section": "pData:Hash",
31+
"url": "pData:Hash",
32+
"table": "pData:Hash",
33+
"math": "pData:Hash",
34+
"horizontal_line": "pData:Hash",
35+
"images": "pData:Hash",
36+
"inline_elements": "pData:Hash",
37+
"toc": "pData:Hash",
38+
"init": "pTplHash:Hash"
39+
},
40+
"MethodReturn": {
41+
"section": "String",
42+
"url": "String",
43+
"table": "String",
44+
"math": "String",
45+
"horizontal_line": "String",
46+
"images": "String",
47+
"inline_elements": "String",
48+
"toc": "String",
49+
"init": ""
50+
},
51+
"MethodCode": {
52+
"section": "",
53+
"url": "",
54+
"table": "",
55+
"math": "",
56+
"horizontal_line": "",
57+
"images": "",
58+
"inline_elements": "",
59+
"toc": "",
60+
"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"
61+
},
62+
"MethodComment": {
63+
"section": "Comment for section",
64+
"url": "Comment for url",
65+
"table": "Comment for table",
66+
"math": "Comment for math",
67+
"horizontal_line": "Comment for horizontal_line",
68+
"images": "Comment for images",
69+
"inline_elements": "Comment for inline_elements",
70+
"toc": "Comment for toc",
71+
"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)'"
72+
},
73+
"MethodAccess": {
74+
"section": "public",
75+
"url": "public",
76+
"table": "public",
77+
"math": "public",
78+
"horizontal_line": "public",
79+
"images": "public",
80+
"inline_elements": "public",
81+
"toc": "public",
82+
"init": "public"
83+
},
84+
"sClassList": "TemplateEngine",
85+
"tMethodAccess": "public",
86+
"JSCC_version": "1"
87+
}

0 commit comments

Comments
 (0)