Skip to content

Commit 618c361

Browse files
committed
Fixed visualpython#155 - Add 'Comment Template' to comment logic block.
- Add comment templates consisting of default, class and method
1 parent d648b1d commit 618c361

File tree

1 file changed

+96
-3
lines changed

1 file changed

+96
-3
lines changed

visualpython/js/m_logic/Comment.js

Lines changed: 96 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* Author : Black Logic
66
* Note : Logic > comment
77
* License : GNU GPLv3 with Visual Python special exception
8-
* Date : 2021. 11. 18
8+
* Date : 2023. 04. 04
99
* Change Date :
1010
*/
1111

@@ -18,6 +18,61 @@ define([
1818
], function(com_String, PopupComponent) {
1919

2020
const COMMENT_DEFAULT_CODE = '# Write down comments'
21+
// Templates from NumPy Style Python Docstrings.
22+
const COMMENT_CLASS_TEMPLATE =
23+
`"""Summarize the class in one line.
24+
25+
Several sentences ...
26+
providing an extended description.
27+
28+
Note
29+
----------
30+
Note about this class.
31+
32+
Parameters
33+
----------
34+
param1 : param_type
35+
Parameter description.
36+
param2 : param_type
37+
Parameter description.
38+
39+
Attributes
40+
----------
41+
attr1 : attr_type
42+
Attibute description.
43+
attr2 : attr_type
44+
Attibute description.
45+
46+
Examples
47+
----------
48+
49+
References
50+
----------
51+
"""`
52+
const COMMENT_METHOD_TEMPLATE =
53+
`"""Summarize the function in one line.
54+
55+
Several sentences ...
56+
providing an extended description.
57+
58+
Parameters
59+
----------
60+
param1 : param_type
61+
Parameter description.
62+
param2 : param_type
63+
Parameter description.
64+
65+
Returns
66+
-------
67+
return_type
68+
Return description.
69+
70+
Note
71+
----------
72+
73+
Examples
74+
----------
75+
"""`
2176

2277
/**
2378
* Comment
@@ -29,25 +84,63 @@ define([
2984
this.config.dataview = false;
3085
this.config.codeview = false;
3186
this.config.saveOnly = true;
87+
this.selectBoxClassName = 'vp-ct-option'; // Select Box ClassName
3288

3389
this.state = {
3490
code: COMMENT_DEFAULT_CODE,
3591
...this.state
3692
}
37-
93+
94+
this.cmTemplates = { // a kind of templates
95+
Default : COMMENT_DEFAULT_CODE,
96+
Class : COMMENT_CLASS_TEMPLATE,
97+
Method : COMMENT_METHOD_TEMPLATE
98+
}
99+
38100
this._addCodemirror('code', this.wrapSelector('#code'));
39101
}
40102

41103
_bindEvent() {
42104
super._bindEvent();
43-
/** Implement binding events */
105+
106+
var commentTemplates = this.cmTemplates;
107+
let cmCodeListTemp = this.cmCodeList;
108+
109+
$('.' + this.selectBoxClassName).on('change', function(){
110+
// get code mirror object
111+
let targetCmObj = cmCodeListTemp.filter(obj => obj.key == 'code');
112+
var templateOption = $(this).val();
113+
let cm = targetCmObj[0].cm;
114+
115+
// Change Code Mirror Text
116+
if(templateOption == 'vp_template_class'){
117+
cm.setValue(commentTemplates.Class);
118+
}else if(templateOption == 'vp_template_method'){
119+
cm.setValue(commentTemplates.Method);
120+
}else if(templateOption == 'vp_template_default'){
121+
cm.setValue(commentTemplates.Default);
122+
}
123+
124+
cm.save();
125+
});
44126
}
45127

46128
templateForBody() {
47129
/** Implement generating template */
48130
var page = new com_String();
49131
page.appendFormatLine('<textarea name="code" class="code vp-state" id="code">{0}</textarea>'
50132
, this.state.code);
133+
134+
// add select box
135+
page.appendFormatLine('<select class="vp-select w100 {0}" >', this.selectBoxClassName);
136+
// add options
137+
Object.entries(this.cmTemplates).forEach(([optionValue, t_code]) => {
138+
page.appendFormatLine('<option value="{0}">{1}</option>',
139+
'vp_template_' + optionValue.toLowerCase(),
140+
optionValue);
141+
});
142+
page.appendFormatLine('</select>');
143+
51144
return page.toString();
52145
}
53146

0 commit comments

Comments
 (0)