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", () => {
|
describe("generateLineByLineJsonHtml", () => {
|
||||||
it("should work for list of files", () => {
|
it("should work for list of files", () => {
|
||||||
const exampleJson: DiffFile[] = [
|
const exampleJson: DiffFile[] = [
|
||||||
|
|
|
||||||
|
|
@ -32,17 +32,19 @@ export default class LineByLineRenderer {
|
||||||
}
|
}
|
||||||
|
|
||||||
render(diffFiles: DiffFile[]): string | undefined {
|
render(diffFiles: DiffFile[]): string | undefined {
|
||||||
const htmlDiffs = diffFiles.map(file => {
|
const diffsHtml = diffFiles
|
||||||
let diffs;
|
.map(file => {
|
||||||
if (file.blocks.length) {
|
let diffs;
|
||||||
diffs = this.generateFileHtml(file);
|
if (file.blocks.length) {
|
||||||
} else {
|
diffs = this.generateFileHtml(file);
|
||||||
diffs = this.generateEmptyDiff();
|
} else {
|
||||||
}
|
diffs = this.generateEmptyDiff();
|
||||||
return this.makeFileDiffHtml(file, diffs);
|
}
|
||||||
});
|
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
|
// 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
|
// TODO: Make this private after improving tests
|
||||||
makeColumnLineNumberHtml(block: DiffBlock): string {
|
makeColumnLineNumberHtml(block: DiffBlock): string {
|
||||||
return this.hoganUtils.render(genericTemplatesPath, "column-line-number", {
|
return this.hoganUtils.render(genericTemplatesPath, "column-line-number", {
|
||||||
|
|
|
||||||
|
|
@ -17,11 +17,6 @@ export const defaultSideBySideRendererConfig = {
|
||||||
maxLineSizeInBlockForComparison: 200
|
maxLineSizeInBlockForComparison: 200
|
||||||
};
|
};
|
||||||
|
|
||||||
type FileHtml = {
|
|
||||||
right: string;
|
|
||||||
left: string;
|
|
||||||
};
|
|
||||||
|
|
||||||
const genericTemplatesPath = "generic";
|
const genericTemplatesPath = "generic";
|
||||||
const baseTemplatesPath = "side-by-side";
|
const baseTemplatesPath = "side-by-side";
|
||||||
const iconsBaseTemplatesPath = "icon";
|
const iconsBaseTemplatesPath = "icon";
|
||||||
|
|
@ -37,7 +32,7 @@ export default class SideBySideRenderer {
|
||||||
}
|
}
|
||||||
|
|
||||||
render(diffFiles: DiffFile[]): string | undefined {
|
render(diffFiles: DiffFile[]): string | undefined {
|
||||||
const content = diffFiles
|
const diffsHtml = diffFiles
|
||||||
.map(file => {
|
.map(file => {
|
||||||
let diffs;
|
let diffs;
|
||||||
if (file.blocks.length) {
|
if (file.blocks.length) {
|
||||||
|
|
@ -45,12 +40,11 @@ export default class SideBySideRenderer {
|
||||||
} else {
|
} else {
|
||||||
diffs = this.generateEmptyDiff();
|
diffs = this.generateEmptyDiff();
|
||||||
}
|
}
|
||||||
|
return this.makeFileDiffHtml(file, diffs);
|
||||||
return this.makeDiffHtml(file, diffs);
|
|
||||||
})
|
})
|
||||||
.join("\n");
|
.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
|
// TODO: Make this private after improving tests
|
||||||
|
|
@ -66,7 +60,7 @@ export default class SideBySideRenderer {
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Make this private after improving tests
|
// 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 fileDiffTemplate = this.hoganUtils.template(baseTemplatesPath, "file-diff");
|
||||||
const filePathTemplate = this.hoganUtils.template(genericTemplatesPath, "file-path");
|
const filePathTemplate = this.hoganUtils.template(genericTemplatesPath, "file-path");
|
||||||
const fileIconTemplate = this.hoganUtils.template(iconsBaseTemplatesPath, "file");
|
const fileIconTemplate = this.hoganUtils.template(iconsBaseTemplatesPath, "file");
|
||||||
|
|
@ -307,8 +301,6 @@ export default class SideBySideRenderer {
|
||||||
newLine.newNumber,
|
newLine.newNumber,
|
||||||
newPrefix
|
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