File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11export class baseXMLBUilder {
22 protected _data : string [ ] = [ ] ;
3+ private tab : string = " " ;
4+ private indent : number = 0 ;
35
46 protected putTag ( name : string , attr : { [ key : string ] : string } ,
57 contents ?: ( ( ) => void ) | string ) {
6- const attrStr =
7- Object . entries ( attr )
8+ const attrStr = ( ( ) => {
9+ const a = Object . entries ( attr )
810 . map ( ( [ key , value ] ) => { return `${ key } ="${ value } "` ; } )
911 . join ( ' ' ) ;
12+ return a ? " " + a : "" ;
13+ } ) ( ) ;
1014
1115 if ( ! contents ) {
12- this . _data . push ( `<${ name } ${ attrStr } />` ) ;
16+ this . _data . push ( `${ this . tab . repeat ( this . indent ) } <${ name } ${ attrStr } />` ) ;
1317 return ;
1418 }
1519
16- this . _data . push ( `<${ name } ${ attrStr } >` ) ;
20+ this . _data . push ( `${ this . tab . repeat ( this . indent ) } <${ name } ${ attrStr } >` ) ;
1721 if ( typeof contents === "function" ) {
22+ this . indent ++ ;
1823 contents ( ) ;
19- this . _data . push ( `</${ name } >` ) ;
24+ this . indent --
25+ this . _data . push ( `${ this . tab . repeat ( this . indent ) } </${ name } >` ) ;
2026 } else {
21- const tmp : string [ ] = [ contents , `</${ name } >` ] ;
22- this . _data [ this . _data . length - 1 ] += tmp . join ( "" ) ;
27+ this . _data [ this . _data . length - 1 ] += `${ contents } </${ name } >` ;
2328 }
2429 }
2530
You can’t perform that action at this time.
0 commit comments