refactor: Generators 1
This commit is contained in:
parent
ef1ccb093e
commit
f8f5c10c57
3 changed files with 21 additions and 39 deletions
|
|
@ -327,18 +327,6 @@ describe("LineByLineRenderer", () => {
|
|||
});
|
||||
});
|
||||
|
||||
describe("makeLineByLineHtmlWrapper", () => {
|
||||
it("should work for simple content", () => {
|
||||
const hoganUtils = new HoganJsUtils({});
|
||||
const lineByLineRenderer = new LineByLineRenderer(hoganUtils, {});
|
||||
const fileHtml = lineByLineRenderer.makeLineByLineHtmlWrapper("<span>Random Html</span>");
|
||||
|
||||
const expected = '<div class="d2h-wrapper">\n' + " <span>Random Html</span>\n" + "</div>";
|
||||
|
||||
expect(fileHtml).toEqual(expected);
|
||||
});
|
||||
});
|
||||
|
||||
describe("generateLineByLineJsonHtml", () => {
|
||||
it("should work for list of files", () => {
|
||||
const exampleJson: DiffFile[] = [
|
||||
|
|
|
|||
|
|
@ -32,17 +32,19 @@ export default class LineByLineRenderer {
|
|||
}
|
||||
|
||||
render(diffFiles: DiffFile[]): string | undefined {
|
||||
const htmlDiffs = diffFiles.map(file => {
|
||||
let diffs;
|
||||
if (file.blocks.length) {
|
||||
diffs = this.generateFileHtml(file);
|
||||
} else {
|
||||
diffs = this.generateEmptyDiff();
|
||||
}
|
||||
return this.makeFileDiffHtml(file, diffs);
|
||||
});
|
||||
const diffsHtml = diffFiles
|
||||
.map(file => {
|
||||
let diffs;
|
||||
if (file.blocks.length) {
|
||||
diffs = this.generateFileHtml(file);
|
||||
} else {
|
||||
diffs = this.generateEmptyDiff();
|
||||
}
|
||||
return this.makeFileDiffHtml(file, diffs);
|
||||
})
|
||||
.join("\n");
|
||||
|
||||
return this.makeLineByLineHtmlWrapper(htmlDiffs.join("\n"));
|
||||
return this.hoganUtils.render(genericTemplatesPath, "wrapper", { content: diffsHtml });
|
||||
}
|
||||
|
||||
// TODO: Make this private after improving tests
|
||||
|
|
@ -70,11 +72,6 @@ export default class LineByLineRenderer {
|
|||
});
|
||||
}
|
||||
|
||||
// TODO: Make this private after improving tests
|
||||
makeLineByLineHtmlWrapper(content: string): string {
|
||||
return this.hoganUtils.render(genericTemplatesPath, "wrapper", { content: content });
|
||||
}
|
||||
|
||||
// TODO: Make this private after improving tests
|
||||
makeColumnLineNumberHtml(block: DiffBlock): string {
|
||||
return this.hoganUtils.render(genericTemplatesPath, "column-line-number", {
|
||||
|
|
|
|||
|
|
@ -17,11 +17,6 @@ export const defaultSideBySideRendererConfig = {
|
|||
maxLineSizeInBlockForComparison: 200
|
||||
};
|
||||
|
||||
type FileHtml = {
|
||||
right: string;
|
||||
left: string;
|
||||
};
|
||||
|
||||
const genericTemplatesPath = "generic";
|
||||
const baseTemplatesPath = "side-by-side";
|
||||
const iconsBaseTemplatesPath = "icon";
|
||||
|
|
@ -37,7 +32,7 @@ export default class SideBySideRenderer {
|
|||
}
|
||||
|
||||
render(diffFiles: DiffFile[]): string | undefined {
|
||||
const content = diffFiles
|
||||
const diffsHtml = diffFiles
|
||||
.map(file => {
|
||||
let diffs;
|
||||
if (file.blocks.length) {
|
||||
|
|
@ -45,12 +40,11 @@ export default class SideBySideRenderer {
|
|||
} else {
|
||||
diffs = this.generateEmptyDiff();
|
||||
}
|
||||
|
||||
return this.makeDiffHtml(file, diffs);
|
||||
return this.makeFileDiffHtml(file, diffs);
|
||||
})
|
||||
.join("\n");
|
||||
|
||||
return this.hoganUtils.render(genericTemplatesPath, "wrapper", { content: content });
|
||||
return this.hoganUtils.render(genericTemplatesPath, "wrapper", { content: diffsHtml });
|
||||
}
|
||||
|
||||
// TODO: Make this private after improving tests
|
||||
|
|
@ -66,7 +60,7 @@ export default class SideBySideRenderer {
|
|||
}
|
||||
|
||||
// TODO: Make this private after improving tests
|
||||
makeDiffHtml(file: DiffFile, diffs: FileHtml): string {
|
||||
makeFileDiffHtml(file: DiffFile, diffs: FileHtml): string {
|
||||
const fileDiffTemplate = this.hoganUtils.template(baseTemplatesPath, "file-diff");
|
||||
const filePathTemplate = this.hoganUtils.template(genericTemplatesPath, "file-path");
|
||||
const fileIconTemplate = this.hoganUtils.template(iconsBaseTemplatesPath, "file");
|
||||
|
|
@ -307,8 +301,6 @@ export default class SideBySideRenderer {
|
|||
newLine.newNumber,
|
||||
newPrefix
|
||||
);
|
||||
} else {
|
||||
console.error("How did it get here?");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -355,3 +347,8 @@ export default class SideBySideRenderer {
|
|||
});
|
||||
}
|
||||
}
|
||||
|
||||
type FileHtml = {
|
||||
right: string;
|
||||
left: string;
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in a new issue