diff --git a/src/file-list-printer.js b/src/file-list-printer.js index c7a36fb..5b6d8ff 100644 --- a/src/file-list-printer.js +++ b/src/file-list-printer.js @@ -9,34 +9,26 @@ var printerUtils = require('./printer-utils.js').PrinterUtils; + var hoganUtils = require('./hoganjs-utils.js').HoganJsUtils; + var baseTemplatesPath = 'file-summary'; + function FileListPrinter() { } FileListPrinter.prototype.generateFileList = function(diffFiles) { - return '
\n' + - '
\n' + - ' Files changed (' + diffFiles.length + ')  \n' + - ' hide\n' + - ' show\n' + - '
\n' + - ' \n' + + var files = diffFiles.map(function(file) { + return hoganUtils.render(baseTemplatesPath, 'line', { + fileHtmlId: printerUtils.getHtmlId(file), + fileName: printerUtils.getDiffName(file), + deletedLines: '-' + file.deletedLines, + addedLines: '+' + file.addedLines + }); + }).join('\n'); - diffFiles.map(function(file) { - return ' \n' + - ' \n' + - ' \n' + - ' \n' + - ' \n'; - }).join('\n') + - '
\n' + - ' +' + file.addedLines + '\n' + - ' \n' + - ' -' + file.deletedLines + '\n' + - ' \n' + - ' ' + - ' ' + printerUtils.getDiffName(file) + - ' \n' + - '
\n'; + return hoganUtils.render(baseTemplatesPath, 'wrapper', { + filesNumber: diffFiles.length, + files: files + }); }; module.exports.FileListPrinter = new FileListPrinter(); diff --git a/src/side-by-side-printer.js b/src/side-by-side-printer.js index fbf2360..f50f473 100644 --- a/src/side-by-side-printer.js +++ b/src/side-by-side-printer.js @@ -26,14 +26,6 @@ SideBySidePrinter.prototype.makeDiffHtml = function(file, diffs) { return '
\n' + '
\n' + - ' \n' + - ' \n' + - ' +' + file.addedLines + '\n' + - ' \n' + - ' \n' + - ' -' + file.deletedLines + '\n' + - ' \n' + - ' \n' + ' \n' + ' ' + printerUtils.getDiffName(file) + '\n' + ' \n' + diff --git a/src/templates/diff2html-templates.js b/src/templates/diff2html-templates.js index 02c0991..6b11375 100644 --- a/src/templates/diff2html-templates.js +++ b/src/templates/diff2html-templates.js @@ -1,8 +1,10 @@ (function() { if (!!!global.browserTemplates) global.browserTemplates = {}; -var Hogan = require("hogan.js");global.browserTemplates["line-by-line-column-line-number"] = new Hogan.Template({code: function (c,p,i) { var t=this;t.b(i=i||"");t.b("");t.b("\n" + i);t.b(" ");t.b("\n" + i);t.b(" ");t.b("\n" + i);t.b("
");t.b(t.t(t.f("blockHeader",c,p,0)));t.b("
");t.b("\n" + i);t.b(" ");t.b("\n" + i);t.b("");return t.fl(); },partials: {}, subs: { }}); +var Hogan = require("hogan.js");global.browserTemplates["file-summary-line"] = new Hogan.Template({code: function (c,p,i) { var t=this;t.b(i=i||"");t.b("
  • ");t.b("\n" + i);t.b(" ");t.b("\n" + i);t.b(" ");t.b("\n" + i);t.b(" ");t.b("\n" + i);t.b(" ");t.b("\n" + i);t.b(" ");t.b("\n" + i);t.b(" ");t.b("\n" + i);t.b(" ");t.b(t.v(t.f("fileName",c,p,0)));t.b("");t.b("\n" + i);t.b(" ");t.b("\n" + i);t.b(" ");t.b("\n" + i);t.b(" ");t.b(t.v(t.f("addedLines",c,p,0)));t.b("");t.b(t.v(t.f("deletedLines",c,p,0)));t.b("");t.b("\n" + i);t.b(" ");t.b("\n" + i);t.b("
  • ");return t.fl(); },partials: {}, subs: { }}); +global.browserTemplates["file-summary-wrapper"] = new Hogan.Template({code: function (c,p,i) { var t=this;t.b(i=i||"");t.b("
    ");t.b("\n" + i);t.b("
    ");t.b("\n" + i);t.b(" Files changed (");t.b(t.v(t.f("filesNumber",c,p,0)));t.b(")");t.b("\n" + i);t.b(" hide");t.b("\n" + i);t.b(" show");t.b("\n" + i);t.b("
    ");t.b("\n" + i);t.b("
      ");t.b("\n" + i);t.b(" ");t.b(t.t(t.f("files",c,p,0)));t.b("\n" + i);t.b("
    ");t.b("\n" + i);t.b("
    ");return t.fl(); },partials: {}, subs: { }}); +global.browserTemplates["line-by-line-column-line-number"] = new Hogan.Template({code: function (c,p,i) { var t=this;t.b(i=i||"");t.b("");t.b("\n" + i);t.b(" ");t.b("\n" + i);t.b(" ");t.b("\n" + i);t.b("
    ");t.b(t.t(t.f("blockHeader",c,p,0)));t.b("
    ");t.b("\n" + i);t.b(" ");t.b("\n" + i);t.b("");return t.fl(); },partials: {}, subs: { }}); global.browserTemplates["line-by-line-empty-diff"] = new Hogan.Template({code: function (c,p,i) { var t=this;t.b(i=i||"");t.b("");t.b("\n" + i);t.b(" ");t.b("\n" + i);t.b("
    ");t.b("\n" + i);t.b(" File without changes");t.b("\n" + i);t.b("
    ");t.b("\n" + i);t.b(" ");t.b("\n" + i);t.b("");return t.fl(); },partials: {}, subs: { }}); -global.browserTemplates["line-by-line-file-diff"] = new Hogan.Template({code: function (c,p,i) { var t=this;t.b(i=i||"");t.b("
    ");t.b("\n" + i);t.b("
    ");t.b("\n" + i);t.b(" ");t.b("\n" + i);t.b(" ");t.b("\n" + i);t.b(" +");t.b(t.v(t.d("file.addedLines",c,p,0)));t.b("");t.b("\n" + i);t.b(" ");t.b("\n" + i);t.b(" ");t.b("\n" + i);t.b(" -");t.b(t.v(t.d("file.deletedLines",c,p,0)));t.b("");t.b("\n" + i);t.b(" ");t.b("\n" + i);t.b(" ");t.b("\n" + i);t.b(" ");t.b("\n" + i);t.b("  ");t.b(t.v(t.f("fileDiffName",c,p,0)));t.b("");t.b("\n" + i);t.b(" ");t.b("\n" + i);t.b("
    ");t.b("\n" + i);t.b("
    ");t.b("\n" + i);t.b("
    ");t.b("\n" + i);t.b(" ");t.b("\n" + i);t.b(" ");t.b("\n" + i);t.b(" ");t.b(t.t(t.f("diffs",c,p,0)));t.b("\n" + i);t.b(" ");t.b("\n" + i);t.b("
    ");t.b("\n" + i);t.b("
    ");t.b("\n" + i);t.b("
    ");t.b("\n" + i);t.b("
    ");return t.fl(); },partials: {}, subs: { }}); +global.browserTemplates["line-by-line-file-diff"] = new Hogan.Template({code: function (c,p,i) { var t=this;t.b(i=i||"");t.b("
    ");t.b("\n" + i);t.b("
    ");t.b("\n" + i);t.b(" ");t.b("\n" + i);t.b(" ");t.b("\n" + i);t.b(" ");t.b("\n" + i);t.b(" ");t.b("\n" + i);t.b(" ");t.b("\n" + i);t.b(" ");t.b("\n" + i);t.b(" ");t.b("\n" + i);t.b(" ");t.b(t.v(t.f("fileDiffName",c,p,0)));t.b("\n" + i);t.b(" ");t.b("\n" + i);t.b(" ");t.b("\n" + i);t.b("
    ");t.b("\n" + i);t.b("
    ");t.b("\n" + i);t.b("
    ");t.b("\n" + i);t.b(" ");t.b("\n" + i);t.b(" ");t.b("\n" + i);t.b(" ");t.b(t.t(t.f("diffs",c,p,0)));t.b("\n" + i);t.b(" ");t.b("\n" + i);t.b("
    ");t.b("\n" + i);t.b("
    ");t.b("\n" + i);t.b("
    ");t.b("\n" + i);t.b("
    ");return t.fl(); },partials: {}, subs: { }}); global.browserTemplates["line-by-line-line"] = new Hogan.Template({code: function (c,p,i) { var t=this;t.b(i=i||"");t.b("");t.b("\n" + i);t.b(" ");t.b("\n" + i);t.b("
    ");t.b(t.v(t.f("oldNumber",c,p,0)));t.b("
    ");t.b("\n" + i);t.b("
    ");t.b(t.v(t.f("newNumber",c,p,0)));t.b("
    ");t.b("\n" + i);t.b(" ");t.b("\n" + i);t.b(" ");t.b("\n" + i);t.b("
    ");t.b("\n" + i);if(t.s(t.f("prefix",c,p,1),c,p,0,253,329,"{{ }}")){t.rs(c,p,function(c,p,t){t.b(" ");t.b(t.t(t.f("prefix",c,p,0)));t.b("");t.b("\n" + i);});c.pop();}if(t.s(t.f("content",c,p,1),c,p,0,361,435,"{{ }}")){t.rs(c,p,function(c,p,t){t.b(" ");t.b(t.t(t.f("content",c,p,0)));t.b("");t.b("\n" + i);});c.pop();}t.b("
    ");t.b("\n" + i);t.b(" ");t.b("\n" + i);t.b("");return t.fl(); },partials: {}, subs: { }}); global.browserTemplates["line-by-line-wrapper"] = new Hogan.Template({code: function (c,p,i) { var t=this;t.b(i=i||"");t.b("
    ");t.b("\n" + i);t.b(" ");t.b(t.t(t.f("content",c,p,0)));t.b("\n" + i);t.b("
    ");return t.fl(); },partials: {}, subs: { }}); module.exports = global.browserTemplates; diff --git a/src/templates/file-summary-line.mustache b/src/templates/file-summary-line.mustache new file mode 100644 index 0000000..d4cae43 --- /dev/null +++ b/src/templates/file-summary-line.mustache @@ -0,0 +1,13 @@ +
  • + + + + + {{fileName}} + + + {{addedLines}}{{deletedLines}} + +
  • diff --git a/src/templates/file-summary-wrapper.mustache b/src/templates/file-summary-wrapper.mustache new file mode 100644 index 0000000..126854c --- /dev/null +++ b/src/templates/file-summary-wrapper.mustache @@ -0,0 +1,10 @@ +
    +
    + Files changed ({{filesNumber}}) + hide + show +
    +
      + {{{files}}} +
    +
    diff --git a/src/templates/line-by-line-file-diff.mustache b/src/templates/line-by-line-file-diff.mustache index 7789fda..c711788 100644 --- a/src/templates/line-by-line-file-diff.mustache +++ b/src/templates/line-by-line-file-diff.mustache @@ -1,15 +1,14 @@
    - - - +{{file.addedLines}} - - - -{{file.deletedLines}} - - -  {{fileDiffName}} + + + + + {{fileDiffName}} +
    diff --git a/src/ui/css/diff2html.css b/src/ui/css/diff2html.css index a6a6bf4..abab8d5 100644 --- a/src/ui/css/diff2html.css +++ b/src/ui/css/diff2html.css @@ -16,32 +16,32 @@ } .d2h-file-stats { - display: inline; + display: block; text-align: center; + float: right; + font-size: 14px; + top: 2px; + position: relative; } .d2h-lines-added { text-align: right; -} - -.d2h-lines-added > * { - background-color: #ceffce; + /*background-color: #ceffce;*/ border: 1px solid #b4e2b4; - color: #399839; border-radius: 5px 0 0 5px; + color: #399839; padding: 2px; + vertical-align: middle; } .d2h-lines-deleted { text-align: left; -} - -.d2h-lines-deleted > * { - background-color: #f7c8c8; + /*background-color: #f7c8c8;*/ border: 1px solid #e9aeae; - color: #c33; border-radius: 0 5px 5px 0; + color: #c33; padding: 2px; + vertical-align: middle; } .d2h-file-name-wrapper { @@ -258,6 +258,19 @@ .d2h-file-list { display: block; + list-style: none; + padding: 0; + margin: 0; +} + +.d2h-file-list > li { + border-bottom: #ddd solid 1px; + padding: 5px 10px; + margin: 0; +} + +.d2h-file-list > li:last-child { + border-bottom: none; } .d2h-file-switch { @@ -266,6 +279,15 @@ cursor: pointer; } +.d2h-icon-wrapper { + line-height: 31px; +} + +.d2h-icon { + vertical-align: middle; + margin-right: 10px; +} + /* * Selection util. */