Skip to content

Commit c00dd14

Browse files
committed
Merge branch 'release-0.1.7'
2 parents e696c45 + d7ecc76 commit c00dd14

File tree

9 files changed

+694
-491
lines changed

9 files changed

+694
-491
lines changed

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) 2016-2017 Andrias Meisyal
3+
Copyright (c) 2016-2018 Andrias Meisyal
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# staruml-ruby
22

3-
staruml-ruby is a Ruby extension for [StarUML][staruml] 2. This extension helps
3+
staruml-ruby is a Ruby extension for [StarUML][staruml]. This extension helps
44
you to generate Ruby code from a UML class diagram.
55

66
## Current Status
@@ -66,7 +66,7 @@ take a moment to look over the [contributing guidelines][contributing] first.
6666
This extension is released under the terms of MIT License. See the
6767
[LICENSE][license] file for more details.
6868

69-
Copyright © 2016-2017 Andrias Meisyal.
69+
Copyright © 2016-2018 Andrias Meisyal.
7070

7171
[staruml]: http://staruml.io
7272
[umlconcept]:

code-generator-utils.js

Lines changed: 83 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,96 @@
1-
define(function (require, exports, module) {
2-
'use strict';
1+
/*
2+
* Copyright (c) 2016-2018 Andrias Meisyal. All rights reserved.
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a
5+
* copy of this software and associated documentation files (the "Software"),
6+
* to deal in the Software without restriction, including without limitation
7+
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
8+
* and/or sell copies of the Software, and to permit persons to whom the
9+
* Software is furnished to do so, subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included in
12+
* all copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19+
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
20+
* IN THE SOFTWARE.
21+
*/
322

4-
function CodeWriter(indentString) {
5-
this.lines = [];
6-
this.indentString = (indentString ? indentString : ' ');
7-
this.indentations = [];
23+
/*
24+
* CodeWriter
25+
*/
26+
class CodeWriter {
27+
/*
28+
* @constructor
29+
*
30+
* @param {string} indentString
31+
*/
32+
constructor (indentString) {
33+
// @member {Array.<string>} lines
34+
this.lines = []
35+
// @member {string} indentString
36+
this.indentString = indentString || ' ' // default 4 spaces
37+
// @member {Array.<string>} indentations
38+
this.indentations = []
839
}
940

10-
CodeWriter.prototype.indent = function () {
11-
this.indentations.push(this.indentString);
12-
};
41+
/*
42+
* Indent
43+
*/
44+
indent () {
45+
this.indentations.push(this.indentString)
46+
}
1347

14-
CodeWriter.prototype.outdent = function () {
15-
this.indentations.splice(this.indentations.length - 1, 1);
16-
};
48+
/*
49+
* Outdent
50+
*/
51+
outdent () {
52+
this.indentations.splice(this.indentations.length - 1, 1)
53+
}
1754

18-
CodeWriter.prototype.writeLine = function (line) {
55+
/*
56+
* Write a line
57+
* @param {string} line
58+
*/
59+
writeLine (line) {
1960
if (line) {
20-
this.lines.push(this.indentations.join('') + line);
61+
this.lines.push(this.indentations.join('') + line)
2162
} else {
22-
this.lines.push('');
63+
this.lines.push('')
2364
}
24-
};
65+
}
2566

26-
CodeWriter.prototype.getData = function () {
27-
return this.lines.join('\n');
28-
};
67+
/*
68+
* Return as all string data
69+
* @return {string} line
70+
*/
71+
getData () {
72+
return this.lines.join('\n')
73+
}
2974

30-
CodeWriter.prototype.fileName = function (className) {
31-
return className.replace(/([a-z])([A-Z])/g, '$1_$2').toLowerCase();
32-
};
75+
/*
76+
* Return file name by converting class name to snack case
77+
* @param {string} class name
78+
* @return {string} file name
79+
*/
80+
getFileName (className) {
81+
return className.replace(/([a-z])([A-Z])/g, '$1_$2').toLowerCase()
82+
}
3383

34-
CodeWriter.prototype.toCamelCase = function (className) {
84+
/*
85+
* Convert class name to camel case
86+
* @param {string} class name
87+
* @return {string} converted class name
88+
*/
89+
toCamelCase (className) {
3590
return className.replace(/(\b|_)\w/g, function (match) {
36-
return match.replace(/_/, '').toUpperCase();
37-
});
38-
};
91+
return match.replace(/_/, '').toUpperCase()
92+
})
93+
}
94+
}
3995

40-
exports.CodeWriter = CodeWriter;
41-
});
96+
exports.CodeWriter = CodeWriter

main.js

Lines changed: 79 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,89 @@
1-
define(function (require, exports, module) {
2-
'use strict';
1+
/*
2+
* Copyright (c) 2016-2018 Andrias Meisyal. All rights reserved.
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a
5+
* copy of this software and associated documentation files (the "Software"),
6+
* to deal in the Software without restriction, including without limitation
7+
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
8+
* and/or sell copies of the Software, and to permit persons to whom the
9+
* Software is furnished to do so, subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included in
12+
* all copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19+
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
20+
* IN THE SOFTWARE.
21+
*/
322

4-
var Commands = app.getModule('command/Commands');
5-
var CommandManager = app.getModule('command/CommandManager');
6-
var MenuManager = app.getModule('menu/MenuManager');
7-
var Dialogs = app.getModule('dialogs/Dialogs');
8-
var ElementPickerDialog = app.getModule('dialogs/ElementPickerDialog');
9-
var FileSystem = app.getModule('filesystem/FileSystem');
23+
const RubyCodeGenerator = require('./ruby-code-generator')
1024

11-
var CodeGenUtils = require('code-generator-utils');
12-
var RubyCodeGenerator = require('ruby-code-generator');
13-
var RubyPreferences = require('ruby-preferences');
14-
15-
var CMD_RUBY = 'ruby';
16-
var CMD_RUBY_GENERATE = 'ruby.generate';
17-
var CMD_RUBY_CONFIGURE = 'ruby.configure';
18-
19-
function _handleGenerate(base, path, options) {
20-
var result = new $.Deferred();
21-
options = options || RubyPreferences.getGenerateOptions();
25+
function getGeneratorOptions () {
26+
return {
27+
useTab: app.preferences.get('ruby.generator.useTab'),
28+
indentSpaces: app.preferences.get('ruby.generator.indentSpaces'),
29+
initializeMethod: app.preferences.get('ruby.generator.initializeMethod'),
30+
toStringMethod: app.preferences.get('ruby.generator.toStringMethod'),
31+
documentation: app.preferences.get('ruby.generator.documentation')
32+
}
33+
}
2234

23-
if (!base) {
24-
ElementPickerDialog.showDialog('Select a base model to generate codes', null, type.UMLPackage)
25-
.done(function (buttonId, selected) {
26-
if (buttonId === Dialogs.DIALOG_BTN_OK && selected) {
27-
base = selected;
28-
if (!path) {
29-
FileSystem.showOpenDialog(false, true, 'Select a folder where generated codes to be located', null, null, function (error, files) {
30-
if (!error) {
31-
if (files) {
32-
path = files[0];
33-
RubyCodeGenerator.generate(base, path, options).then(result.resolve, result.reject);
34-
} else {
35-
result.reject(FileSystem.USER_CANCELED);
36-
}
37-
} else {
38-
result.reject(error);
39-
}
40-
});
41-
} else {
42-
RubyCodeGenerator.generate(base, path, options).then(result.resolve, result.reject);
43-
}
44-
} else {
45-
result.reject();
35+
/*
36+
* Command Handler for Ruby Generate
37+
*
38+
* @param {Element} base
39+
* @param {string} path
40+
* @param {Object} options
41+
* @return {$.Promise}
42+
*/
43+
function _handleGenerate (base, path, options) {
44+
// If options is not passed, get from preference
45+
options = options || getGeneratorOptions()
46+
// If base is not assigned, popup ElementPicker
47+
if (!base) {
48+
app.elementPickerDialog.showDialog('Select a base model to generate codes', null, type.UMLPackage).then(function ({buttonId, returnValue}) {
49+
if (buttonId === 'ok') {
50+
base = returnValue
51+
// If path is not assigned, popup Open Dialog to select a folder
52+
if (!path) {
53+
var files = app.dialogs.showOpenDialog('Select a folder where generated codes to be located', null, null, { properties: ['openDirectory']})
54+
if (files && files.length > 0) {
55+
path = files[0]
56+
RubyCodeGenerator.generate(base, path, options)
4657
}
47-
});
58+
} else {
59+
RubyCodeGenerator.generate(base, path, options)
60+
}
61+
}
62+
})
63+
} else {
64+
// If path is not assigned, popup Open Dialog to select a folder
65+
if (!path) {
66+
var files = app.dialogs.showOpenDialog('Select a folder where generated codes to be located', null, null, { properties: ['openDirectory']})
67+
if (files && files.length > 0) {
68+
path = files[0]
69+
RubyCodeGenerator.generate(base, path, options)
70+
}
4871
} else {
49-
window.alert('NotImplementedError');
72+
RubyCodeGenerator.generate(base, path, options)
5073
}
51-
52-
return result.promise();
5374
}
75+
}
5476

55-
function _handleConfigure() {
56-
CommandManager.execute(Commands.FILE_PREFERENCES, RubyPreferences.getId());
57-
}
77+
/*
78+
* Popup PreferenceDialog with Ruby Preference Schema
79+
*/
80+
function _handleConfigure () {
81+
app.commands.execute('application:preferences', 'ruby')
82+
}
5883

59-
CommandManager.register('Ruby', CMD_RUBY, CommandManager.doNothing);
60-
CommandManager.register('Generate Code...', CMD_RUBY_GENERATE, _handleGenerate);
61-
CommandManager.register('Configure...', CMD_RUBY_CONFIGURE, _handleConfigure);
84+
function init () {
85+
app.commands.register('ruby:generate', _handleGenerate)
86+
app.commands.register('ruby:configure', _handleConfigure)
87+
}
6288

63-
var menu = MenuManager.getMenu(Commands.TOOLS);
64-
var menuItem = menu.addMenuItem(CMD_RUBY);
65-
menuItem.addMenuItem(CMD_RUBY_GENERATE);
66-
menuItem.addMenuDivider();
67-
menuItem.addMenuItem(CMD_RUBY_CONFIGURE);
68-
});
89+
exports.init = init

menus/menu.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"menu": [
3+
{
4+
"id": "tools",
5+
"submenu": [
6+
{
7+
"label": "Ruby",
8+
"id": "tools.ruby",
9+
"submenu": [
10+
{ "label": "Generate Code...", "id": "tools.ruby.generate", "command": "ruby:generate" },
11+
{ "type": "separator" },
12+
{ "label": "Configure...", "id": "tools.ruby.configure", "command": "ruby:configure" }
13+
]
14+
}
15+
]
16+
}
17+
]
18+
}

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55
"homepage": "https://github.com/meisyal/staruml-ruby",
66
"issues": "https://github.com/meisyal/staruml-ruby/issues",
77
"keywords": ["ruby"],
8-
"version": "0.1.6",
8+
"version": "0.1.7",
99
"author": {
1010
"name": "Andrias Meisyal",
1111
"email": "[email protected]",
1212
"url": "https://github.com/meisyal"
1313
},
1414
"license": "MIT",
1515
"engines": {
16-
"staruml": ">=2.0.0"
16+
"staruml": "^3.0.0"
1717
}
1818
}

preferences/preference.json

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
{
2+
"id": "ruby",
3+
"name": "Ruby",
4+
"schema": {
5+
"ruby.generator": {
6+
"text": "Ruby Code Generation",
7+
"type": "section"
8+
},
9+
"ruby.generator.useTab": {
10+
"text": "Use Tab",
11+
"description": "Use tab for indentation instead of spaces.",
12+
"type": "check",
13+
"default": false
14+
},
15+
"ruby.generator.indentSpaces": {
16+
"text": "Indent Spaces",
17+
"description": "Number of spaces for indentation.",
18+
"type": "number",
19+
"default": 2
20+
},
21+
"ruby.generator.initializeMethod": {
22+
"text": "The initialize method",
23+
"description": "Generate initialize method that works almost same way as constructor.",
24+
"type": "check",
25+
"default": true
26+
},
27+
"ruby.generator.toStringMethod": {
28+
"text": "The to_s method",
29+
"description": "Generate to_s method that returns a string representation of the object.",
30+
"type": "check",
31+
"default": true
32+
},
33+
"ruby.generator.documentation": {
34+
"text": "Documentation",
35+
"description": "Generate documentation of class elements.",
36+
"type": "check",
37+
"default": true
38+
}
39+
}
40+
}

0 commit comments

Comments
 (0)