Update FileListRenderer to class
This commit is contained in:
parent
14989f1ddd
commit
4e6bb49788
3 changed files with 40 additions and 29 deletions
|
|
@ -1,4 +1,4 @@
|
||||||
import { render } from '../file-list-renderer';
|
import { FileListRenderer } from '../file-list-renderer';
|
||||||
import HoganJsUtils from '../hoganjs-utils';
|
import HoganJsUtils from '../hoganjs-utils';
|
||||||
|
|
||||||
describe('FileListRenderer', () => {
|
describe('FileListRenderer', () => {
|
||||||
|
|
@ -10,6 +10,7 @@ describe('FileListRenderer', () => {
|
||||||
'file-summary-line': '{{oldName}}, {{newName}}, {{fileName}}',
|
'file-summary-line': '{{oldName}}, {{newName}}, {{fileName}}',
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
const fileListRenderer = new FileListRenderer(hoganUtils);
|
||||||
const files = [
|
const files = [
|
||||||
{
|
{
|
||||||
isCombined: false,
|
isCombined: false,
|
||||||
|
|
@ -55,7 +56,7 @@ describe('FileListRenderer', () => {
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
const fileHtml = render(files, hoganUtils);
|
const fileHtml = fileListRenderer.render(files);
|
||||||
|
|
||||||
expect(fileHtml).toMatchInlineSnapshot(`
|
expect(fileHtml).toMatchInlineSnapshot(`
|
||||||
"my/file/name.js, my/file/name.js, my/file/name.js
|
"my/file/name.js, my/file/name.js, my/file/name.js
|
||||||
|
|
@ -67,6 +68,8 @@ describe('FileListRenderer', () => {
|
||||||
|
|
||||||
it('should work for all kinds of files', () => {
|
it('should work for all kinds of files', () => {
|
||||||
const hoganUtils = new HoganJsUtils({});
|
const hoganUtils = new HoganJsUtils({});
|
||||||
|
const fileListRenderer = new FileListRenderer(hoganUtils);
|
||||||
|
|
||||||
const files = [
|
const files = [
|
||||||
{
|
{
|
||||||
isCombined: false,
|
isCombined: false,
|
||||||
|
|
@ -111,7 +114,7 @@ describe('FileListRenderer', () => {
|
||||||
isDeleted: true,
|
isDeleted: true,
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
const fileHtml = render(files, hoganUtils);
|
const fileHtml = fileListRenderer.render(files);
|
||||||
expect(fileHtml).toMatchInlineSnapshot(`
|
expect(fileHtml).toMatchInlineSnapshot(`
|
||||||
"<div class="d2h-file-list-wrapper">
|
"<div class="d2h-file-list-wrapper">
|
||||||
<div class="d2h-file-list-header">
|
<div class="d2h-file-list-header">
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
import * as DiffParser from './diff-parser';
|
import * as DiffParser from './diff-parser';
|
||||||
import * as fileListPrinter from './file-list-renderer';
|
import { FileListRenderer } from './file-list-renderer';
|
||||||
import LineByLineRenderer, { LineByLineRendererConfig, defaultLineByLineRendererConfig } from './line-by-line-renderer';
|
import LineByLineRenderer, { LineByLineRendererConfig, defaultLineByLineRendererConfig } from './line-by-line-renderer';
|
||||||
import SideBySideRenderer, { SideBySideRendererConfig, defaultSideBySideRendererConfig } from './side-by-side-renderer';
|
import SideBySideRenderer, { SideBySideRendererConfig, defaultSideBySideRendererConfig } from './side-by-side-renderer';
|
||||||
import { DiffFile, OutputFormatType } from './types';
|
import { DiffFile, OutputFormatType } from './types';
|
||||||
|
|
@ -32,7 +32,7 @@ export function html(diffInput: string | DiffFile[], configuration: Diff2HtmlCon
|
||||||
|
|
||||||
const hoganUtils = new HoganJsUtils(config);
|
const hoganUtils = new HoganJsUtils(config);
|
||||||
|
|
||||||
const fileList = config.drawFileList ? fileListPrinter.render(diffJson, hoganUtils) : '';
|
const fileList = config.drawFileList ? new FileListRenderer(hoganUtils).render(diffJson) : '';
|
||||||
|
|
||||||
const diffOutput =
|
const diffOutput =
|
||||||
config.outputFormat === 'side-by-side'
|
config.outputFormat === 'side-by-side'
|
||||||
|
|
|
||||||
|
|
@ -5,29 +5,37 @@ import { DiffFile } from './types';
|
||||||
const baseTemplatesPath = 'file-summary';
|
const baseTemplatesPath = 'file-summary';
|
||||||
const iconsBaseTemplatesPath = 'icon';
|
const iconsBaseTemplatesPath = 'icon';
|
||||||
|
|
||||||
export function render(diffFiles: DiffFile[], hoganUtils: HoganJsUtils): string {
|
export class FileListRenderer {
|
||||||
const files = diffFiles
|
private readonly hoganUtils: HoganJsUtils;
|
||||||
.map(file =>
|
|
||||||
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: hoganUtils.template(iconsBaseTemplatesPath, renderUtils.getFileIcon(file)),
|
|
||||||
},
|
|
||||||
),
|
|
||||||
)
|
|
||||||
.join('\n');
|
|
||||||
|
|
||||||
return hoganUtils.render(baseTemplatesPath, 'wrapper', {
|
constructor(hoganUtils: HoganJsUtils) {
|
||||||
filesNumber: diffFiles.length,
|
this.hoganUtils = hoganUtils;
|
||||||
files: files,
|
}
|
||||||
});
|
|
||||||
|
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', {
|
||||||
|
filesNumber: diffFiles.length,
|
||||||
|
files: files,
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue