Skip to content

Commit

Permalink
Merge branch 'master' of github.com:mde/geddy
Browse files Browse the repository at this point in the history
* 'master' of github.com:mde/geddy:
  Updated doc-generation tasks.
  Add geddy.utils.XML.stringify for XML output
  Version 0.3.4
  • Loading branch information
Techwraith committed Feb 15, 2012
2 parents 5f43094 + d05453e commit b0d17a9
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 25 deletions.
32 changes: 8 additions & 24 deletions Jakefile
Expand Up @@ -44,7 +44,7 @@ namespace('gen', function () {
return names;
};

desc('Creates a new Geddy app scaffold.');
// Creates a new Geddy app scaffold
task('app', [], function (appName) {
if (!appName) {
throw new Error('No app-name specified.');
Expand Down Expand Up @@ -76,7 +76,7 @@ namespace('gen', function () {
});
}, {async: true});

desc('Creates a resource-based route with model and controller.');
// Creates a resource-based route with model and controller
task('resource', function (name) {
jake.Task['gen:model'].invoke(name);
jake.Task['gen:controller'].invoke(name);
Expand Down Expand Up @@ -187,46 +187,30 @@ namespace('gen', function () {
});

namespace('doc', function () {
desc('Generate docs for Geddy');
task('generate', ['doc:clobber'], function () {
var cmd = '../node-jsdoc-toolkit/app/run.js -n -r=100 ' +
'-t=../node-jsdoc-toolkit/templates/codeview -d=./doc/ ./lib';
console.log('Generating docs ...');
exec(cmd, function (err, stdout, stderr) {
if (err) {
throw err;
}
if (stderr) {
console.log(stderr);
}
if (stdout) {
console.log(stdout);
}
jake.exec([cmd], function () {
console.log('Done.');
complete();
});
}, {async: true});

desc('Clobber the generated docs.');
task('clobber', function () {
var cmd = 'rm -fr ./doc/*';
exec(cmd, function (err, stdout, stderr) {
if (err) {
throw err;
}
if (stderr) {
console.log(stderr);
}
if (stdout) {
console.log(stdout);
}
jake.exec([cmd], function () {
console.log('Clobbered old docs.');
complete();
});
}, {async: true});

});

desc('Generate docs for Geddy');
task('doc', ['doc:generate']);


desc('Runs the tests.');
task('test', function () {
var dir = process.cwd()
Expand Down
2 changes: 2 additions & 0 deletions lib/utils/index.js
Expand Up @@ -22,6 +22,7 @@ var geddy
, date = require('./date').date
, request = require('./request').request
, EventBuffer = require('./event_buffer').EventBuffer
, XML = require('./xml').XML
, SortedCollection = require('./sorted_collection').SortedCollection;

var utils = new (function () {
Expand Down Expand Up @@ -116,6 +117,7 @@ utils.date = date;
utils.request = request;
utils.SortedCollection = SortedCollection;
utils.EventBuffer = EventBuffer;
utils.XML = XML;

module.exports = utils;

51 changes: 51 additions & 0 deletions lib/utils/xml.js
@@ -0,0 +1,51 @@
/* This work is licensed under Creative Commons GNU LGPL License.
License: http://creativecommons.org/licenses/LGPL/2.1/
Version: 0.9
Author: Stefan Goessner/2006
Web: http://goessner.net/
*/
function json2xml(o, tab) {
var toXml = function(v, name, ind) {
var xml = "";
if (v instanceof Array) {
for (var i=0, n=v.length; i<n; i++)
xml += ind + toXml(v[i], name, ind+"\t") + "\n";
}
else if (typeof(v) == "object") {
var hasChild = false;
xml += ind + "<" + name;
for (var m in v) {
if (m.charAt(0) == "@")
xml += " " + m.substr(1) + "=\"" + v[m].toString() + "\"";
else
hasChild = true;
}
xml += hasChild ? ">" : "/>";
if (hasChild) {
for (var m in v) {
if (m == "#text")
xml += v[m];
else if (m == "#cdata")
xml += "<![CDATA[" + v[m] + "]]>";
else if (m.charAt(0) != "@")
xml += toXml(v[m], m, ind+"\t");
}
xml += (xml.charAt(xml.length-1)=="\n"?ind:"") + "</" + name + ">";
}
}
else {
xml += ind + "<" + name + ">" + v.toString() + "</" + name + ">";
}
return xml;
}, xml="";
for (var m in o)
xml += toXml(o[m], m, "");
return tab ? xml.replace(/\t/g, tab) : xml.replace(/\t|\n/g, "");
}

exports.XML = new function XML() {
this.stringify = function(o) {
return json2xml(o);
};
};
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -7,7 +7,7 @@
"REST",
"MVC"
],
"version": "0.3.3",
"version": "0.3.4",
"author": "Matthew Eernisse <mde@fleegix.org> (http://fleegix.org)",
"dependencies": {
"jake": "0.2.x"
Expand Down

0 comments on commit b0d17a9

Please sign in to comment.