Skip to content

Instantly share code, notes, and snippets.

@xcriptus
Created December 14, 2012 17:22
Show Gist options
  • Save xcriptus/4287124 to your computer and use it in GitHub Desktop.
Save xcriptus/4287124 to your computer and use it in GitHub Desktop.
Predefined function in staruml templates
/////////////////////////////////////////////////
// createFile :
//
function createFile(path) {
notify('Creating file '+ path + '...');
return fileObject.CreateTextFile(path, true, false);
}
/////////////////////////////////////////////////
// deleteFile :
//
function deleteFile(path) {
notify('Deleting file '+ path + '...');
fileObject.DeleteFile(path, false);
}
/////////////////////////////////////////////////
// createFolder :
//
function createFolder(path) {
notify('Creating folder '+ path + '...');
return fileObject.CreateFolder(path);
}
/////////////////////////////////////////////////
// deleteFolder :
//
function deleteFolder(path) {
notify('Deleting folder '+ path + '...');
fileObject.deleteFolder(path);
}
/////////////////////////////////////////////////
// fileExists :
//
function fileExists(path) {
return fileObject.FileExists(path);
}
/////////////////////////////////////////////////
// fileExists :
//
function folderExists(path) {
return fileObject.FolderExists(path);
}
/////////////////////////////////////////////////
// fileBegin :
//
function fileBegin(path) {
fileExceptionOccurred = false;
try
{
var cs;
if (fileExists(path)) {
cs = fileObject.CreateTextFile(path, true, false);
} else {
var ep = path.lastIndexOf("\\");
if (ep > -1) {
var folder = path.substr(0, ep);
if (!folderExists(folder))
createFolder(folder);
}
cs = createFile(path);
}
outputStreamStack.push(os);
os = cs;
}
catch (ex)
{
fileExceptionOccurred = true;
}
}
/////////////////////////////////////////////////
// fileEnd :
//
function fileEnd() {
if (!fileExceptionOccurred) {
os.close();
os = outputStreamStack.pop();
} else {
// ...?
}
}
/////////////////////////////////////////////////
// getTarget() :
//
function getTarget() {
return targetPath;
}
/////////////////////////////////////////////////
// getArgument()
//
function getArgument(name) {
for (var i=0; i<argKeys.length; i++)
if (argKeys[i] == name)
return argValues[i];
return "";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment