Skip to content
This repository has been archived by the owner on Nov 24, 2018. It is now read-only.

Commit

Permalink
Added Object styles in arrays
Browse files Browse the repository at this point in the history
examples and picture updated
  • Loading branch information
alshakh committed May 24, 2015
1 parent 211b51d commit 75b645b
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 12 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
Expand Down Expand Up @@ -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);
Expand Down
Binary file modified doc/example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 10 additions & 10 deletions src/Styler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down Expand Up @@ -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") {

Expand Down
3 changes: 2 additions & 1 deletion tests/simple.html
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 75b645b

Please sign in to comment.