Comparing version 1.6.0 to 1.6.4
{ | ||
"name": "vsvg", | ||
"version": "1.6.0", | ||
"version": "1.6.4", | ||
"description": "A minimal implementation of a vdom that allows for quick server or client side rendering of svg's", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -25,3 +25,3 @@ | ||
if ( tag.tagName ) { | ||
if ( tag.tagName && methods[ tag.tagName ] ) { | ||
@@ -48,3 +48,3 @@ elem = methods[ tag.tagName ]( tag.attributes ); | ||
return tag.text; | ||
return tag.text || ''; | ||
}; | ||
@@ -51,0 +51,0 @@ |
@@ -27,7 +27,10 @@ | ||
attributes = Object.create( attributes || {} ); | ||
this.guid = utils.guid(); | ||
this.tagName = tagName; | ||
this._children = []; | ||
this._attributes = Object.create( attributes || {} ); | ||
this.styles = {}; | ||
this.styles = attributes.style ? utils.styleToObject( attributes.style ) : {}; | ||
attributes.style = this.styles; | ||
this._attributes = attributes; | ||
} | ||
@@ -34,0 +37,0 @@ |
@@ -39,2 +39,29 @@ | ||
/* | ||
styleToObject - decompilies key:value to { key: value }; | ||
params | ||
styles { String } - compiled sting with css declarations | ||
retruns | ||
ret { Object } - object of style declarations | ||
*/ | ||
exports.styleToObject = function styleToObject( styles ) { | ||
var ret = { }; | ||
if ( typeof styles === 'object' ) { | ||
return styles; | ||
} | ||
styles.split( ';' ).map( keyVal ).forEach( addToReturn ); | ||
function addToReturn ( keyval ) { | ||
ret[ keyval[ 0 ] ] = keyval[ 1 ]; | ||
} | ||
function keyVal( str ) { | ||
return str.trim().split( ':' ); | ||
} | ||
return ret; | ||
}; | ||
/* | ||
objToAttribute - compiles { key: value } to key="value" | ||
@@ -55,3 +82,5 @@ params | ||
value = attr === 'style' ? objToStyles( attributes[ attr ] ) : attributes[ attr ]; | ||
ret += attr + '="' + value + '" '; | ||
if ( attr !== 'style' || value ) { | ||
ret += attr + '="' + value + '" '; | ||
} | ||
} | ||
@@ -58,0 +87,0 @@ return ret; |
@@ -23,2 +23,11 @@ var test = require( 'tape' ), | ||
test( 'testing styleToObject', function( t ) { | ||
var styles = utils.styleToObject( 'color:white;foo:bar;'); | ||
t.equals( typeof styles, 'object', 'deccompilied styles are an object' ); | ||
t.equals( styles.color, 'white', 'style declaration is correct' ); | ||
t.equals( styles.foo, 'bar', 'style declaration is correct' ); | ||
t.end(); | ||
} ); | ||
test( 'testing objToAttributes', function( t ){ | ||
@@ -25,0 +34,0 @@ var attributes = utils.objToAttributes({ |
Sorry, the diff of this file is not supported yet
98321
28
1476
5