Skip to content

Commit

Permalink
use commonjs module system for jm
Browse files Browse the repository at this point in the history
  • Loading branch information
smtlaissezfaire committed Apr 28, 2010
1 parent 2828fe9 commit 27a6702
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 21 deletions.
48 changes: 28 additions & 20 deletions lib/jm.js
@@ -1,12 +1,12 @@
JM = {
var jm = {
major: 0,
minor: 0,
tiny: 1
};

JM.version = JM.major + "." + JM.minor + "." + JM.tiny;
jm.version = jm.major + "." + jm.minor + "." + jm.tiny;

JM.Helpers = {
jm.Helpers = {
forEach: function(obj, fun) {
var value_only = true,
x;
Expand All @@ -22,7 +22,7 @@ JM.Helpers = {
forEachProperty: function(obj, fun) {
var property;

JM.Helpers.forEach(obj, function(key, value) {
jm.Helpers.forEach(obj, function(key, value) {
if (obj.hasOwnProperty(key)) {
fun(key, value);
}
Expand All @@ -32,7 +32,7 @@ JM.Helpers = {
map: function(collection, fun) {
var new_collection = [];

JM.Helpers.forEach(collection, function(element) {
jm.Helpers.forEach(collection, function(element) {
new_collection.push(fun(element));
});

Expand All @@ -50,7 +50,7 @@ JM.Helpers = {
}
};

JM.render = function(locals, code) {
jm.render = function(locals, code) {
if (typeof(code) === 'undefined') {
if (locals instanceof Function) {
code = locals;
Expand All @@ -60,7 +60,7 @@ JM.render = function(locals, code) {
}
}

var builder = new JM.Builder;
var builder = new jm.Builder;

if (code instanceof Function) {
code = "(" + code.toString() + ")();";
Expand All @@ -77,15 +77,15 @@ JM.render = function(locals, code) {
return builder.toHTML();
};

JM.Builder = function() {
if (this instanceof JM.Builder) {
jm.Builder = function() {
if (this instanceof jm.Builder) {
return this;
} else {
return new JM.Builder;
return new jm.Builder;
}
};

JM.Builder.selfClosingTags = [
jm.Builder.selfClosingTags = [
'base',
'meta',
'link',
Expand All @@ -99,7 +99,7 @@ JM.Builder.selfClosingTags = [
'frame'
];

JM.Builder.blockTags = [
jm.Builder.blockTags = [
'html',
'head',
'title',
Expand Down Expand Up @@ -200,10 +200,10 @@ JM.Builder.blockTags = [
'h1'
];

JM.Builder.prototype = (function() {
jm.Builder.prototype = (function() {
var builder = {},
forEach = JM.Helpers.forEach,
forEachProperty = JM.Helpers.forEachProperty;
forEach = jm.Helpers.forEach,
forEachProperty = jm.Helpers.forEachProperty;

builder.concat = function(str) {
this.buffer += str;
Expand All @@ -216,7 +216,7 @@ JM.Builder.prototype = (function() {
this.indentation_level += this.indentation_spaces;

this.concat("\n");
this.concat(JM.Helpers.stringMultiply(" ", this.indentation_level));
this.concat(jm.Helpers.stringMultiply(" ", this.indentation_level));
}
};

Expand All @@ -225,7 +225,7 @@ JM.Builder.prototype = (function() {
this.indentation_level -= this.indentation_spaces;

this.concat("\n");
this.concat(JM.Helpers.stringMultiply(" ", this.indentation_level));
this.concat(jm.Helpers.stringMultiply(" ", this.indentation_level));
}
};

Expand Down Expand Up @@ -261,13 +261,13 @@ JM.Builder.prototype = (function() {
return this.toHTML();
};

forEach(JM.Builder.blockTags, function(tag) {
forEach(jm.Builder.blockTags, function(tag) {
builder[tag] = function() {
return this.node(tag, arguments[0], false, arguments[1]);
};
});

forEach(JM.Builder.selfClosingTags, function(tag) {
forEach(jm.Builder.selfClosingTags, function(tag) {
builder[tag] = function() {
return this.node(tag, arguments[0], true);
};
Expand All @@ -283,4 +283,12 @@ JM.Builder.prototype = (function() {
builder.indentation_spaces = 2;

return builder;
})();
})();

if (typeof(exports) === 'object') {
for (key in jm) {
if (jm.hasOwnProperty(key)) {
exports[key] = jm[key];
}
}
}
2 changes: 1 addition & 1 deletion spec/node.js
Expand Up @@ -2,7 +2,7 @@ require('./vendor/jspec/lib/jspec');
require('./vendor/jspec_dot_reporter/jspec_dot_reporter');
require('./unit/spec.helper');
require.paths.unshift("./lib");
require("jm");
JM = require("jm");

JSpec
.exec('spec/unit/spec.js')
Expand Down

0 comments on commit 27a6702

Please sign in to comment.