-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
694 additions
and
491 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,96 @@ | ||
define(function (require, exports, module) { | ||
'use strict'; | ||
/* | ||
* Copyright (c) 2016-2018 Andrias Meisyal. All rights reserved. | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a | ||
* copy of this software and associated documentation files (the "Software"), | ||
* to deal in the Software without restriction, including without limitation | ||
* the rights to use, copy, modify, merge, publish, distribute, sublicense, | ||
* and/or sell copies of the Software, and to permit persons to whom the | ||
* Software is furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS | ||
* IN THE SOFTWARE. | ||
*/ | ||
|
||
function CodeWriter(indentString) { | ||
this.lines = []; | ||
this.indentString = (indentString ? indentString : ' '); | ||
this.indentations = []; | ||
/* | ||
* CodeWriter | ||
*/ | ||
class CodeWriter { | ||
/* | ||
* @constructor | ||
* | ||
* @param {string} indentString | ||
*/ | ||
constructor (indentString) { | ||
// @member {Array.<string>} lines | ||
this.lines = [] | ||
// @member {string} indentString | ||
this.indentString = indentString || ' ' // default 4 spaces | ||
// @member {Array.<string>} indentations | ||
this.indentations = [] | ||
} | ||
|
||
CodeWriter.prototype.indent = function () { | ||
this.indentations.push(this.indentString); | ||
}; | ||
/* | ||
* Indent | ||
*/ | ||
indent () { | ||
this.indentations.push(this.indentString) | ||
} | ||
|
||
CodeWriter.prototype.outdent = function () { | ||
this.indentations.splice(this.indentations.length - 1, 1); | ||
}; | ||
/* | ||
* Outdent | ||
*/ | ||
outdent () { | ||
this.indentations.splice(this.indentations.length - 1, 1) | ||
} | ||
|
||
CodeWriter.prototype.writeLine = function (line) { | ||
/* | ||
* Write a line | ||
* @param {string} line | ||
*/ | ||
writeLine (line) { | ||
if (line) { | ||
this.lines.push(this.indentations.join('') + line); | ||
this.lines.push(this.indentations.join('') + line) | ||
} else { | ||
this.lines.push(''); | ||
this.lines.push('') | ||
} | ||
}; | ||
} | ||
|
||
CodeWriter.prototype.getData = function () { | ||
return this.lines.join('\n'); | ||
}; | ||
/* | ||
* Return as all string data | ||
* @return {string} line | ||
*/ | ||
getData () { | ||
return this.lines.join('\n') | ||
} | ||
|
||
CodeWriter.prototype.fileName = function (className) { | ||
return className.replace(/([a-z])([A-Z])/g, '$1_$2').toLowerCase(); | ||
}; | ||
/* | ||
* Return file name by converting class name to snack case | ||
* @param {string} class name | ||
* @return {string} file name | ||
*/ | ||
getFileName (className) { | ||
return className.replace(/([a-z])([A-Z])/g, '$1_$2').toLowerCase() | ||
} | ||
|
||
CodeWriter.prototype.toCamelCase = function (className) { | ||
/* | ||
* Convert class name to camel case | ||
* @param {string} class name | ||
* @return {string} converted class name | ||
*/ | ||
toCamelCase (className) { | ||
return className.replace(/(\b|_)\w/g, function (match) { | ||
return match.replace(/_/, '').toUpperCase(); | ||
}); | ||
}; | ||
return match.replace(/_/, '').toUpperCase() | ||
}) | ||
} | ||
} | ||
|
||
exports.CodeWriter = CodeWriter; | ||
}); | ||
exports.CodeWriter = CodeWriter |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,68 +1,89 @@ | ||
define(function (require, exports, module) { | ||
'use strict'; | ||
/* | ||
* Copyright (c) 2016-2018 Andrias Meisyal. All rights reserved. | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a | ||
* copy of this software and associated documentation files (the "Software"), | ||
* to deal in the Software without restriction, including without limitation | ||
* the rights to use, copy, modify, merge, publish, distribute, sublicense, | ||
* and/or sell copies of the Software, and to permit persons to whom the | ||
* Software is furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS | ||
* IN THE SOFTWARE. | ||
*/ | ||
|
||
var Commands = app.getModule('command/Commands'); | ||
var CommandManager = app.getModule('command/CommandManager'); | ||
var MenuManager = app.getModule('menu/MenuManager'); | ||
var Dialogs = app.getModule('dialogs/Dialogs'); | ||
var ElementPickerDialog = app.getModule('dialogs/ElementPickerDialog'); | ||
var FileSystem = app.getModule('filesystem/FileSystem'); | ||
const RubyCodeGenerator = require('./ruby-code-generator') | ||
|
||
var CodeGenUtils = require('code-generator-utils'); | ||
var RubyCodeGenerator = require('ruby-code-generator'); | ||
var RubyPreferences = require('ruby-preferences'); | ||
|
||
var CMD_RUBY = 'ruby'; | ||
var CMD_RUBY_GENERATE = 'ruby.generate'; | ||
var CMD_RUBY_CONFIGURE = 'ruby.configure'; | ||
|
||
function _handleGenerate(base, path, options) { | ||
var result = new $.Deferred(); | ||
options = options || RubyPreferences.getGenerateOptions(); | ||
function getGeneratorOptions () { | ||
return { | ||
useTab: app.preferences.get('ruby.generator.useTab'), | ||
indentSpaces: app.preferences.get('ruby.generator.indentSpaces'), | ||
initializeMethod: app.preferences.get('ruby.generator.initializeMethod'), | ||
toStringMethod: app.preferences.get('ruby.generator.toStringMethod'), | ||
documentation: app.preferences.get('ruby.generator.documentation') | ||
} | ||
} | ||
|
||
if (!base) { | ||
ElementPickerDialog.showDialog('Select a base model to generate codes', null, type.UMLPackage) | ||
.done(function (buttonId, selected) { | ||
if (buttonId === Dialogs.DIALOG_BTN_OK && selected) { | ||
base = selected; | ||
if (!path) { | ||
FileSystem.showOpenDialog(false, true, 'Select a folder where generated codes to be located', null, null, function (error, files) { | ||
if (!error) { | ||
if (files) { | ||
path = files[0]; | ||
RubyCodeGenerator.generate(base, path, options).then(result.resolve, result.reject); | ||
} else { | ||
result.reject(FileSystem.USER_CANCELED); | ||
} | ||
} else { | ||
result.reject(error); | ||
} | ||
}); | ||
} else { | ||
RubyCodeGenerator.generate(base, path, options).then(result.resolve, result.reject); | ||
} | ||
} else { | ||
result.reject(); | ||
/* | ||
* Command Handler for Ruby Generate | ||
* | ||
* @param {Element} base | ||
* @param {string} path | ||
* @param {Object} options | ||
* @return {$.Promise} | ||
*/ | ||
function _handleGenerate (base, path, options) { | ||
// If options is not passed, get from preference | ||
options = options || getGeneratorOptions() | ||
// If base is not assigned, popup ElementPicker | ||
if (!base) { | ||
app.elementPickerDialog.showDialog('Select a base model to generate codes', null, type.UMLPackage).then(function ({buttonId, returnValue}) { | ||
if (buttonId === 'ok') { | ||
base = returnValue | ||
// If path is not assigned, popup Open Dialog to select a folder | ||
if (!path) { | ||
var files = app.dialogs.showOpenDialog('Select a folder where generated codes to be located', null, null, { properties: ['openDirectory']}) | ||
if (files && files.length > 0) { | ||
path = files[0] | ||
RubyCodeGenerator.generate(base, path, options) | ||
} | ||
}); | ||
} else { | ||
RubyCodeGenerator.generate(base, path, options) | ||
} | ||
} | ||
}) | ||
} else { | ||
// If path is not assigned, popup Open Dialog to select a folder | ||
if (!path) { | ||
var files = app.dialogs.showOpenDialog('Select a folder where generated codes to be located', null, null, { properties: ['openDirectory']}) | ||
if (files && files.length > 0) { | ||
path = files[0] | ||
RubyCodeGenerator.generate(base, path, options) | ||
} | ||
} else { | ||
window.alert('NotImplementedError'); | ||
RubyCodeGenerator.generate(base, path, options) | ||
} | ||
|
||
return result.promise(); | ||
} | ||
} | ||
|
||
function _handleConfigure() { | ||
CommandManager.execute(Commands.FILE_PREFERENCES, RubyPreferences.getId()); | ||
} | ||
/* | ||
* Popup PreferenceDialog with Ruby Preference Schema | ||
*/ | ||
function _handleConfigure () { | ||
app.commands.execute('application:preferences', 'ruby') | ||
} | ||
|
||
CommandManager.register('Ruby', CMD_RUBY, CommandManager.doNothing); | ||
CommandManager.register('Generate Code...', CMD_RUBY_GENERATE, _handleGenerate); | ||
CommandManager.register('Configure...', CMD_RUBY_CONFIGURE, _handleConfigure); | ||
function init () { | ||
app.commands.register('ruby:generate', _handleGenerate) | ||
app.commands.register('ruby:configure', _handleConfigure) | ||
} | ||
|
||
var menu = MenuManager.getMenu(Commands.TOOLS); | ||
var menuItem = menu.addMenuItem(CMD_RUBY); | ||
menuItem.addMenuItem(CMD_RUBY_GENERATE); | ||
menuItem.addMenuDivider(); | ||
menuItem.addMenuItem(CMD_RUBY_CONFIGURE); | ||
}); | ||
exports.init = init |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"menu": [ | ||
{ | ||
"id": "tools", | ||
"submenu": [ | ||
{ | ||
"label": "Ruby", | ||
"id": "tools.ruby", | ||
"submenu": [ | ||
{ "label": "Generate Code...", "id": "tools.ruby.generate", "command": "ruby:generate" }, | ||
{ "type": "separator" }, | ||
{ "label": "Configure...", "id": "tools.ruby.configure", "command": "ruby:configure" } | ||
] | ||
} | ||
] | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
{ | ||
"id": "ruby", | ||
"name": "Ruby", | ||
"schema": { | ||
"ruby.generator": { | ||
"text": "Ruby Code Generation", | ||
"type": "section" | ||
}, | ||
"ruby.generator.useTab": { | ||
"text": "Use Tab", | ||
"description": "Use tab for indentation instead of spaces.", | ||
"type": "check", | ||
"default": false | ||
}, | ||
"ruby.generator.indentSpaces": { | ||
"text": "Indent Spaces", | ||
"description": "Number of spaces for indentation.", | ||
"type": "number", | ||
"default": 2 | ||
}, | ||
"ruby.generator.initializeMethod": { | ||
"text": "The initialize method", | ||
"description": "Generate initialize method that works almost same way as constructor.", | ||
"type": "check", | ||
"default": true | ||
}, | ||
"ruby.generator.toStringMethod": { | ||
"text": "The to_s method", | ||
"description": "Generate to_s method that returns a string representation of the object.", | ||
"type": "check", | ||
"default": true | ||
}, | ||
"ruby.generator.documentation": { | ||
"text": "Documentation", | ||
"description": "Generate documentation of class elements.", | ||
"type": "check", | ||
"default": true | ||
} | ||
} | ||
} |
Oops, something went wrong.