2019-12-29 22:31:32 +00:00
|
|
|
import * as renderUtils from './render-utils';
|
|
|
|
|
import HoganJsUtils from './hoganjs-utils';
|
2023-09-19 00:08:01 +00:00
|
|
|
import { ColorSchemeType, DiffFile } from './types';
|
2019-10-12 21:45:49 +00:00
|
|
|
|
2019-12-29 22:31:32 +00:00
|
|
|
const baseTemplatesPath = 'file-summary';
|
|
|
|
|
const iconsBaseTemplatesPath = 'icon';
|
2019-10-12 21:45:49 +00:00
|
|
|
|
2023-09-19 00:08:01 +00:00
|
|
|
export interface FileListRendererConfig {
|
|
|
|
|
colorScheme?: ColorSchemeType;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const defaultFileListRendererConfig = {
|
|
|
|
|
colorScheme: ColorSchemeType.LIGHT,
|
|
|
|
|
};
|
|
|
|
|
|
2023-09-18 23:41:51 +00:00
|
|
|
export class FileListRenderer {
|
|
|
|
|
private readonly hoganUtils: HoganJsUtils;
|
2023-09-19 00:08:01 +00:00
|
|
|
private readonly config: typeof defaultFileListRendererConfig;
|
2019-10-12 21:45:49 +00:00
|
|
|
|
2023-09-19 00:08:01 +00:00
|
|
|
constructor(hoganUtils: HoganJsUtils, config: FileListRendererConfig = {}) {
|
2023-09-18 23:41:51 +00:00
|
|
|
this.hoganUtils = hoganUtils;
|
2023-09-19 00:08:01 +00:00
|
|
|
this.config = { ...defaultFileListRendererConfig, ...config };
|
2023-09-18 23:41:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
render(diffFiles: DiffFile[]): string {
|
|
|
|
|
const files = diffFiles
|
|
|
|
|
.map(file =>
|
|
|
|
|
this.hoganUtils.render(
|
|
|
|
|
baseTemplatesPath,
|
|
|
|
|
'line',
|
|
|
|
|
{
|
|
|
|
|
fileHtmlId: renderUtils.getHtmlId(file),
|
|
|
|
|
oldName: file.oldName,
|
|
|
|
|
newName: file.newName,
|
|
|
|
|
fileName: renderUtils.filenameDiff(file),
|
|
|
|
|
deletedLines: '-' + file.deletedLines,
|
|
|
|
|
addedLines: '+' + file.addedLines,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
fileIcon: this.hoganUtils.template(iconsBaseTemplatesPath, renderUtils.getFileIcon(file)),
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
.join('\n');
|
|
|
|
|
|
|
|
|
|
return this.hoganUtils.render(baseTemplatesPath, 'wrapper', {
|
2023-09-19 00:08:01 +00:00
|
|
|
colorScheme: renderUtils.colorSchemeToCss(this.config.colorScheme),
|
2023-09-18 23:41:51 +00:00
|
|
|
filesNumber: diffFiles.length,
|
|
|
|
|
files: files,
|
|
|
|
|
});
|
|
|
|
|
}
|
2019-10-12 21:45:49 +00:00
|
|
|
}
|