diff --git a/README.md b/README.md index 0a1cdff..d8d726b 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,7 @@ Example ------------ ```js + var styler = new ObjectStyler.Styler({punctuation: "codeSyl", blockIndent : "indentedSyl", endLine: "endLineSyl"}, [ {name: "codeSyl", className: "grey"}, {name: "greenSyl", className: "green"}, @@ -34,7 +35,8 @@ var style = { obj1 : {k:'greenSyl', v: { obj1Key1 : {k:'redSyl', v:'fancy'} }}, - numberArray : {k:['bigSyl', 'greenSyl'], v: ['bigSyl', 'codeSyl']} + numberArray : {k:['bigSyl', 'greenSyl'], v:['bigSyl', 'codeSyl']}, + objectArray : {v:{key1:{k:'greenSyl',v:'redSyl'}}} } document.body.innerHTML = styler.style(obj,style); diff --git a/doc/example.png b/doc/example.png index f98d3e0..bf15cd0 100644 Binary files a/doc/example.png and b/doc/example.png differ diff --git a/src/Styler.ts b/src/Styler.ts index 8d02058..bd5f403 100644 --- a/src/Styler.ts +++ b/src/Styler.ts @@ -59,18 +59,22 @@ module ObjectStyler { } return html; } - private styleArray(array: any[], activatedStyles: string[]) : HTML { + private styleArray(array: any[], activaSyls: string[] | StyleDiscription) : HTML { + var valSyl = (activaSyls instanceof Array? activaSyls : []); + var objectSyl = (typeof activaSyls === 'object'? activaSyls: {}); + + var htmlResult = this.styleSpan("[", [this.punctuationStyleName]); for(var i = 0 ; i < array.length ; i++) { if(i !== 0) { htmlResult += this.styleSpan(", ", [this.punctuationStyleName]); } if(array[i] instanceof Array) { - htmlResult += this.styleArray(array[i], activatedStyles); + htmlResult += this.styleArray(array[i], activaSyls); } else if (typeof array[i] === "object" ) { - htmlResult += this.styleObject(array[i], {}); + htmlResult += this.styleObject(array[i], objectSyl); } else { - htmlResult += this.styleValue(array[i], activatedStyles); + htmlResult += this.styleValue(array[i], valSyl); } } htmlResult += this.styleSpan("]", [this.punctuationStyleName]); @@ -132,12 +136,8 @@ module ObjectStyler { // value if(object[key] instanceof Array) { - var arraySyls = getValueActiveStyles(styleDisc[key],[]); - if(arraySyls instanceof Array) { - html += this.styleArray(object[key],arraySyls); - } else { - html += this.styleArray(object[key],[]); - } + var syls = getValueActiveStyles(styleDisc[key],[]); + html += this.styleArray(object[key],syls); } else if(typeof object[key] === "object") { diff --git a/tests/simple.html b/tests/simple.html index 02394e1..f7fb1f1 100644 --- a/tests/simple.html +++ b/tests/simple.html @@ -50,7 +50,8 @@ obj1 : {k:'greenSyl', v: { obj1Key1 : {k:'redSyl', v:'fancy'} }}, - numberArray : {k:['bigSyl', 'greenSyl'], v: ['bigSyl', 'codeSyl']} + numberArray : {k:['bigSyl', 'greenSyl'], v:['bigSyl', 'codeSyl']}, + objectArray : {v:{key1:{k:'greenSyl',v:'redSyl'}}} } document.body.innerHTML = styler.style(obj,style);