Fix repeated variable name in same scope (thanks Codacy)

This commit is contained in:
Rodrigo Fernandes 2016-02-24 00:13:43 +00:00
parent 9205e5e0a1
commit 465dde689a
17 changed files with 172 additions and 151 deletions

View file

@ -1,6 +1,6 @@
{ {
"name": "diff2html", "name": "diff2html",
"version": "2.0.0-beta3", "version": "2.0.0-beta7",
"homepage": "http://rtfpessoa.github.io/diff2html/", "homepage": "http://rtfpessoa.github.io/diff2html/",
"description": "Fast Diff to colorized HTML", "description": "Fast Diff to colorized HTML",
"keywords": [ "keywords": [
@ -40,6 +40,7 @@
], ],
"ignore": [ "ignore": [
"**/.*", "**/.*",
"webpack.config.js",
"package.json", "package.json",
"release.sh", "release.sh",
"circle.yml", "circle.yml",

View file

@ -5,15 +5,15 @@ var colno = null;
var output = ""; var output = "";
try { try {
var parentTemplate = null; var parentTemplate = null;
output += "<tr>\n <td class=\"d2h-code-linenumber "; output += "<tr>\n <td class=\"d2h-code-linenumber ";
output += runtime.suppressValue(runtime.memberLookup((runtime.memberLookup((runtime.contextOrFrameLookup(context, frame, "diffParser")),"LINE_TYPE")),"INFO"), env.opts.autoescape); output += runtime.suppressValue(runtime.memberLookup((runtime.memberLookup((runtime.contextOrFrameLookup(context, frame, "diffParser")),"LINE_TYPE")),"INFO"), env.opts.autoescape);
output += "\"></td>\n <td class=\""; output += "\"></td>\n <td class=\"";
output += runtime.suppressValue(runtime.memberLookup((runtime.memberLookup((runtime.contextOrFrameLookup(context, frame, "diffParser")),"LINE_TYPE")),"INFO"), env.opts.autoescape); output += runtime.suppressValue(runtime.memberLookup((runtime.memberLookup((runtime.contextOrFrameLookup(context, frame, "diffParser")),"LINE_TYPE")),"INFO"), env.opts.autoescape);
output += "\">\n <div class=\"d2h-code-line "; output += "\">\n <div class=\"d2h-code-line ";
output += runtime.suppressValue(runtime.memberLookup((runtime.memberLookup((runtime.contextOrFrameLookup(context, frame, "diffParser")),"LINE_TYPE")),"INFO"), env.opts.autoescape); output += runtime.suppressValue(runtime.memberLookup((runtime.memberLookup((runtime.contextOrFrameLookup(context, frame, "diffParser")),"LINE_TYPE")),"INFO"), env.opts.autoescape);
output += "\"> "; output += "\"> ";
output += runtime.suppressValue((lineno = 3, colno = 73, runtime.callWrap(runtime.memberLookup((runtime.contextOrFrameLookup(context, frame, "utils")),"escape"), "utils[\"escape\"]", context, [runtime.memberLookup((runtime.contextOrFrameLookup(context, frame, "block")),"header")])), env.opts.autoescape); output += runtime.suppressValue((lineno = 3, colno = 77, runtime.callWrap(runtime.memberLookup((runtime.contextOrFrameLookup(context, frame, "utils")),"escape"), "utils[\"escape\"]", context, [runtime.memberLookup((runtime.contextOrFrameLookup(context, frame, "block")),"header")])), env.opts.autoescape);
output += " </div>\n </td>\n</tr>\n"; output += "</div>\n </td>\n</tr>\n";
if(parentTemplate) { if(parentTemplate) {
parentTemplate.rootRenderFunc(env, context, frame, runtime, cb); parentTemplate.rootRenderFunc(env, context, frame, runtime, cb);
} else { } else {
@ -37,11 +37,11 @@ var colno = null;
var output = ""; var output = "";
try { try {
var parentTemplate = null; var parentTemplate = null;
output += "<tr>\n <td class=\""; output += "<tr>\n <td class=\"";
output += runtime.suppressValue(runtime.memberLookup((runtime.memberLookup((runtime.contextOrFrameLookup(context, frame, "diffParser")),"LINE_TYPE")),"INFO"), env.opts.autoescape); output += runtime.suppressValue(runtime.memberLookup((runtime.memberLookup((runtime.contextOrFrameLookup(context, frame, "diffParser")),"LINE_TYPE")),"INFO"), env.opts.autoescape);
output += "\">\n <div class=\"d2h-code-line "; output += "\">\n <div class=\"d2h-code-line ";
output += runtime.suppressValue(runtime.memberLookup((runtime.memberLookup((runtime.contextOrFrameLookup(context, frame, "diffParser")),"LINE_TYPE")),"INFO"), env.opts.autoescape); output += runtime.suppressValue(runtime.memberLookup((runtime.memberLookup((runtime.contextOrFrameLookup(context, frame, "diffParser")),"LINE_TYPE")),"INFO"), env.opts.autoescape);
output += "\">\n File without changes\n </div>\n </td>\n</tr>\n"; output += "\">\n File without changes\n </div>\n </td>\n</tr>\n";
if(parentTemplate) { if(parentTemplate) {
parentTemplate.rootRenderFunc(env, context, frame, runtime, cb); parentTemplate.rootRenderFunc(env, context, frame, runtime, cb);
} else { } else {
@ -69,15 +69,15 @@ output += "<div id=\"";
output += runtime.suppressValue((lineno = 0, colno = 32, runtime.callWrap(runtime.memberLookup((runtime.contextOrFrameLookup(context, frame, "printerUtils")),"getHtmlId"), "printerUtils[\"getHtmlId\"]", context, [runtime.contextOrFrameLookup(context, frame, "file")])), env.opts.autoescape); output += runtime.suppressValue((lineno = 0, colno = 32, runtime.callWrap(runtime.memberLookup((runtime.contextOrFrameLookup(context, frame, "printerUtils")),"getHtmlId"), "printerUtils[\"getHtmlId\"]", context, [runtime.contextOrFrameLookup(context, frame, "file")])), env.opts.autoescape);
output += "\" class=\"d2h-file-wrapper\" data-lang=\""; output += "\" class=\"d2h-file-wrapper\" data-lang=\"";
output += runtime.suppressValue(runtime.memberLookup((runtime.contextOrFrameLookup(context, frame, "file")),"language"), env.opts.autoescape); output += runtime.suppressValue(runtime.memberLookup((runtime.contextOrFrameLookup(context, frame, "file")),"language"), env.opts.autoescape);
output += "\">\n <div class=\"d2h-file-header\">\n <span class=\"d2h-file-stats\">\n <span class=\"d2h-lines-added\">\n <span>+"; output += "\">\n <div class=\"d2h-file-header\">\n <span class=\"d2h-file-stats\">\n <span class=\"d2h-lines-added\">\n <span>+";
output += runtime.suppressValue(runtime.memberLookup((runtime.contextOrFrameLookup(context, frame, "file")),"addedLines"), env.opts.autoescape); output += runtime.suppressValue(runtime.memberLookup((runtime.contextOrFrameLookup(context, frame, "file")),"addedLines"), env.opts.autoescape);
output += "</span>\n </span>\n <span class=\"d2h-lines-deleted\">\n <span>-"; output += "</span>\n </span>\n <span class=\"d2h-lines-deleted\">\n <span>-";
output += runtime.suppressValue(runtime.memberLookup((runtime.contextOrFrameLookup(context, frame, "file")),"deletedLines"), env.opts.autoescape); output += runtime.suppressValue(runtime.memberLookup((runtime.contextOrFrameLookup(context, frame, "file")),"deletedLines"), env.opts.autoescape);
output += "</span>\n </span>\n </span>\n <span class=\"d2h-file-name-wrapper\">\n <span class=\"d2h-file-name\">&nbsp;"; output += "</span>\n </span>\n </span>\n <span class=\"d2h-file-name-wrapper\">\n <span class=\"d2h-file-name\">&nbsp;";
output += runtime.suppressValue((lineno = 11, colno = 67, runtime.callWrap(runtime.memberLookup((runtime.contextOrFrameLookup(context, frame, "printerUtils")),"getDiffName"), "printerUtils[\"getDiffNam\"]", context, [runtime.contextOrFrameLookup(context, frame, "file")])), env.opts.autoescape); output += runtime.suppressValue((lineno = 11, colno = 67, runtime.callWrap(runtime.memberLookup((runtime.contextOrFrameLookup(context, frame, "printerUtils")),"getDiffName"), "printerUtils[\"getDiffNam\"]", context, [runtime.contextOrFrameLookup(context, frame, "file")])), env.opts.autoescape);
output += "</span>\n </span>\n </div>\n <div class=\"d2h-file-diff\">\n <div class=\"d2h-code-wrapper\">\n <table class=\"d2h-diff-table\">\n <tbody class=\"d2h-diff-tbody\">\n "; output += "</span>\n </span>\n </div>\n <div class=\"d2h-file-diff\">\n <div class=\"d2h-code-wrapper\">\n <table class=\"d2h-diff-table\">\n <tbody class=\"d2h-diff-tbody\">\n ";
output += runtime.suppressValue(env.getFilter("safe").call(context, runtime.contextOrFrameLookup(context, frame, "diffs")), env.opts.autoescape); output += runtime.suppressValue(env.getFilter("safe").call(context, runtime.contextOrFrameLookup(context, frame, "diffs")), env.opts.autoescape);
output += "\n </tbody>\n </table>\n </div>\n </div>\n</div>\n"; output += "\n </tbody>\n </table>\n </div>\n </div>\n</div>\n";
if(parentTemplate) { if(parentTemplate) {
parentTemplate.rootRenderFunc(env, context, frame, runtime, cb); parentTemplate.rootRenderFunc(env, context, frame, runtime, cb);
} else { } else {
@ -101,31 +101,30 @@ var colno = null;
var output = ""; var output = "";
try { try {
var parentTemplate = null; var parentTemplate = null;
output += "<tr>\n <td class=\"d2h-code-linenumber "; output += "<tr>\n <td class=\"d2h-code-linenumber ";
output += runtime.suppressValue(runtime.contextOrFrameLookup(context, frame, "type"), env.opts.autoescape); output += runtime.suppressValue(runtime.contextOrFrameLookup(context, frame, "type"), env.opts.autoescape);
output += "\">\n <div class=\"line-num1\">"; output += "\">\n <div class=\"line-num1\">";
output += runtime.suppressValue(env.getFilter("safe").call(context, (lineno = 2, colno = 46, runtime.callWrap(runtime.memberLookup((runtime.contextOrFrameLookup(context, frame, "utils")),"valueOrEmpty"), "utils[\"valueOrEmp\"]", context, [runtime.contextOrFrameLookup(context, frame, "oldNumber")]))), env.opts.autoescape); output += runtime.suppressValue(env.getFilter("safe").call(context, (lineno = 2, colno = 50, runtime.callWrap(runtime.memberLookup((runtime.contextOrFrameLookup(context, frame, "utils")),"valueOrEmpty"), "utils[\"valueOrEmp\"]", context, [runtime.contextOrFrameLookup(context, frame, "oldNumber")]))), env.opts.autoescape);
output += "</div>\n <div class=\"line-num2\">"; output += "</div>\n <div class=\"line-num2\">";
output += runtime.suppressValue(env.getFilter("safe").call(context, (lineno = 3, colno = 46, runtime.callWrap(runtime.memberLookup((runtime.contextOrFrameLookup(context, frame, "utils")),"valueOrEmpty"), "utils[\"valueOrEmp\"]", context, [runtime.contextOrFrameLookup(context, frame, "newNumber")]))), env.opts.autoescape); output += runtime.suppressValue(env.getFilter("safe").call(context, (lineno = 3, colno = 50, runtime.callWrap(runtime.memberLookup((runtime.contextOrFrameLookup(context, frame, "utils")),"valueOrEmpty"), "utils[\"valueOrEmp\"]", context, [runtime.contextOrFrameLookup(context, frame, "newNumber")]))), env.opts.autoescape);
output += "</div>\n </td>\n <td class=\""; output += "</div>\n </td>\n <td class=\"";
output += runtime.suppressValue(runtime.contextOrFrameLookup(context, frame, "type"), env.opts.autoescape); output += runtime.suppressValue(runtime.contextOrFrameLookup(context, frame, "type"), env.opts.autoescape);
output += "\">\n <div class=\"d2h-code-line "; output += "\">\n <div class=\"d2h-code-line ";
output += runtime.suppressValue(runtime.contextOrFrameLookup(context, frame, "type"), env.opts.autoescape); output += runtime.suppressValue(runtime.contextOrFrameLookup(context, frame, "type"), env.opts.autoescape);
output += "\">\n"; output += "\">";
if(runtime.contextOrFrameLookup(context, frame, "prefix")) { if(runtime.contextOrFrameLookup(context, frame, "prefix")) {
output += "\n <span class=\"d2h-code-line-prefix\">"; output += "\n <span class=\"d2h-code-line-prefix\">";
output += runtime.suppressValue(env.getFilter("safe").call(context, (lineno = 8, colno = 83, runtime.callWrap(runtime.memberLookup((runtime.contextOrFrameLookup(context, frame, "utils")),"convertWhiteSpaceToNonBreakingSpace"), "utils[\"convertWhi\"]", context, [runtime.contextOrFrameLookup(context, frame, "prefix")]))), env.opts.autoescape); output += runtime.suppressValue(env.getFilter("safe").call(context, (lineno = 8, colno = 89, runtime.callWrap(runtime.memberLookup((runtime.contextOrFrameLookup(context, frame, "utils")),"convertWhiteSpaceToNonBreakingSpace"), "utils[\"convertWhi\"]", context, [runtime.contextOrFrameLookup(context, frame, "prefix")]))), env.opts.autoescape);
output += "</span>\n"; output += "</span>\n ";
; ;
} }
output += "\n";
if(runtime.contextOrFrameLookup(context, frame, "content")) { if(runtime.contextOrFrameLookup(context, frame, "content")) {
output += "\n <span class=\"d2h-code-line-ctn\">"; output += "<span class=\"d2h-code-line-ctn\">";
output += runtime.suppressValue(env.getFilter("safe").call(context, (lineno = 11, colno = 80, runtime.callWrap(runtime.memberLookup((runtime.contextOrFrameLookup(context, frame, "utils")),"convertWhiteSpaceToNonBreakingSpace"), "utils[\"convertWhi\"]", context, [runtime.contextOrFrameLookup(context, frame, "content")]))), env.opts.autoescape); output += runtime.suppressValue(env.getFilter("safe").call(context, (lineno = 11, colno = 86, runtime.callWrap(runtime.memberLookup((runtime.contextOrFrameLookup(context, frame, "utils")),"convertWhiteSpaceToNonBreakingSpace"), "utils[\"convertWhi\"]", context, [runtime.contextOrFrameLookup(context, frame, "content")]))), env.opts.autoescape);
output += "</span>\n"; output += "</span>";
; ;
} }
output += "\n </div>\n </td>\n</tr>\n"; output += "\n </div>\n </td>\n</tr>\n";
if(parentTemplate) { if(parentTemplate) {
parentTemplate.rootRenderFunc(env, context, frame, runtime, cb); parentTemplate.rootRenderFunc(env, context, frame, runtime, cb);
} else { } else {
@ -149,7 +148,7 @@ var colno = null;
var output = ""; var output = "";
try { try {
var parentTemplate = null; var parentTemplate = null;
output += "<div class=\"d2h-wrapper\">\n "; output += "<div class=\"d2h-wrapper\">\n ";
output += runtime.suppressValue(runtime.contextOrFrameLookup(context, frame, "content"), env.opts.autoescape); output += runtime.suppressValue(runtime.contextOrFrameLookup(context, frame, "content"), env.opts.autoescape);
output += "\n</div>\n"; output += "\n</div>\n";
if(parentTemplate) { if(parentTemplate) {

File diff suppressed because one or more lines are too long

View file

@ -126,9 +126,14 @@
Diff2HtmlUI.prototype._getTarget = function(targetId) { Diff2HtmlUI.prototype._getTarget = function(targetId) {
var $target; var $target;
if (targetId) {
if (typeof(targetId) === 'object' && targetId instanceof jQuery) {
$target = targetId;
} else if (typeof(targetId) === 'string') {
$target = $(targetId); $target = $(targetId);
} else { } else {
console.error("Wrong target provided! Falling back to default value 'body'.");
console.log("Please provide a jQuery object or a valid DOM query string.");
$target = $(defaultTarget); $target = $(defaultTarget);
} }

View file

@ -1 +1 @@
!function(modules){function __webpack_require__(moduleId){if(installedModules[moduleId])return installedModules[moduleId].exports;var module=installedModules[moduleId]={exports:{},id:moduleId,loaded:!1};return modules[moduleId].call(module.exports,module,module.exports,__webpack_require__),module.loaded=!0,module.exports}var installedModules={};return __webpack_require__.m=modules,__webpack_require__.c=installedModules,__webpack_require__.p="",__webpack_require__(0)}([function(module,exports){(function(global){!function(){function Diff2HtmlUI(config){var cfg=config||{};cfg.diff?diffJson=Diff2Html.getJsonFromDiff(cfg.diff):cfg.json&&(diffJson=cfg.json)}var diffJson=null,defaultTarget="body";Diff2HtmlUI.prototype.draw=function(targetId,config){var cfg=config||{},$target=this._getTarget(targetId);$target.html(Diff2Html.getPrettyHtml(diffJson,cfg))},Diff2HtmlUI.prototype.fileListCloseable=function(targetId,startVisible){function show(){$showBtn.hide(),$hideBtn.show(),$fileList.show()}function hide(){$hideBtn.hide(),$showBtn.show(),$fileList.hide()}var $target=this._getTarget(targetId),hashTag=this._getHashTag(),$showBtn=$target.find(".d2h-show"),$hideBtn=$target.find(".d2h-hide"),$fileList=$target.find(".d2h-file-list");"files-summary-show"===hashTag?show():"files-summary-hide"===hashTag?hide():startVisible?show():hide(),$showBtn.click(show),$hideBtn.click(hide)},Diff2HtmlUI.prototype.highlightCode=function(targetId){var that=this,$target=that._getTarget(targetId),languages=that._getLanguages($target);hljs.configure({languages:languages});var $codeLines=$target.find(".d2h-code-line-ctn");$codeLines.map(function(i,line){hljs.highlightBlock(line)})},Diff2HtmlUI.prototype._getTarget=function(targetId){var $target;return $target=$(targetId?targetId:defaultTarget)},Diff2HtmlUI.prototype._getLanguages=function($target){var allFileLanguages=[];return diffJson?allFileLanguages=diffJson.map(function(line){return line.language}):$target.find(".d2h-file-wrapper").map(function(i,file){allFileLanguages.push($(file).data("lang"))}),this._distinct(allFileLanguages)},Diff2HtmlUI.prototype._getHashTag=function(){var docUrl=document.URL,hashTagIndex=docUrl.indexOf("#"),hashTag=null;return-1!==hashTagIndex&&(hashTag=docUrl.substr(hashTagIndex+1)),hashTag},Diff2HtmlUI.prototype._distinct=function(collection){return collection.filter(function(v,i){return collection.indexOf(v)===i})},module.exports.Diff2HtmlUI=Diff2HtmlUI,global.Diff2HtmlUI=Diff2HtmlUI}()}).call(exports,function(){return this}())}]); !function(modules){function __webpack_require__(moduleId){if(installedModules[moduleId])return installedModules[moduleId].exports;var module=installedModules[moduleId]={exports:{},id:moduleId,loaded:!1};return modules[moduleId].call(module.exports,module,module.exports,__webpack_require__),module.loaded=!0,module.exports}var installedModules={};return __webpack_require__.m=modules,__webpack_require__.c=installedModules,__webpack_require__.p="",__webpack_require__(0)}([function(module,exports){(function(global){!function(){function Diff2HtmlUI(config){var cfg=config||{};cfg.diff?diffJson=Diff2Html.getJsonFromDiff(cfg.diff):cfg.json&&(diffJson=cfg.json)}var diffJson=null,defaultTarget="body";Diff2HtmlUI.prototype.draw=function(targetId,config){var cfg=config||{},$target=this._getTarget(targetId);$target.html(Diff2Html.getPrettyHtml(diffJson,cfg))},Diff2HtmlUI.prototype.fileListCloseable=function(targetId,startVisible){function show(){$showBtn.hide(),$hideBtn.show(),$fileList.show()}function hide(){$hideBtn.hide(),$showBtn.show(),$fileList.hide()}var $target=this._getTarget(targetId),hashTag=this._getHashTag(),$showBtn=$target.find(".d2h-show"),$hideBtn=$target.find(".d2h-hide"),$fileList=$target.find(".d2h-file-list");"files-summary-show"===hashTag?show():"files-summary-hide"===hashTag?hide():startVisible?show():hide(),$showBtn.click(show),$hideBtn.click(hide)},Diff2HtmlUI.prototype.highlightCode=function(targetId){var that=this,$target=that._getTarget(targetId),languages=that._getLanguages($target);hljs.configure({languages:languages});var $codeLines=$target.find(".d2h-code-line-ctn");$codeLines.map(function(i,line){hljs.highlightBlock(line)})},Diff2HtmlUI.prototype._getTarget=function(targetId){var $target;return"object"==typeof targetId&&targetId instanceof jQuery?$target=targetId:"string"==typeof targetId?$target=$(targetId):(console.error("Wrong target provided! Falling back to default value 'body'."),console.log("Please provide a jQuery object or a valid DOM query string."),$target=$(defaultTarget)),$target},Diff2HtmlUI.prototype._getLanguages=function($target){var allFileLanguages=[];return diffJson?allFileLanguages=diffJson.map(function(line){return line.language}):$target.find(".d2h-file-wrapper").map(function(i,file){allFileLanguages.push($(file).data("lang"))}),this._distinct(allFileLanguages)},Diff2HtmlUI.prototype._getHashTag=function(){var docUrl=document.URL,hashTagIndex=docUrl.indexOf("#"),hashTag=null;return-1!==hashTagIndex&&(hashTag=docUrl.substr(hashTagIndex+1)),hashTag},Diff2HtmlUI.prototype._distinct=function(collection){return collection.filter(function(v,i){return collection.indexOf(v)===i})},module.exports.Diff2HtmlUI=Diff2HtmlUI,global.Diff2HtmlUI=Diff2HtmlUI}()}).call(exports,function(){return this}())}]);

24
dist/diff2html.js vendored
View file

@ -325,10 +325,10 @@
if (utils.startsWith(line, 'diff')) { if (utils.startsWith(line, 'diff')) {
startFile(); startFile();
} else if (currentFile && !currentFile.oldName && (values = getSrcFilename(line, config))) { } else if (currentFile && !currentFile.oldName && (values = getSrcFilename(line, config))) {
currentFile.oldName = values[1]; currentFile.oldName = values;
currentFile.language = getExtension(currentFile.oldName, currentFile.language); currentFile.language = getExtension(currentFile.oldName, currentFile.language);
} else if (currentFile && !currentFile.newName && (values = getDstFilename(line, config))) { } else if (currentFile && !currentFile.newName && (values = getDstFilename(line, config))) {
currentFile.newName = values[1]; currentFile.newName = values;
currentFile.language = getExtension(currentFile.newName, currentFile.language); currentFile.language = getExtension(currentFile.newName, currentFile.language);
} else if (currentFile && utils.startsWith(line, '@@')) { } else if (currentFile && utils.startsWith(line, '@@')) {
startBlock(line); startBlock(line);
@ -391,7 +391,7 @@
} }
function getSrcFilename(line, cfg) { function getSrcFilename(line, cfg) {
var prefixes = ["a\\/", "i\\/", "w\\/", "c\\/", "o\\/"]; var prefixes = ["a/", "i/", "w/", "c/", "o/"];
if (cfg.srcPrefix) prefixes.push(cfg.srcPrefix); if (cfg.srcPrefix) prefixes.push(cfg.srcPrefix);
@ -399,7 +399,7 @@
} }
function getDstFilename(line, cfg) { function getDstFilename(line, cfg) {
var prefixes = ["b\\/", "i\\/", "w\\/", "c\\/", "o\\/"]; var prefixes = ["b/", "i/", "w/", "c/", "o/"];
if (cfg.dstPrefix) prefixes.push(cfg.dstPrefix); if (cfg.dstPrefix) prefixes.push(cfg.dstPrefix);
@ -407,8 +407,20 @@
} }
function _getFilename(linePrefix, line, prefixes) { function _getFilename(linePrefix, line, prefixes) {
var prefixesStr = prefixes.join("|"); var FilenameRegExp = new RegExp('^' + linePrefix + ' "?(.+?)"?$');
return new RegExp('^' + linePrefix + ' "?(?:' + prefixesStr + ')(.+?)"?$').exec(line);
var filename;
var values = FilenameRegExp.exec(line);
if (values && values[1]) {
filename = values[1];
var matchingPrefixes = prefixes.filter(function(p) {
return filename.indexOf(p) === 0;
});
if (matchingPrefixes[0]) filename = filename.slice(matchingPrefixes[0].length); // remove prefix if exists
}
return filename;
} }
module.exports.DiffParser = new DiffParser(); module.exports.DiffParser = new DiffParser();

File diff suppressed because one or more lines are too long

View file

@ -1,6 +1,6 @@
{ {
"name": "diff2html", "name": "diff2html",
"version": "2.0.0-beta3", "version": "2.0.0-beta7",
"homepage": "http://rtfpessoa.github.io/diff2html/", "homepage": "http://rtfpessoa.github.io/diff2html/",
"description": "Fast Diff to colorized HTML", "description": "Fast Diff to colorized HTML",
"keywords": [ "keywords": [

View file

@ -249,11 +249,11 @@
var values = FilenameRegExp.exec(line); var values = FilenameRegExp.exec(line);
if (values && values[1]) { if (values && values[1]) {
filename = values[1]; filename = values[1];
var prefix = prefixes.find(function(prefix) { var matchingPrefixes = prefixes.filter(function(p) {
return filename.startsWith(prefix); return filename.indexOf(p) === 0;
}); });
if (prefix) filename = filename.slice(prefix.length); // remove prefix if exists if (matchingPrefixes[0]) filename = filename.slice(matchingPrefixes[0].length); // remove prefix if exists
} }
return filename; return filename;

View file

@ -1,6 +1,6 @@
<tr> <tr>
<td class="d2h-code-linenumber {{ diffParser.LINE_TYPE.INFO }}"></td> <td class="d2h-code-linenumber {{ diffParser.LINE_TYPE.INFO }}"></td>
<td class="{{ diffParser.LINE_TYPE.INFO }}"> <td class="{{ diffParser.LINE_TYPE.INFO }}">
<div class="d2h-code-line {{ diffParser.LINE_TYPE.INFO }}"> {{ utils.escape(block.header) }} </div> <div class="d2h-code-line {{ diffParser.LINE_TYPE.INFO }}"> {{ utils.escape(block.header) }}</div>
</td> </td>
</tr> </tr>

View file

@ -1,7 +1,7 @@
<tr> <tr>
<td class="{{ diffParser.LINE_TYPE.INFO }}"> <td class="{{ diffParser.LINE_TYPE.INFO }}">
<div class="d2h-code-line {{ diffParser.LINE_TYPE.INFO }}"> <div class="d2h-code-line {{ diffParser.LINE_TYPE.INFO }}">
File without changes File without changes
</div> </div>
</td> </td>
</tr> </tr>

View file

@ -1,5 +1,5 @@
<div id="{{ printerUtils.getHtmlId(file) }}" class="d2h-file-wrapper" data-lang="{{ file.language }}"> <div id="{{ printerUtils.getHtmlId(file) }}" class="d2h-file-wrapper" data-lang="{{ file.language }}">
<div class="d2h-file-header"> <div class="d2h-file-header">
<span class="d2h-file-stats"> <span class="d2h-file-stats">
<span class="d2h-lines-added"> <span class="d2h-lines-added">
<span>+{{ file.addedLines }}</span> <span>+{{ file.addedLines }}</span>
@ -11,14 +11,14 @@
<span class="d2h-file-name-wrapper"> <span class="d2h-file-name-wrapper">
<span class="d2h-file-name">&nbsp;{{ printerUtils.getDiffName(file) }}</span> <span class="d2h-file-name">&nbsp;{{ printerUtils.getDiffName(file) }}</span>
</span> </span>
</div>
<div class="d2h-file-diff">
<div class="d2h-code-wrapper">
<table class="d2h-diff-table">
<tbody class="d2h-diff-tbody">
{{ diffs | safe}}
</tbody>
</table>
</div> </div>
</div> <div class="d2h-file-diff">
<div class="d2h-code-wrapper">
<table class="d2h-diff-table">
<tbody class="d2h-diff-tbody">
{{ diffs | safe}}
</tbody>
</table>
</div>
</div>
</div> </div>

View file

@ -1,16 +1,16 @@
<tr> <tr>
<td class="d2h-code-linenumber {{ type }}"> <td class="d2h-code-linenumber {{ type }}">
<div class="line-num1">{{ utils.valueOrEmpty(oldNumber) | safe }}</div> <div class="line-num1">{{ utils.valueOrEmpty(oldNumber) | safe }}</div>
<div class="line-num2">{{ utils.valueOrEmpty(newNumber) | safe }}</div> <div class="line-num2">{{ utils.valueOrEmpty(newNumber) | safe }}</div>
</td> </td>
<td class="{{ type }}"> <td class="{{ type }}">
<div class="d2h-code-line {{ type }}"> <div class="d2h-code-line {{ type }}">
{% if prefix %} {%- if prefix %}
<span class="d2h-code-line-prefix">{{ utils.convertWhiteSpaceToNonBreakingSpace(prefix) | safe }}</span> <span class="d2h-code-line-prefix">{{ utils.convertWhiteSpaceToNonBreakingSpace(prefix) | safe }}</span>
{% endif %} {% endif -%}
{% if content %} {% if content -%}
<span class="d2h-code-line-ctn">{{ utils.convertWhiteSpaceToNonBreakingSpace(content) | safe }}</span> <span class="d2h-code-line-ctn">{{ utils.convertWhiteSpaceToNonBreakingSpace(content) | safe }}</span>
{% endif %} {%- endif %}
</div> </div>
</td> </td>
</tr> </tr>

View file

@ -1,3 +1,3 @@
<div class="d2h-wrapper"> <div class="d2h-wrapper">
{{ content }} {{ content }}
</div> </div>

View file

@ -80,9 +80,14 @@
Diff2HtmlUI.prototype._getTarget = function(targetId) { Diff2HtmlUI.prototype._getTarget = function(targetId) {
var $target; var $target;
if (targetId) {
if (typeof(targetId) === 'object' && targetId instanceof jQuery) {
$target = targetId;
} else if (typeof(targetId) === 'string') {
$target = $(targetId); $target = $(targetId);
} else { } else {
console.error("Wrong target provided! Falling back to default value 'body'.");
console.log("Please provide a jQuery object or a valid DOM query string.");
$target = $(defaultTarget); $target = $(defaultTarget);
} }

View file

@ -10,11 +10,11 @@ describe('LineByLinePrinter', function() {
var lineByLinePrinter = new LineByLinePrinter({}); var lineByLinePrinter = new LineByLinePrinter({});
var fileHtml = lineByLinePrinter._generateEmptyDiff(); var fileHtml = lineByLinePrinter._generateEmptyDiff();
var expected = '<tr>\n' + var expected = '<tr>\n' +
' <td class="d2h-info">\n' + ' <td class="d2h-info">\n' +
' <div class="d2h-code-line d2h-info">\n' + ' <div class="d2h-code-line d2h-info">\n' +
' File without changes\n' + ' File without changes\n' +
' </div>\n' + ' </div>\n' +
' </td>\n' + ' </td>\n' +
'</tr>\n'; '</tr>\n';
assert.equal(expected, fileHtml); assert.equal(expected, fileHtml);
@ -29,17 +29,17 @@ describe('LineByLinePrinter', function() {
diffParser.LINE_TYPE.INSERTS, '', 30, '+', 'test'); diffParser.LINE_TYPE.INSERTS, '', 30, '+', 'test');
fileHtml = fileHtml.replace(/\n\n+/g, '\n'); fileHtml = fileHtml.replace(/\n\n+/g, '\n');
var expected = '<tr>\n' + var expected = '<tr>\n' +
' <td class="d2h-code-linenumber d2h-ins">\n' + ' <td class="d2h-code-linenumber d2h-ins">\n' +
' <div class="line-num1"></div>\n' + ' <div class="line-num1"></div>\n' +
' <div class="line-num2">30</div>\n' + ' <div class="line-num2">30</div>\n' +
' </td>\n' + ' </td>\n' +
' <td class="d2h-ins">\n' + ' <td class="d2h-ins">\n' +
' <div class="d2h-code-line d2h-ins">\n' + ' <div class="d2h-code-line d2h-ins">\n' +
' <span class="d2h-code-line-prefix">test</span>\n' + ' <span class="d2h-code-line-prefix">test</span>\n' +
' <span class="d2h-code-line-ctn">+</span>\n' + ' <span class="d2h-code-line-ctn">+</span>\n' +
' </div>\n' + ' </div>\n' +
' </td>\n' + ' </td>\n' +
'</tr>\n'; '</tr>\n';
assert.equal(expected, fileHtml); assert.equal(expected, fileHtml);
}); });
@ -51,17 +51,17 @@ describe('LineByLinePrinter', function() {
diffParser.LINE_TYPE.DELETES, 30, '', '-', 'test'); diffParser.LINE_TYPE.DELETES, 30, '', '-', 'test');
fileHtml = fileHtml.replace(/\n\n+/g, '\n'); fileHtml = fileHtml.replace(/\n\n+/g, '\n');
var expected = '<tr>\n' + var expected = '<tr>\n' +
' <td class="d2h-code-linenumber d2h-del">\n' + ' <td class="d2h-code-linenumber d2h-del">\n' +
' <div class="line-num1">30</div>\n' + ' <div class="line-num1">30</div>\n' +
' <div class="line-num2"></div>\n' + ' <div class="line-num2"></div>\n' +
' </td>\n' + ' </td>\n' +
' <td class="d2h-del">\n' + ' <td class="d2h-del">\n' +
' <div class="d2h-code-line d2h-del">\n' + ' <div class="d2h-code-line d2h-del">\n' +
' <span class="d2h-code-line-prefix">test</span>\n' + ' <span class="d2h-code-line-prefix">test</span>\n' +
' <span class="d2h-code-line-ctn">-</span>\n' + ' <span class="d2h-code-line-ctn">-</span>\n' +
' </div>\n' + ' </div>\n' +
' </td>\n' + ' </td>\n' +
'</tr>\n'; '</tr>\n';
assert.equal(expected, fileHtml); assert.equal(expected, fileHtml);
}); });
@ -73,17 +73,17 @@ describe('LineByLinePrinter', function() {
diffParser.LINE_TYPE.INSERTS, '', 30, '+', ' test'); diffParser.LINE_TYPE.INSERTS, '', 30, '+', ' test');
fileHtml = fileHtml.replace(/\n\n+/g, '\n'); fileHtml = fileHtml.replace(/\n\n+/g, '\n');
var expected = '<tr>\n' + var expected = '<tr>\n' +
' <td class="d2h-code-linenumber d2h-ins">\n' + ' <td class="d2h-code-linenumber d2h-ins">\n' +
' <div class="line-num1"></div>\n' + ' <div class="line-num1"></div>\n' +
' <div class="line-num2">30</div>\n' + ' <div class="line-num2">30</div>\n' +
' </td>\n' + ' </td>\n' +
' <td class="d2h-ins">\n' + ' <td class="d2h-ins">\n' +
' <div class="d2h-code-line d2h-ins">\n' + ' <div class="d2h-code-line d2h-ins">\n' +
' <span class="d2h-code-line-prefix">&nbsp;&nbsp;test</span>\n' + ' <span class="d2h-code-line-prefix">&nbsp;&nbsp;test</span>\n' +
' <span class="d2h-code-line-ctn">+</span>\n' + ' <span class="d2h-code-line-ctn">+</span>\n' +
' </div>\n' + ' </div>\n' +
' </td>\n' + ' </td>\n' +
'</tr>\n'; '</tr>\n';
assert.equal(expected, fileHtml); assert.equal(expected, fileHtml);
}); });
@ -95,17 +95,17 @@ describe('LineByLinePrinter', function() {
diffParser.LINE_TYPE.INSERTS, '', 30, '+', ' test'); diffParser.LINE_TYPE.INSERTS, '', 30, '+', ' test');
fileHtml = fileHtml.replace(/\n\n+/g, '\n'); fileHtml = fileHtml.replace(/\n\n+/g, '\n');
var expected = '<tr>\n' + var expected = '<tr>\n' +
' <td class="d2h-code-linenumber d2h-ins">\n' + ' <td class="d2h-code-linenumber d2h-ins">\n' +
' <div class="line-num1"></div>\n' + ' <div class="line-num1"></div>\n' +
' <div class="line-num2">30</div>\n' + ' <div class="line-num2">30</div>\n' +
' </td>\n' + ' </td>\n' +
' <td class="d2h-ins">\n' + ' <td class="d2h-ins">\n' +
' <div class="d2h-code-line d2h-ins">\n' + ' <div class="d2h-code-line d2h-ins">\n' +
' <span class="d2h-code-line-prefix">&nbsp;&nbsp;&nbsp;&nbsp;test</span>\n' + ' <span class="d2h-code-line-prefix">&nbsp;&nbsp;&nbsp;&nbsp;test</span>\n' +
' <span class="d2h-code-line-ctn">+</span>\n' + ' <span class="d2h-code-line-ctn">+</span>\n' +
' </div>\n' + ' </div>\n' +
' </td>\n' + ' </td>\n' +
'</tr>\n'; '</tr>\n';
assert.equal(expected, fileHtml); assert.equal(expected, fileHtml);
}); });
@ -117,17 +117,17 @@ describe('LineByLinePrinter', function() {
diffParser.LINE_TYPE.INSERTS, '', 30, '+', Utils.escape('\ttest')); diffParser.LINE_TYPE.INSERTS, '', 30, '+', Utils.escape('\ttest'));
fileHtml = fileHtml.replace(/\n\n+/g, '\n'); fileHtml = fileHtml.replace(/\n\n+/g, '\n');
var expected = '<tr>\n' + var expected = '<tr>\n' +
' <td class="d2h-code-linenumber d2h-ins">\n' + ' <td class="d2h-code-linenumber d2h-ins">\n' +
' <div class="line-num1"></div>\n' + ' <div class="line-num1"></div>\n' +
' <div class="line-num2">30</div>\n' + ' <div class="line-num2">30</div>\n' +
' </td>\n' + ' </td>\n' +
' <td class="d2h-ins">\n' + ' <td class="d2h-ins">\n' +
' <div class="d2h-code-line d2h-ins">\n' + ' <div class="d2h-code-line d2h-ins">\n' +
' <span class="d2h-code-line-prefix">&nbsp;&nbsp;&nbsp;&nbsp;test</span>\n' + ' <span class="d2h-code-line-prefix">&nbsp;&nbsp;&nbsp;&nbsp;test</span>\n' +
' <span class="d2h-code-line-ctn">+</span>\n' + ' <span class="d2h-code-line-ctn">+</span>\n' +
' </div>\n' + ' </div>\n' +
' </td>\n' + ' </td>\n' +
'</tr>\n'; '</tr>\n';
assert.equal(expected, fileHtml); assert.equal(expected, fileHtml);
}); });

View file

@ -129,11 +129,11 @@ describe('SideBySidePrinter', function() {
var fileHtml = sideBySidePrinter.generateSingleLineHtml( var fileHtml = sideBySidePrinter.generateSingleLineHtml(
diffParser.LINE_TYPE.INSERTS, 30, 'test', '+'); diffParser.LINE_TYPE.INSERTS, 30, 'test', '+');
var expected = '<tr>\n' + var expected = '<tr>\n' +
' <td class="d2h-code-side-linenumber d2h-ins">30</td>\n' + ' <td class="d2h-code-side-linenumber d2h-ins">30</td>\n' +
' <td class="d2h-ins">' + ' <td class="d2h-ins">' +
' <div class="d2h-code-side-line d2h-ins"><span class="d2h-code-line-prefix">+</span><span class="d2h-code-line-ctn">test</span></div>' + ' <div class="d2h-code-side-line d2h-ins"><span class="d2h-code-line-prefix">+</span><span class="d2h-code-line-ctn">test</span></div>' +
' </td>\n' + ' </td>\n' +
' </tr>\n'; ' </tr>\n';
assert.equal(expected, fileHtml); assert.equal(expected, fileHtml);
}); });
@ -144,11 +144,11 @@ describe('SideBySidePrinter', function() {
var fileHtml = sideBySidePrinter.generateSingleLineHtml( var fileHtml = sideBySidePrinter.generateSingleLineHtml(
diffParser.LINE_TYPE.DELETES, 30, 'test', '-'); diffParser.LINE_TYPE.DELETES, 30, 'test', '-');
var expected = '<tr>\n' + var expected = '<tr>\n' +
' <td class="d2h-code-side-linenumber d2h-del">30</td>\n' + ' <td class="d2h-code-side-linenumber d2h-del">30</td>\n' +
' <td class="d2h-del">' + ' <td class="d2h-del">' +
' <div class="d2h-code-side-line d2h-del"><span class="d2h-code-line-prefix">-</span><span class="d2h-code-line-ctn">test</span></div>' + ' <div class="d2h-code-side-line d2h-del"><span class="d2h-code-line-prefix">-</span><span class="d2h-code-line-ctn">test</span></div>' +
' </td>\n' + ' </td>\n' +
' </tr>\n'; ' </tr>\n';
assert.equal(expected, fileHtml); assert.equal(expected, fileHtml);
}); });