diff --git a/.gitignore b/.gitignore
index 4befed3..6d84185 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,2 +1,3 @@
.DS_Store
.idea
+node_modules
\ No newline at end of file
diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 0000000..b8e1f17
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,3 @@
+language: node_js
+node_js:
+ - 0.6
\ No newline at end of file
diff --git a/LICENSE b/LICENSE
deleted file mode 100644
index 09c6070..0000000
--- a/LICENSE
+++ /dev/null
@@ -1,7 +0,0 @@
-Copyright (C) 2012 Adrian Sieber
-
-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.
\ No newline at end of file
diff --git a/README.md b/README.md
index a1c05b5..40b470b 100644
--- a/README.md
+++ b/README.md
@@ -1,4 +1,6 @@
+[](https://travis-ci.org/microjs/DOMinate)
# DOMinate
+
A **DOM building utility** and **Template engine** build upon **JsonML** with syntax sugar.
## Features
@@ -9,55 +11,54 @@ A **DOM building utility** and **Template engine** build upon **JsonML** with sy
```javascript
- DOMinate(
- [document.body,
- ['h1#logo', 'Static Example', {style:'color:blue'}],
- ['p','some example text'],
- ['ul', {id:'list', class:'bullets'},
- ['li', 'item1'],
- ['li.active', 'item2'],
- ['li',
- ['a', 'item3', {href: '#'}]
- ]
- ]
- ]
- );
+DOMinate(
+ [document.body,
+ ['h1#logo', 'Static Example', {style:'color:blue'}],
+ ['p','some example text'],
+ ['ul', {id:'list', class:'bullets'},
+ ['li', 'item1'],
+ ['li.active', 'item2'],
+ ['li',
+ ['a', 'item3', {href: '#'}]
+ ]
+ ]
+ ]
+);
```
compiles to
```html
-
*/
+describe('essential', function () {
+ it('attaches to the first element', function () {
+ var element = document.createElementNS(ns, 'div');
+ DOMinate([element, ['div']]);
+ expect(element.children.length).to.be(1);
+ expect(element.children[0].__tag).to.be('div');
+ expect(element.children[0].__ns).to.be(ns);
+ });
+ it('recursively builds a DOM', function () {
+ var element = document.createElementNS(ns, 'div');
DOMinate(
- [this.gen,
+ [element,
['div',
['p', 'test',
['a', '2']
@@ -22,16 +23,31 @@ TestCase('Essential', {
]
]
);
+ expect(element.children.length).to.be(1);
- assertTrue(this.gen.outerHTML + ' == ' + this.ref.outerHTML, this.gen.isEqualNode(this.ref));
- },
+ element = element.children[0];
+ expect(element.__tag).to.be('div');
+ expect(element.__ns).to.be(ns);
+ expect(element.children.length).to.be(1);
- 'test setting of Properties': function () {
- /*:DOC gen = */
- /*:DOC ref =
*/
+ element = element.children[0];
+ expect(element.__tag).to.be('p');
+ expect(element.__ns).to.be(ns);
+ expect(element.children.length).to.be(2)
+ var text = element.children[0];
+ expect(text.text).to.be('test');
+ var a = element.children[1];
+ expect(a.__tag).to.be('a');
+ expect(a.__ns).to.be(ns);
+ expect(a.children.length).to.be(1);
+ expect(a.children[0].text).to.be('2');
+ });
+
+ it('sets properties when given an object', function () {
+ var element = document.createElementNS(ns, 'div');
DOMinate(
- [this.gen,
+ [element,
['div', {
id: 'important',
class: 'test', // class is restricted word
@@ -39,7 +55,12 @@ TestCase('Essential', {
}]
]
);
-
- assertTrue(this.gen.outerHTML + ' == ' + this.ref.outerHTML, this.gen.isEqualNode(this.ref));
- }
+ expect(element.children.length).to.be(1);
+ element = element.children[0];
+ expect(element.__tag).to.be('div');
+ expect(element.__ns).to.be(ns);
+ expect(element.id).to.be('important');
+ expect(element.className).to.be('test');
+ expect(element['data-info']).to.be('none');
+ });
});
\ No newline at end of file
diff --git a/test/extended_features.js b/test/extended_features.js
index b3e2d5b..ce7051c 100644
--- a/test/extended_features.js
+++ b/test/extended_features.js
@@ -1,33 +1,69 @@
-var reference, a, b, c,
- bo = document.body;
+var expect = require('expect.js');
+var DOMinate = require('..');
+require('./document-mock');
+var ns = 'http://www.w3.org/1999/xhtml';
-TestCase('Extended', {
- 'test syntax-sugar class': function () {
- /*:DOC ref =
*/
- /*:DOC gen = */
+describe('extended', function () {
+ describe('syntax-sugar class', function () {
+ it('works with just a class', function () {
+ var element = document.createElementNS(ns, 'div');
+ DOMinate([element, ['a.new']]);
+ expect(element.children.length).to.be(1);
+ expect(element.children[0].__ns).to.be(ns);
+ expect(element.children[0].__tag).to.be('a');
+ expect(element.children[0].className).to.be('new');
+ });
+ it('works with a class and an id', function () {
+ var element = document.createElementNS(ns, 'div');
+ DOMinate([element, ['a#b.new']]);
+ expect(element.children.length).to.be(1);
+ expect(element.children[0].__ns).to.be(ns);
+ expect(element.children[0].__tag).to.be('a');
+ expect(element.children[0].className).to.be('new');
+ expect(element.children[0].id).to.be('b');
+ });
+ it('works with class and id reversed', function () {
+ var element = document.createElementNS(ns, 'div');
+ DOMinate([element, ['a.new#b']]);
+ expect(element.children.length).to.be(1);
+ expect(element.children[0].__ns).to.be(ns);
+ expect(element.children[0].__tag).to.be('a');
+ expect(element.children[0].className).to.be('new');
+ expect(element.children[0].id).to.be('b');
+ });
+ });
+ describe('namespace support', function () {
+ describe('when a namespace is passed as the second argument', function () {
+ it('is used to create the elements', function () {
+ var svgNS = 'http://www.w3.org/2000/svg';
+ var element = document.createElementNS(ns, 'div');
+ DOMinate(
+ [element,
+ ['svg', {height: 100, width: 100},
+ ['circle', {cx: 10, cy: 10, r: 5, style: 'fill:green'}]
+ ]
+ ], svgNS
+ );
+ expect(element.__ns).to.be(ns);
+ expect(element.__tag).to.be('div');
+ expect(element.children.length).to.be(1);
- DOMinate([this.gen, ['a.new']]);
+ var svg = element.children[0];
+ expect(svg.__ns).to.be(svgNS);
+ expect(svg.__tag).to.be('svg');
+ expect(svg.height).to.be(100);
+ expect(svg.width).to.be(100);
+ expect(svg.children.length).to.be(1);
- assertTrue(this.gen.outerHTML + ' == ' + this.ref.outerHTML, this.gen.isEqualNode(this.ref));
- },
-
- 'test syntax-sugar class and id': function () {
- /*:DOC ref =
*/
- /*:DOC gen = */
-
- DOMinate([this.gen, ['a#b.new']]);
-
- assertTrue(this.gen.outerHTML + ' == ' + this.ref.outerHTML, this.gen.isEqualNode(this.ref));
- },
-
- 'test syntax-sugar class and id reversed': function () {
- /*:DOC ref =
*/
- /*:DOC gen = */
-
- DOMinate([this.gen, ['a.new#c']]);
-
- console.log(this.gen, this.ref);
-
- assertTrue(this.gen.outerHTML + ' == ' + this.ref.outerHTML, this.gen.isEqualNode(this.ref));
- }
+ var circle = svg.children[0];
+ expect(circle.__ns).to.be(svgNS);
+ expect(circle.__tag).to.be('circle');
+ expect(circle.cx).to.be(10);
+ expect(circle.cy).to.be(10);
+ expect(circle.r).to.be(5);
+ expect(circle.style).to.be('fill:green');
+ expect(circle.children.length).to.be(0);
+ });
+ });
+ });
});
\ No newline at end of file
diff --git a/test/standard_features.js b/test/standard_features.js
index c2d2345..b4dd66f 100644
--- a/test/standard_features.js
+++ b/test/standard_features.js
@@ -1,16 +1,20 @@
-TestCase('Standard', {
- 'test return of DOM element': function () {
- /*:DOC gen = */
+var expect = require('expect.js');
+var DOMinate = require('..');
+require('./document-mock');
+var ns = 'http://www.w3.org/1999/xhtml';
- assertEquals('Should return a node of type', 1, DOMinate([this.gen, ['a']]).nodeType);
- },
-
- 'test syntax-sugar id': function () {
- /*:DOC gen = */
- /*:DOC ref =
*/
-
- DOMinate([this.gen, ['div#test']]);
-
- assertTrue(this.gen.outerHTML + ' == ' + this.ref.outerHTML, this.gen.isEqualNode(this.ref));
- }
+describe('standard', function () {
+ it('returns the node that is the first element of the root array', function () {
+ var element = document.createElementNS(ns, 'div');
+ expect(DOMinate([element, ['a']])).to.be(element);
+ });
+
+ it('supports id syntax-sugar', function () {
+ var element = document.createElementNS(ns, 'div');
+ DOMinate([element, ['div#test']]);
+ expect(element.children.length).to.be(1);
+ expect(element.children[0].__ns).to.be(ns);
+ expect(element.children[0].__tag).to.be('div');
+ expect(element.children[0].id).to.be('test');
+ });
});
\ No newline at end of file