DocumentNodeElement wlxml class getting/setting
authorAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Tue, 9 Jul 2013 10:32:24 +0000 (12:32 +0200)
committerAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Tue, 9 Jul 2013 10:32:24 +0000 (12:32 +0200)
modules/documentCanvas/canvas/canvas.test3.js
modules/documentCanvas/canvas/documentElement.js

index 253a97c..3c25cf5 100644 (file)
@@ -46,7 +46,18 @@ describe('Canvas', function() {
             expect(c.doc().wlxmlTag).to.equal('section');
         });
 
             expect(c.doc().wlxmlTag).to.equal('section');
         });
 
-        describe('DocumentElement', function() {
+        describe('DocumentTextElement', function() {
+            it('can have its content set', function() {
+                var c = canvas.fromXML('<section>Alice</section>'),
+                    root = c.doc(),
+                    text = root.children()[0];
+                
+                text.setText('a cat');
+                expect(root.children()[0].getText()).to.equal('a cat');
+            });
+        });
+
+        describe('DocumentNodeElement', function() {
             it('knows index of its child', function() {
                 var c = canvas.fromXML('<section><div></div><header></header><span></span></section>'),
                     root = c.doc(),
             it('knows index of its child', function() {
                 var c = canvas.fromXML('<section><div></div><header></header><span></span></section>'),
                     root = c.doc(),
@@ -54,17 +65,26 @@ describe('Canvas', function() {
                 expect(root.childIndex(child)).to.equal(1);
             });
 
                 expect(root.childIndex(child)).to.equal(1);
             });
 
-            describe('DocumentTextElement can have its content set', function() {
-                var c = canvas.fromXML('<section>Alice</section>'),
-                    root = c.doc(),
-                    text = root.children()[0];
-                
-                text.setText('a cat');
-                expect(root.children()[0].getText()).to.equal('a cat');
+            it('knows WLXML tag it renders', function(){
+                var c = canvas.fromXML('<section></section>'),
+                    section = c.doc();
+                expect(section.getWlxmlTag()).to.equal('section', 'initial tag is section');
+                section.setWlxmlTag('header');
+                expect(section.getWlxmlTag()).to.equal('header', 'tag is changed to header');
+            });
+
+            it('knows WLXML class of a WLXML tag it renders', function(){
+                var c = canvas.fromXML('<section class="some.class"></section>'),
+                    section = c.doc();
+                expect(section.getWlxmlClass()).to.equal('some.class');
+                section.setWlxmlClass('some.other.class');
+                expect(section.getWlxmlClass()).to.equal('some.other.class');
             });
         });
     });
 
             });
         });
     });
 
+
+
     describe('document representation api', function() {
         describe('document root element', function() {
             var c = canvas.fromXML('<section></section>');
     describe('document representation api', function() {
         describe('document root element', function() {
             var c = canvas.fromXML('<section></section>');
index 0d08aab..e18f856 100644 (file)
@@ -105,8 +105,17 @@ $.extend(DocumentNodeElement.prototype, {
     after: function(params) {
         manipulate(this, params, 'after');
     },
     after: function(params) {
         manipulate(this, params, 'after');
     },
+    getWlxmlTag: function() {
+        return this.$element.attr('wlxml-tag');
+    },
+    setWlxmlTag: function(tag) {
+        this.$element.attr('wlxml-tag', tag);
+    },
+    getWlxmlClass: function() {
+        return this.$element.attr('wlxml-class').replace('-', '.');
+    },
     setWlxmlClass: function(klass) {
     setWlxmlClass: function(klass) {
-        this.$element.attr('class', klass);
+        this.$element.attr('wlxml-class', klass);
     },
     is: function(what) {
         if(what === 'list' && _.contains(['list-items', 'list-items-enum'], this.$element.attr('wlxml-class')))
     },
     is: function(what) {
         if(what === 'list' && _.contains(['list-items', 'list-items-enum'], this.$element.attr('wlxml-class')))