Skip to content

Commit

Permalink
dd convenience methods
Browse files Browse the repository at this point in the history
  • Loading branch information
jrootham committed Sep 5, 2012
1 parent c9b68a2 commit e3b2914
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
lib
5 changes: 5 additions & 0 deletions spec/mhSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,9 @@ describe("Simple functions to build HTML strings", function(){
expect(mh.paired("div", "contents", [mh.nv("class","foo"),mh.nv("id","thing")]))
.toEqual('<div class="foo" id="thing">contents</div>');
});

it("paired with class and id options", function(){
expect(mh.paired("div", "contents", [mh.cl("foo"),mh.id("thing")]))
.toEqual('<div class="foo" id="thing">contents</div>');
});
});
17 changes: 17 additions & 0 deletions src/mh.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// Simple functions to ease construction of HTML strings

var mh = {

// single : a tag with no contents, includes its own terminator and options

// tag : HTML tag
Expand Down Expand Up @@ -43,5 +44,21 @@ var mh = {

nv : function(name, value) {
return {name: name, value: value};
},

// a convenience function to create an class options object

// value : class name
cl : function(value) {
return {name: 'class', value: value};
},

// a convenience function to create an id options object

// value : id name
id : function(value) {
return {name: 'id', value: value};
}


};
2 changes: 1 addition & 1 deletion testmh.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<link rel="stylesheet" type="text/css" href="lib/jasmine-1.2.0/jasmine.css">
<script type="text/javascript" src="lib/jasmine-1.2.0/jasmine.js"></script>
<script type="text/javascript" src="lib/jasmine-1.2.0/jasmine-html.js"></script>

<!-- include source files here... -->
<script type="text/javascript" src="src/mh.js"></script>

Expand Down

0 comments on commit e3b2914

Please sign in to comment.