@@ -5,29 +5,37 @@ import { DiffFile } from './types';
55const baseTemplatesPath = 'file-summary' ;
66const iconsBaseTemplatesPath = 'icon' ;
77
8- export function render ( diffFiles : DiffFile [ ] , hoganUtils : HoganJsUtils ) : string {
9- const files = diffFiles
10- . map ( file =>
11- hoganUtils . render (
12- baseTemplatesPath ,
13- 'line' ,
14- {
15- fileHtmlId : renderUtils . getHtmlId ( file ) ,
16- oldName : file . oldName ,
17- newName : file . newName ,
18- fileName : renderUtils . filenameDiff ( file ) ,
19- deletedLines : '-' + file . deletedLines ,
20- addedLines : '+' + file . addedLines ,
21- } ,
22- {
23- fileIcon : hoganUtils . template ( iconsBaseTemplatesPath , renderUtils . getFileIcon ( file ) ) ,
24- } ,
25- ) ,
26- )
27- . join ( '\n' ) ;
8+ export class FileListRenderer {
9+ private readonly hoganUtils : HoganJsUtils ;
2810
29- return hoganUtils . render ( baseTemplatesPath , 'wrapper' , {
30- filesNumber : diffFiles . length ,
31- files : files ,
32- } ) ;
11+ constructor ( hoganUtils : HoganJsUtils ) {
12+ this . hoganUtils = hoganUtils ;
13+ }
14+
15+ render ( diffFiles : DiffFile [ ] ) : string {
16+ const files = diffFiles
17+ . map ( file =>
18+ this . hoganUtils . render (
19+ baseTemplatesPath ,
20+ 'line' ,
21+ {
22+ fileHtmlId : renderUtils . getHtmlId ( file ) ,
23+ oldName : file . oldName ,
24+ newName : file . newName ,
25+ fileName : renderUtils . filenameDiff ( file ) ,
26+ deletedLines : '-' + file . deletedLines ,
27+ addedLines : '+' + file . addedLines ,
28+ } ,
29+ {
30+ fileIcon : this . hoganUtils . template ( iconsBaseTemplatesPath , renderUtils . getFileIcon ( file ) ) ,
31+ } ,
32+ ) ,
33+ )
34+ . join ( '\n' ) ;
35+
36+ return this . hoganUtils . render ( baseTemplatesPath , 'wrapper' , {
37+ filesNumber : diffFiles . length ,
38+ files : files ,
39+ } ) ;
40+ }
3341}
0 commit comments