Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

#157 - Add 'Comment Template' to comment logic block#173

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
minjk-bl merged 1 commit intovisualpython:oss22_libraryfromMinku-Koo:osskoo
Aug 29, 2022
Merged
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
117 changes: 110 additions & 7 deletionsjs/m_logic/Comment.js
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -6,7 +6,7 @@
* Note : Logic > comment
* License : GNU GPLv3 with Visual Python special exception
* Date : 2021. 11. 18
* Change Date :
* Change Date : 2022. 08. 10
*/

//============================================================================
Expand All@@ -18,6 +18,67 @@ define([
], function(com_String, PopupComponent) {

const COMMENT_DEFAULT_CODE = '# Write down comments'
// Templates from NumPy Style Python Docstrings.
const COMMENT_CLASS_TEMPLATE =
`
"""Summarize the class in one line.

Several sentences ...
providing an extended description.

Note
----------
Note about this class.

Parameters
----------
param1 : param_type
Parameter description.
param2 : param_type
Parameter description.

Attributes
----------
attr1 : attr_type
Attibute description.
attr2 : attr_type
Attibute description.

Examples
----------

References
----------

"""
`
const COMMENT_METHOD_TEMPLATE =
`
"""Summarize the function in one line.

Several sentences ...
providing an extended description.

Parameters
----------
param1 : param_type
Parameter description.
param2 : param_type
Parameter description.

Returns
-------
return_type
Return description.

Note
----------

Examples
----------

"""
`

/**
* Comment
Expand All@@ -29,45 +90,87 @@ define([
this.config.dataview = false;
this.config.codeview = false;
this.config.saveOnly = true;

this.cmKey = 'code'; // Code Mirror Key
this.selectBoxClassName = 'vp-ct-option'; // Select Box ClassName

this.state = {
code: COMMENT_DEFAULT_CODE,
...this.state
};

this.cmTemplates = { // a kind of templates
Template : COMMENT_DEFAULT_CODE,
Class : COMMENT_CLASS_TEMPLATE,
Method : COMMENT_METHOD_TEMPLATE
}

this._addCodemirror('code', this.wrapSelector('#code'));
this._addCodemirror(this.cmKey, this.wrapSelector('#code'));
}

_bindEvent() {
super._bindEvent();
/** Implement binding events */

var commentTemplates = this.cmTemplates;
var cm_key = this.cmKey;
let cmCodeListTemp = this.cmCodeList;

// Select box change Event
$('.' + this.selectBoxClassName).on('change', function(){
// get code mirror object
let targetCmObj = cmCodeListTemp.filter(obj => obj.key == cm_key);
var templateOption = $(this).val();
let cm = targetCmObj[0].cm;

// Change Code Mirror Text
if(templateOption == 'vp_template_class'){
cm.setValue(commentTemplates.Class);
}else if(templateOption == 'vp_template_method'){
cm.setValue(commentTemplates.Method);
}else if(templateOption == 'vp_template_template'){
cm.setValue(commentTemplates.Template);
}

cm.save();
});

}


templateForBody() {
/** Implement generating template */
var page = new com_String();
page.appendFormatLine('<textarea name="code" class="code vp-state" id="code">{0}</textarea>'
, this.state.code);
// add select box
page.appendFormatLine('<select class="vp-select w100 {0}" >', this.selectBoxClassName);
// add options
Object.entries(this.cmTemplates).forEach(([opt, t_code]) => {
page.appendFormatLine('<option value="{0}">{1}</option>',
'vp_template_' + opt.toLowerCase(), opt);
});
page.appendFormatLine('</select>');

return page.toString();
}

open() {
super.open();

if (this.state.code === COMMENT_DEFAULT_CODE) {
// set default selection
let cmObj = this.getCodemirror('code');

let cmObj = this.getCodemirror(this.cmKey);
if (cmObj && cmObj.cm) {
cmObj.cm.setSelection({ line: 0, ch: 2 }, { line: 0 });
cmObj.cm.focus();
}
}
}

generateCode() {
return this.state.code;
}

}

return Comment;
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp