Skip to content

Commit

Permalink
Merge branch 'release-0.1.7'
Browse files Browse the repository at this point in the history
  • Loading branch information
meisyal committed Jun 30, 2018
2 parents e696c45 + d7ecc76 commit c00dd14
Show file tree
Hide file tree
Showing 9 changed files with 694 additions and 491 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2016-2017 Andrias Meisyal
Copyright (c) 2016-2018 Andrias Meisyal

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# staruml-ruby

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

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

Copyright © 2016-2017 Andrias Meisyal.
Copyright © 2016-2018 Andrias Meisyal.

[staruml]: http://staruml.io
[umlconcept]:
Expand Down
111 changes: 83 additions & 28 deletions code-generator-utils.js
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
137 changes: 79 additions & 58 deletions main.js
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
18 changes: 18 additions & 0 deletions menus/menu.json
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" }
]
}
]
}
]
}
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
"homepage": "https://github.com/meisyal/staruml-ruby",
"issues": "https://github.com/meisyal/staruml-ruby/issues",
"keywords": ["ruby"],
"version": "0.1.6",
"version": "0.1.7",
"author": {
"name": "Andrias Meisyal",
"email": "andriasonline@gmail.com",
"url": "https://github.com/meisyal"
},
"license": "MIT",
"engines": {
"staruml": ">=2.0.0"
"staruml": "^3.0.0"
}
}
40 changes: 40 additions & 0 deletions preferences/preference.json
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
}
}
}
Loading

0 comments on commit c00dd14

Please sign in to comment.