2015-08-08 00:11:35 +00:00
|
|
|
|
/******/ (function(modules) { // webpackBootstrap
|
|
|
|
|
|
/******/ // The module cache
|
|
|
|
|
|
/******/ var installedModules = {};
|
|
|
|
|
|
|
|
|
|
|
|
/******/ // The require function
|
|
|
|
|
|
/******/ function __webpack_require__(moduleId) {
|
|
|
|
|
|
|
|
|
|
|
|
/******/ // Check if module is in cache
|
|
|
|
|
|
/******/ if(installedModules[moduleId])
|
|
|
|
|
|
/******/ return installedModules[moduleId].exports;
|
|
|
|
|
|
|
|
|
|
|
|
/******/ // Create a new module (and put it into the cache)
|
|
|
|
|
|
/******/ var module = installedModules[moduleId] = {
|
|
|
|
|
|
/******/ exports: {},
|
|
|
|
|
|
/******/ id: moduleId,
|
|
|
|
|
|
/******/ loaded: false
|
|
|
|
|
|
/******/ };
|
|
|
|
|
|
|
|
|
|
|
|
/******/ // Execute the module function
|
|
|
|
|
|
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
|
|
|
|
|
|
|
|
|
|
|
|
/******/ // Flag the module as loaded
|
|
|
|
|
|
/******/ module.loaded = true;
|
|
|
|
|
|
|
|
|
|
|
|
/******/ // Return the exports of the module
|
|
|
|
|
|
/******/ return module.exports;
|
|
|
|
|
|
/******/ }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/******/ // expose the modules object (__webpack_modules__)
|
|
|
|
|
|
/******/ __webpack_require__.m = modules;
|
|
|
|
|
|
|
|
|
|
|
|
/******/ // expose the module cache
|
|
|
|
|
|
/******/ __webpack_require__.c = installedModules;
|
|
|
|
|
|
|
|
|
|
|
|
/******/ // __webpack_public_path__
|
|
|
|
|
|
/******/ __webpack_require__.p = "";
|
|
|
|
|
|
|
|
|
|
|
|
/******/ // Load entry module and return exports
|
|
|
|
|
|
/******/ return __webpack_require__(0);
|
|
|
|
|
|
/******/ })
|
|
|
|
|
|
/************************************************************************/
|
|
|
|
|
|
/******/ ([
|
|
|
|
|
|
/* 0 */
|
|
|
|
|
|
/***/ function(module, exports, __webpack_require__) {
|
|
|
|
|
|
|
|
|
|
|
|
/* WEBPACK VAR INJECTION */(function(global) {/*
|
|
|
|
|
|
*
|
|
|
|
|
|
* Diff to HTML (diff2html.js)
|
|
|
|
|
|
* Author: rtfpessoa
|
|
|
|
|
|
*
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
2015-12-20 22:22:58 +00:00
|
|
|
|
(function() {
|
2015-08-08 00:11:35 +00:00
|
|
|
|
|
|
|
|
|
|
var diffParser = __webpack_require__(1).DiffParser;
|
2015-10-19 11:47:49 +00:00
|
|
|
|
var fileLister = __webpack_require__(3).FileListPrinter;
|
2015-12-19 21:09:31 +00:00
|
|
|
|
var htmlPrinter = __webpack_require__(21).HtmlPrinter;
|
2015-08-08 00:11:35 +00:00
|
|
|
|
|
|
|
|
|
|
function Diff2Html() {
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
* Line diff type configuration
|
|
|
|
|
|
var config = {
|
2015-12-20 22:22:58 +00:00
|
|
|
|
'wordByWord': true, // (default)
|
2015-08-08 00:11:35 +00:00
|
|
|
|
// OR
|
2015-12-20 22:22:58 +00:00
|
|
|
|
'charByChar': true
|
2015-08-08 00:11:35 +00:00
|
|
|
|
};
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2015-10-19 11:47:49 +00:00
|
|
|
|
* Generates json object from string diff input
|
2015-08-08 00:11:35 +00:00
|
|
|
|
*/
|
2015-10-19 11:47:49 +00:00
|
|
|
|
Diff2Html.prototype.getJsonFromDiff = function(diffInput) {
|
|
|
|
|
|
return diffParser.generateDiffJson(diffInput);
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
* Generates the html diff. The config parameter configures the output/input formats and other options
|
|
|
|
|
|
*/
|
|
|
|
|
|
Diff2Html.prototype.getPrettyHtml = function(diffInput, config) {
|
2015-08-08 00:11:35 +00:00
|
|
|
|
var configOrEmpty = config || {};
|
2015-10-19 11:47:49 +00:00
|
|
|
|
|
|
|
|
|
|
var diffJson = diffInput;
|
2015-12-20 22:22:58 +00:00
|
|
|
|
if (!configOrEmpty.inputFormat || configOrEmpty.inputFormat === 'diff') {
|
2015-10-19 11:47:49 +00:00
|
|
|
|
diffJson = diffParser.generateDiffJson(diffInput);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2015-12-20 22:22:58 +00:00
|
|
|
|
var fileList = '';
|
|
|
|
|
|
if (configOrEmpty.showFiles === true) {
|
2015-10-19 11:47:49 +00:00
|
|
|
|
fileList = fileLister.generateFileList(diffJson, configOrEmpty);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2015-12-20 22:22:58 +00:00
|
|
|
|
var diffOutput = '';
|
|
|
|
|
|
if (configOrEmpty.outputFormat === 'side-by-side') {
|
2015-10-19 11:47:49 +00:00
|
|
|
|
diffOutput = htmlPrinter.generateSideBySideJsonHtml(diffJson, configOrEmpty);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
diffOutput = htmlPrinter.generateLineByLineJsonHtml(diffJson, configOrEmpty);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2015-12-20 22:22:58 +00:00
|
|
|
|
return fileList + diffOutput;
|
2015-08-08 00:11:35 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
2015-10-19 11:47:49 +00:00
|
|
|
|
|
2015-08-08 00:11:35 +00:00
|
|
|
|
/*
|
2015-10-19 11:47:49 +00:00
|
|
|
|
* Deprecated methods - The following methods exist only to maintain compatibility with previous versions
|
2015-08-08 00:11:35 +00:00
|
|
|
|
*/
|
2015-10-19 11:47:49 +00:00
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
* Generates pretty html from string diff input
|
|
|
|
|
|
*/
|
|
|
|
|
|
Diff2Html.prototype.getPrettyHtmlFromDiff = function(diffInput, config) {
|
|
|
|
|
|
var configOrEmpty = config || {};
|
2015-12-20 22:22:58 +00:00
|
|
|
|
configOrEmpty.inputFormat = 'diff';
|
|
|
|
|
|
configOrEmpty.outputFormat = 'line-by-line';
|
|
|
|
|
|
return this.getPrettyHtml(diffInput, configOrEmpty);
|
2015-08-08 00:11:35 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
* Generates pretty html from a json object
|
|
|
|
|
|
*/
|
|
|
|
|
|
Diff2Html.prototype.getPrettyHtmlFromJson = function(diffJson, config) {
|
|
|
|
|
|
var configOrEmpty = config || {};
|
2015-12-20 22:22:58 +00:00
|
|
|
|
configOrEmpty.inputFormat = 'json';
|
|
|
|
|
|
configOrEmpty.outputFormat = 'line-by-line';
|
|
|
|
|
|
return this.getPrettyHtml(diffJson, configOrEmpty);
|
2015-08-08 00:11:35 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
* Generates pretty side by side html from string diff input
|
|
|
|
|
|
*/
|
|
|
|
|
|
Diff2Html.prototype.getPrettySideBySideHtmlFromDiff = function(diffInput, config) {
|
|
|
|
|
|
var configOrEmpty = config || {};
|
2015-12-20 22:22:58 +00:00
|
|
|
|
configOrEmpty.inputFormat = 'diff';
|
|
|
|
|
|
configOrEmpty.outputFormat = 'side-by-side';
|
|
|
|
|
|
return this.getPrettyHtml(diffInput, configOrEmpty);
|
2015-08-08 00:11:35 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
* Generates pretty side by side html from a json object
|
|
|
|
|
|
*/
|
|
|
|
|
|
Diff2Html.prototype.getPrettySideBySideHtmlFromJson = function(diffJson, config) {
|
|
|
|
|
|
var configOrEmpty = config || {};
|
2015-12-20 22:22:58 +00:00
|
|
|
|
configOrEmpty.inputFormat = 'json';
|
|
|
|
|
|
configOrEmpty.outputFormat = 'side-by-side';
|
|
|
|
|
|
return this.getPrettyHtml(diffJson, configOrEmpty);
|
2015-08-08 00:11:35 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
var diffObject = new Diff2Html();
|
2015-12-20 22:22:58 +00:00
|
|
|
|
module.exports.Diff2Html = diffObject;
|
|
|
|
|
|
|
2015-08-08 00:11:35 +00:00
|
|
|
|
// Expose diff2html in the browser
|
2015-12-20 22:22:58 +00:00
|
|
|
|
global.Diff2Html = diffObject;
|
2015-08-08 00:11:35 +00:00
|
|
|
|
|
2015-12-20 22:22:58 +00:00
|
|
|
|
})();
|
2015-08-08 00:11:35 +00:00
|
|
|
|
|
|
|
|
|
|
/* WEBPACK VAR INJECTION */}.call(exports, (function() { return this; }())))
|
|
|
|
|
|
|
|
|
|
|
|
/***/ },
|
|
|
|
|
|
/* 1 */
|
|
|
|
|
|
/***/ function(module, exports, __webpack_require__) {
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
*
|
|
|
|
|
|
* Diff Parser (diff-parser.js)
|
|
|
|
|
|
* Author: rtfpessoa
|
|
|
|
|
|
*
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
2015-12-20 22:22:58 +00:00
|
|
|
|
(function() {
|
2015-08-08 00:11:35 +00:00
|
|
|
|
|
|
|
|
|
|
var utils = __webpack_require__(2).Utils;
|
|
|
|
|
|
|
|
|
|
|
|
var LINE_TYPE = {
|
|
|
|
|
|
INSERTS: 'd2h-ins',
|
|
|
|
|
|
DELETES: 'd2h-del',
|
2015-12-19 21:09:31 +00:00
|
|
|
|
INSERT_CHANGES: 'd2h-ins d2h-change',
|
|
|
|
|
|
DELETE_CHANGES: 'd2h-del d2h-change',
|
2015-08-08 00:11:35 +00:00
|
|
|
|
CONTEXT: 'd2h-cntx',
|
|
|
|
|
|
INFO: 'd2h-info'
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
function DiffParser() {
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
DiffParser.prototype.LINE_TYPE = LINE_TYPE;
|
|
|
|
|
|
|
|
|
|
|
|
DiffParser.prototype.generateDiffJson = function(diffInput) {
|
|
|
|
|
|
var files = [];
|
|
|
|
|
|
var currentFile = null;
|
|
|
|
|
|
var currentBlock = null;
|
|
|
|
|
|
var oldLine = null;
|
|
|
|
|
|
var newLine = null;
|
|
|
|
|
|
|
|
|
|
|
|
var saveBlock = function() {
|
2015-12-20 22:22:58 +00:00
|
|
|
|
|
2015-08-08 00:11:35 +00:00
|
|
|
|
/* Add previous block(if exists) before start a new file */
|
|
|
|
|
|
if (currentBlock) {
|
|
|
|
|
|
currentFile.blocks.push(currentBlock);
|
|
|
|
|
|
currentBlock = null;
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
var saveFile = function() {
|
2015-12-20 22:22:58 +00:00
|
|
|
|
|
2015-08-08 00:11:35 +00:00
|
|
|
|
/*
|
|
|
|
|
|
* Add previous file(if exists) before start a new one
|
|
|
|
|
|
* if it has name (to avoid binary files errors)
|
|
|
|
|
|
*/
|
|
|
|
|
|
if (currentFile && currentFile.newName) {
|
|
|
|
|
|
files.push(currentFile);
|
|
|
|
|
|
currentFile = null;
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
var startFile = function() {
|
|
|
|
|
|
saveBlock();
|
|
|
|
|
|
saveFile();
|
|
|
|
|
|
|
|
|
|
|
|
/* Create file structure */
|
|
|
|
|
|
currentFile = {};
|
|
|
|
|
|
currentFile.blocks = [];
|
|
|
|
|
|
currentFile.deletedLines = 0;
|
|
|
|
|
|
currentFile.addedLines = 0;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
var startBlock = function(line) {
|
|
|
|
|
|
saveBlock();
|
|
|
|
|
|
|
|
|
|
|
|
var values;
|
|
|
|
|
|
|
|
|
|
|
|
if (values = /^@@ -(\d+),\d+ \+(\d+),\d+ @@.*/.exec(line)) {
|
|
|
|
|
|
currentFile.isCombined = false;
|
|
|
|
|
|
} else if (values = /^@@@ -(\d+),\d+ -\d+,\d+ \+(\d+),\d+ @@@.*/.exec(line)) {
|
|
|
|
|
|
currentFile.isCombined = true;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
values = [0, 0];
|
|
|
|
|
|
currentFile.isCombined = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
oldLine = values[1];
|
|
|
|
|
|
newLine = values[2];
|
|
|
|
|
|
|
|
|
|
|
|
/* Create block metadata */
|
|
|
|
|
|
currentBlock = {};
|
|
|
|
|
|
currentBlock.lines = [];
|
|
|
|
|
|
currentBlock.oldStartLine = oldLine;
|
|
|
|
|
|
currentBlock.newStartLine = newLine;
|
|
|
|
|
|
currentBlock.header = line;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
var createLine = function(line) {
|
|
|
|
|
|
var currentLine = {};
|
|
|
|
|
|
currentLine.content = line;
|
|
|
|
|
|
|
2015-08-08 00:56:50 +00:00
|
|
|
|
var newLinePrefixes = !currentFile.isCombined ? ['+'] : ['+', ' +'];
|
|
|
|
|
|
var delLinePrefixes = !currentFile.isCombined ? ['-'] : ['-', ' -'];
|
|
|
|
|
|
|
2015-08-08 00:11:35 +00:00
|
|
|
|
/* Fill the line data */
|
2015-08-08 00:56:50 +00:00
|
|
|
|
if (utils.startsWith(line, newLinePrefixes)) {
|
2015-08-08 00:11:35 +00:00
|
|
|
|
currentFile.addedLines++;
|
|
|
|
|
|
|
|
|
|
|
|
currentLine.type = LINE_TYPE.INSERTS;
|
|
|
|
|
|
currentLine.oldNumber = null;
|
|
|
|
|
|
currentLine.newNumber = newLine++;
|
|
|
|
|
|
|
|
|
|
|
|
currentBlock.lines.push(currentLine);
|
|
|
|
|
|
|
2015-08-08 00:56:50 +00:00
|
|
|
|
} else if (utils.startsWith(line, delLinePrefixes)) {
|
2015-08-08 00:11:35 +00:00
|
|
|
|
currentFile.deletedLines++;
|
|
|
|
|
|
|
|
|
|
|
|
currentLine.type = LINE_TYPE.DELETES;
|
|
|
|
|
|
currentLine.oldNumber = oldLine++;
|
|
|
|
|
|
currentLine.newNumber = null;
|
|
|
|
|
|
|
|
|
|
|
|
currentBlock.lines.push(currentLine);
|
|
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
currentLine.type = LINE_TYPE.CONTEXT;
|
|
|
|
|
|
currentLine.oldNumber = oldLine++;
|
|
|
|
|
|
currentLine.newNumber = newLine++;
|
|
|
|
|
|
|
|
|
|
|
|
currentBlock.lines.push(currentLine);
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2016-02-07 14:19:23 +00:00
|
|
|
|
var diffLines =
|
|
|
|
|
|
diffInput.replace(/\\ No newline at end of file/g, '')
|
2016-02-21 14:45:50 +00:00
|
|
|
|
.replace(/\r\n?/g, '\n')
|
2016-02-07 14:19:23 +00:00
|
|
|
|
.split('\n');
|
2015-10-28 18:54:16 +00:00
|
|
|
|
|
|
|
|
|
|
/* Diff */
|
|
|
|
|
|
var oldMode = /^old mode (\d{6})/;
|
|
|
|
|
|
var newMode = /^new mode (\d{6})/;
|
|
|
|
|
|
var deletedFileMode = /^deleted file mode (\d{6})/;
|
|
|
|
|
|
var newFileMode = /^new file mode (\d{6})/;
|
|
|
|
|
|
|
|
|
|
|
|
var copyFrom = /^copy from (.+)/;
|
|
|
|
|
|
var copyTo = /^copy to (.+)/;
|
|
|
|
|
|
|
|
|
|
|
|
var renameFrom = /^rename from (.+)/;
|
|
|
|
|
|
var renameTo = /^rename to (.+)/;
|
|
|
|
|
|
|
|
|
|
|
|
var similarityIndex = /^similarity index (\d+)%/;
|
|
|
|
|
|
var dissimilarityIndex = /^dissimilarity index (\d+)%/;
|
|
|
|
|
|
var index = /^index ([0-9a-z]+)..([0-9a-z]+) (\d{6})?/;
|
|
|
|
|
|
|
|
|
|
|
|
/* Combined Diff */
|
|
|
|
|
|
var combinedIndex = /^index ([0-9a-z]+),([0-9a-z]+)..([0-9a-z]+)/;
|
|
|
|
|
|
var combinedMode = /^mode (\d{6}),(\d{6})..(\d{6})/;
|
|
|
|
|
|
var combinedNewFile = /^new file mode (\d{6})/;
|
|
|
|
|
|
var combinedDeletedFile = /^deleted file mode (\d{6}),(\d{6})/;
|
|
|
|
|
|
|
2015-08-08 00:11:35 +00:00
|
|
|
|
diffLines.forEach(function(line) {
|
|
|
|
|
|
// Unmerged paths, and possibly other non-diffable files
|
|
|
|
|
|
// https://github.com/scottgonzalez/pretty-diff/issues/11
|
|
|
|
|
|
// Also, remove some useless lines
|
|
|
|
|
|
if (!line || utils.startsWith(line, '*')) {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var values = [];
|
|
|
|
|
|
if (utils.startsWith(line, 'diff')) {
|
|
|
|
|
|
startFile();
|
2015-10-05 19:08:39 +00:00
|
|
|
|
} else if (currentFile && !currentFile.oldName && (values = /^--- [aiwco]\/(.+)$/.exec(line))) {
|
2015-08-08 00:11:35 +00:00
|
|
|
|
currentFile.oldName = values[1];
|
|
|
|
|
|
currentFile.language = getExtension(currentFile.oldName, currentFile.language);
|
2015-10-05 19:08:39 +00:00
|
|
|
|
} else if (currentFile && !currentFile.newName && (values = /^\+\+\+ [biwco]?\/(.+)$/.exec(line))) {
|
2015-08-08 00:11:35 +00:00
|
|
|
|
currentFile.newName = values[1];
|
|
|
|
|
|
currentFile.language = getExtension(currentFile.newName, currentFile.language);
|
|
|
|
|
|
} else if (currentFile && utils.startsWith(line, '@@')) {
|
|
|
|
|
|
startBlock(line);
|
|
|
|
|
|
} else if ((values = oldMode.exec(line))) {
|
|
|
|
|
|
currentFile.oldMode = values[1];
|
|
|
|
|
|
} else if ((values = newMode.exec(line))) {
|
|
|
|
|
|
currentFile.newMode = values[1];
|
|
|
|
|
|
} else if ((values = deletedFileMode.exec(line))) {
|
|
|
|
|
|
currentFile.deletedFileMode = values[1];
|
|
|
|
|
|
} else if ((values = newFileMode.exec(line))) {
|
|
|
|
|
|
currentFile.newFileMode = values[1];
|
|
|
|
|
|
} else if ((values = copyFrom.exec(line))) {
|
|
|
|
|
|
currentFile.oldName = values[1];
|
|
|
|
|
|
currentFile.isCopy = true;
|
|
|
|
|
|
} else if ((values = copyTo.exec(line))) {
|
|
|
|
|
|
currentFile.newName = values[1];
|
|
|
|
|
|
currentFile.isCopy = true;
|
|
|
|
|
|
} else if ((values = renameFrom.exec(line))) {
|
|
|
|
|
|
currentFile.oldName = values[1];
|
|
|
|
|
|
currentFile.isRename = true;
|
|
|
|
|
|
} else if ((values = renameTo.exec(line))) {
|
|
|
|
|
|
currentFile.newName = values[1];
|
|
|
|
|
|
currentFile.isRename = true;
|
|
|
|
|
|
} else if ((values = similarityIndex.exec(line))) {
|
|
|
|
|
|
currentFile.unchangedPercentage = values[1];
|
|
|
|
|
|
} else if ((values = dissimilarityIndex.exec(line))) {
|
|
|
|
|
|
currentFile.changedPercentage = values[1];
|
|
|
|
|
|
} else if ((values = index.exec(line))) {
|
|
|
|
|
|
currentFile.checksumBefore = values[1];
|
|
|
|
|
|
currentFile.checksumAfter = values[2];
|
|
|
|
|
|
values[2] && (currentFile.mode = values[3]);
|
|
|
|
|
|
} else if ((values = combinedIndex.exec(line))) {
|
|
|
|
|
|
currentFile.checksumBefore = [values[2], values[3]];
|
|
|
|
|
|
currentFile.checksumAfter = values[1];
|
|
|
|
|
|
} else if ((values = combinedMode.exec(line))) {
|
|
|
|
|
|
currentFile.oldMode = [values[2], values[3]];
|
|
|
|
|
|
currentFile.newMode = values[1];
|
|
|
|
|
|
} else if ((values = combinedNewFile.exec(line))) {
|
|
|
|
|
|
currentFile.newFileMode = values[1];
|
|
|
|
|
|
} else if ((values = combinedDeletedFile.exec(line))) {
|
|
|
|
|
|
currentFile.deletedFileMode = values[1];
|
|
|
|
|
|
} else if (currentBlock) {
|
|
|
|
|
|
createLine(line);
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
saveBlock();
|
|
|
|
|
|
saveFile();
|
|
|
|
|
|
|
|
|
|
|
|
return files;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
function getExtension(filename, language) {
|
|
|
|
|
|
var nameSplit = filename.split('.');
|
|
|
|
|
|
if (nameSplit.length > 1) {
|
|
|
|
|
|
return nameSplit[nameSplit.length - 1];
|
|
|
|
|
|
}
|
2015-12-20 22:22:58 +00:00
|
|
|
|
|
|
|
|
|
|
return language;
|
2015-08-08 00:11:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2015-12-20 22:22:58 +00:00
|
|
|
|
module.exports.DiffParser = new DiffParser();
|
2015-08-08 00:11:35 +00:00
|
|
|
|
|
2015-12-20 22:22:58 +00:00
|
|
|
|
})();
|
2015-08-08 00:11:35 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/***/ },
|
|
|
|
|
|
/* 2 */
|
|
|
|
|
|
/***/ function(module, exports) {
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
*
|
|
|
|
|
|
* Utils (utils.js)
|
|
|
|
|
|
* Author: rtfpessoa
|
|
|
|
|
|
*
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
2015-12-20 22:22:58 +00:00
|
|
|
|
(function() {
|
2015-08-08 00:11:35 +00:00
|
|
|
|
|
|
|
|
|
|
function Utils() {
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-01-31 18:33:33 +00:00
|
|
|
|
Utils.prototype.convertWhiteSpaceToNonBreakingSpace = function(str) {
|
|
|
|
|
|
return str.slice(0).replace(/ /g, ' ');
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2015-08-08 00:11:35 +00:00
|
|
|
|
Utils.prototype.escape = function(str) {
|
|
|
|
|
|
return str.slice(0)
|
|
|
|
|
|
.replace(/&/g, '&')
|
|
|
|
|
|
.replace(/</g, '<')
|
|
|
|
|
|
.replace(/>/g, '>')
|
|
|
|
|
|
.replace(/\t/g, ' ');
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
Utils.prototype.startsWith = function(str, start) {
|
2015-08-08 00:56:50 +00:00
|
|
|
|
if (typeof start === 'object') {
|
|
|
|
|
|
var result = false;
|
|
|
|
|
|
start.forEach(function(s) {
|
|
|
|
|
|
if (str.indexOf(s) === 0) {
|
|
|
|
|
|
result = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2015-08-08 00:11:35 +00:00
|
|
|
|
return str.indexOf(start) === 0;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
Utils.prototype.valueOrEmpty = function(value) {
|
|
|
|
|
|
return value ? value : '';
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2015-12-20 22:22:58 +00:00
|
|
|
|
module.exports.Utils = new Utils();
|
2015-08-08 00:11:35 +00:00
|
|
|
|
|
2015-12-20 22:22:58 +00:00
|
|
|
|
})();
|
2015-08-08 00:11:35 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/***/ },
|
|
|
|
|
|
/* 3 */
|
|
|
|
|
|
/***/ function(module, exports, __webpack_require__) {
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
*
|
2015-10-19 11:47:49 +00:00
|
|
|
|
* FileListPrinter (file-list-printer.js)
|
|
|
|
|
|
* Author: nmatpt
|
2015-08-08 00:11:35 +00:00
|
|
|
|
*
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
2015-12-20 22:22:58 +00:00
|
|
|
|
(function() {
|
2015-08-08 00:11:35 +00:00
|
|
|
|
|
2015-12-20 22:22:58 +00:00
|
|
|
|
var printerUtils = __webpack_require__(4).PrinterUtils;
|
2015-08-08 00:11:35 +00:00
|
|
|
|
|
2015-12-20 22:22:58 +00:00
|
|
|
|
function FileListPrinter() {
|
|
|
|
|
|
}
|
2015-08-08 00:11:35 +00:00
|
|
|
|
|
2015-12-20 22:22:58 +00:00
|
|
|
|
FileListPrinter.prototype.generateFileList = function(diffFiles) {
|
|
|
|
|
|
return '<div class="d2h-file-list-wrapper">\n' +
|
|
|
|
|
|
' <div class="d2h-file-list-header">Files changed (' + diffFiles.length + ')  </div>\n' +
|
2016-02-21 14:45:50 +00:00
|
|
|
|
' <a class="d2h-file-switch d2h-hide">hide</a>\n' +
|
|
|
|
|
|
' <a class="d2h-file-switch d2h-show">show</a>\n' +
|
2015-12-20 22:22:58 +00:00
|
|
|
|
' <div class="d2h-clear"></div>\n' +
|
|
|
|
|
|
' <table class="d2h-file-list">\n' +
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
diffFiles.map(function(file) {
|
|
|
|
|
|
return ' <tr class="d2h-file-list-line">\n' +
|
|
|
|
|
|
' <td class="d2h-lines-added">\n' +
|
|
|
|
|
|
' <span>+' + file.addedLines + '</span>\n' +
|
|
|
|
|
|
' </td>\n' +
|
|
|
|
|
|
' <td class="d2h-lines-deleted">\n' +
|
|
|
|
|
|
' <span>-' + file.deletedLines + '</span>\n' +
|
|
|
|
|
|
' </td>\n' +
|
2016-02-07 14:19:23 +00:00
|
|
|
|
' <td class="d2h-file-name"><a href="#' + printerUtils.getHtmlId(file) + '">' +
|
|
|
|
|
|
' ' + printerUtils.getDiffName(file) + '</a></td>\n' +
|
2015-12-20 22:22:58 +00:00
|
|
|
|
' </tr>\n';
|
|
|
|
|
|
}).join('\n') +
|
|
|
|
|
|
'</table></div>\n';
|
|
|
|
|
|
};
|
2015-08-08 00:11:35 +00:00
|
|
|
|
|
2015-12-20 22:22:58 +00:00
|
|
|
|
module.exports.FileListPrinter = new FileListPrinter();
|
2015-08-08 00:11:35 +00:00
|
|
|
|
|
2015-12-20 22:22:58 +00:00
|
|
|
|
})();
|
2015-08-08 00:11:35 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/***/ },
|
2015-10-19 11:47:49 +00:00
|
|
|
|
/* 4 */
|
2015-08-08 00:11:35 +00:00
|
|
|
|
/***/ function(module, exports, __webpack_require__) {
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
*
|
|
|
|
|
|
* PrinterUtils (printer-utils.js)
|
|
|
|
|
|
* Author: rtfpessoa
|
|
|
|
|
|
*
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
2015-12-20 22:22:58 +00:00
|
|
|
|
(function() {
|
2015-08-08 00:11:35 +00:00
|
|
|
|
|
2015-10-19 11:47:49 +00:00
|
|
|
|
var jsDiff = __webpack_require__(5);
|
2015-08-08 00:11:35 +00:00
|
|
|
|
var utils = __webpack_require__(2).Utils;
|
2015-12-19 21:09:31 +00:00
|
|
|
|
var Rematch = __webpack_require__(20).Rematch;
|
2015-08-08 00:11:35 +00:00
|
|
|
|
|
|
|
|
|
|
function PrinterUtils() {
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2015-10-19 11:47:49 +00:00
|
|
|
|
PrinterUtils.prototype.getHtmlId = function(file) {
|
2015-12-20 22:22:58 +00:00
|
|
|
|
var hashCode = function(text) {
|
|
|
|
|
|
var i, chr, len;
|
|
|
|
|
|
var hash = 0;
|
|
|
|
|
|
|
2016-02-07 14:19:23 +00:00
|
|
|
|
if (text.length === 0) {
|
|
|
|
|
|
return hash;
|
|
|
|
|
|
}
|
2015-12-20 22:22:58 +00:00
|
|
|
|
|
2015-10-19 14:43:16 +00:00
|
|
|
|
for (i = 0, len = text.length; i < len; i++) {
|
2015-12-20 22:22:58 +00:00
|
|
|
|
chr = text.charCodeAt(i);
|
|
|
|
|
|
hash = ((hash << 5) - hash) + chr;
|
2015-10-19 14:43:16 +00:00
|
|
|
|
hash |= 0; // Convert to 32bit integer
|
|
|
|
|
|
}
|
2015-12-20 22:22:58 +00:00
|
|
|
|
|
2015-10-19 14:43:16 +00:00
|
|
|
|
return hash;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2015-12-20 22:22:58 +00:00
|
|
|
|
return 'd2h-' + hashCode(this.getDiffName(file)).toString().slice(-6);
|
2015-10-19 11:47:49 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
2015-08-08 00:11:35 +00:00
|
|
|
|
PrinterUtils.prototype.getDiffName = function(file) {
|
|
|
|
|
|
var oldFilename = file.oldName;
|
|
|
|
|
|
var newFilename = file.newName;
|
|
|
|
|
|
|
2015-12-20 22:22:58 +00:00
|
|
|
|
if (oldFilename && newFilename && oldFilename !== newFilename && !isDeletedName(newFilename)) {
|
2015-08-08 00:11:35 +00:00
|
|
|
|
return oldFilename + ' -> ' + newFilename;
|
|
|
|
|
|
} else if (newFilename && !isDeletedName(newFilename)) {
|
|
|
|
|
|
return newFilename;
|
|
|
|
|
|
} else if (oldFilename) {
|
|
|
|
|
|
return oldFilename;
|
|
|
|
|
|
}
|
2015-12-20 22:22:58 +00:00
|
|
|
|
|
|
|
|
|
|
return 'Unknown filename';
|
2015-08-08 00:11:35 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
PrinterUtils.prototype.diffHighlight = function(diffLine1, diffLine2, config) {
|
2015-12-20 22:22:58 +00:00
|
|
|
|
var linePrefix1, linePrefix2, unprefixedLine1, unprefixedLine2;
|
2015-08-08 00:11:35 +00:00
|
|
|
|
|
|
|
|
|
|
var prefixSize = 1;
|
|
|
|
|
|
|
|
|
|
|
|
if (config.isCombined) {
|
|
|
|
|
|
prefixSize = 2;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2015-12-20 22:22:58 +00:00
|
|
|
|
linePrefix1 = diffLine1.substr(0, prefixSize);
|
|
|
|
|
|
linePrefix2 = diffLine2.substr(0, prefixSize);
|
|
|
|
|
|
unprefixedLine1 = diffLine1.substr(prefixSize);
|
|
|
|
|
|
unprefixedLine2 = diffLine2.substr(prefixSize);
|
2015-08-08 00:11:35 +00:00
|
|
|
|
|
|
|
|
|
|
var diff;
|
|
|
|
|
|
if (config.charByChar) {
|
2015-12-20 22:22:58 +00:00
|
|
|
|
diff = jsDiff.diffChars(unprefixedLine1, unprefixedLine2);
|
2015-08-08 00:11:35 +00:00
|
|
|
|
} else {
|
2015-12-20 22:22:58 +00:00
|
|
|
|
diff = jsDiff.diffWordsWithSpace(unprefixedLine1, unprefixedLine2);
|
2015-08-08 00:11:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var highlightedLine = '';
|
|
|
|
|
|
|
2015-12-19 21:09:31 +00:00
|
|
|
|
var changedWords = [];
|
|
|
|
|
|
if (!config.charByChar && config.matching === 'words') {
|
|
|
|
|
|
var treshold = 0.25;
|
2015-12-20 22:22:58 +00:00
|
|
|
|
|
2016-02-07 14:19:23 +00:00
|
|
|
|
if (typeof (config.matchWordsThreshold) !== 'undefined') {
|
2015-12-19 21:09:31 +00:00
|
|
|
|
treshold = config.matchWordsThreshold;
|
|
|
|
|
|
}
|
2015-12-20 22:22:58 +00:00
|
|
|
|
|
2015-12-19 21:09:31 +00:00
|
|
|
|
var matcher = Rematch.rematch(function(a, b) {
|
2015-12-20 22:22:58 +00:00
|
|
|
|
var amod = a.value;
|
|
|
|
|
|
var bmod = b.value;
|
|
|
|
|
|
|
|
|
|
|
|
return Rematch.distance(amod, bmod);
|
2015-12-19 21:09:31 +00:00
|
|
|
|
});
|
2015-12-20 22:22:58 +00:00
|
|
|
|
|
|
|
|
|
|
var removed = diff.filter(function isRemoved(element) {
|
2015-12-19 21:09:31 +00:00
|
|
|
|
return element.removed;
|
|
|
|
|
|
});
|
2015-12-20 22:22:58 +00:00
|
|
|
|
|
|
|
|
|
|
var added = diff.filter(function isAdded(element) {
|
2015-12-19 21:09:31 +00:00
|
|
|
|
return element.added;
|
|
|
|
|
|
});
|
2015-12-20 22:22:58 +00:00
|
|
|
|
|
2015-12-19 21:09:31 +00:00
|
|
|
|
var chunks = matcher(added, removed);
|
2015-12-20 22:22:58 +00:00
|
|
|
|
chunks.forEach(function(chunk) {
|
|
|
|
|
|
if (chunk[0].length === 1 && chunk[1].length === 1) {
|
|
|
|
|
|
var dist = Rematch.distance(chunk[0][0].value, chunk[1][0].value);
|
2015-12-19 21:09:31 +00:00
|
|
|
|
if (dist < treshold) {
|
|
|
|
|
|
changedWords.push(chunk[0][0]);
|
|
|
|
|
|
changedWords.push(chunk[1][0]);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
2015-12-20 22:22:58 +00:00
|
|
|
|
|
2015-08-08 00:11:35 +00:00
|
|
|
|
diff.forEach(function(part) {
|
2015-12-19 21:09:31 +00:00
|
|
|
|
var addClass = changedWords.indexOf(part) > -1 ? ' class="d2h-change"' : '';
|
2015-08-08 00:11:35 +00:00
|
|
|
|
var elemType = part.added ? 'ins' : part.removed ? 'del' : null;
|
|
|
|
|
|
var escapedValue = utils.escape(part.value);
|
|
|
|
|
|
|
|
|
|
|
|
if (elemType !== null) {
|
2015-12-19 21:09:31 +00:00
|
|
|
|
highlightedLine += '<' + elemType + addClass + '>' + escapedValue + '</' + elemType + '>';
|
2015-08-08 00:11:35 +00:00
|
|
|
|
} else {
|
|
|
|
|
|
highlightedLine += escapedValue;
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
|
first: {
|
2015-12-20 22:22:58 +00:00
|
|
|
|
prefix: linePrefix1,
|
2015-08-08 00:11:35 +00:00
|
|
|
|
line: removeIns(highlightedLine)
|
|
|
|
|
|
},
|
|
|
|
|
|
second: {
|
2015-12-20 22:22:58 +00:00
|
|
|
|
prefix: linePrefix2,
|
2015-08-08 00:11:35 +00:00
|
|
|
|
line: removeDel(highlightedLine)
|
|
|
|
|
|
}
|
2015-12-20 23:38:16 +00:00
|
|
|
|
};
|
2015-08-08 00:11:35 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
function isDeletedName(name) {
|
|
|
|
|
|
return name === 'dev/null';
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function removeIns(line) {
|
2015-12-19 21:09:31 +00:00
|
|
|
|
return line.replace(/(<ins[^>]*>((.|\n)*?)<\/ins>)/g, '');
|
2015-08-08 00:11:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function removeDel(line) {
|
2015-12-19 21:09:31 +00:00
|
|
|
|
return line.replace(/(<del[^>]*>((.|\n)*?)<\/del>)/g, '');
|
2015-08-08 00:11:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2015-12-20 22:22:58 +00:00
|
|
|
|
module.exports.PrinterUtils = new PrinterUtils();
|
2015-08-08 00:11:35 +00:00
|
|
|
|
|
2015-12-20 22:22:58 +00:00
|
|
|
|
})();
|
2015-08-08 00:11:35 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/***/ },
|
2015-10-19 11:47:49 +00:00
|
|
|
|
/* 5 */
|
2015-08-08 00:11:35 +00:00
|
|
|
|
/***/ function(module, exports, __webpack_require__) {
|
|
|
|
|
|
|
2015-10-31 21:55:15 +00:00
|
|
|
|
/* See LICENSE file for terms of use */
|
2015-08-08 00:11:35 +00:00
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
* Text diff implementation.
|
|
|
|
|
|
*
|
|
|
|
|
|
* This library supports the following APIS:
|
|
|
|
|
|
* JsDiff.diffChars: Character by character diff
|
|
|
|
|
|
* JsDiff.diffWords: Word (as defined by \b regex) diff which ignores whitespace
|
|
|
|
|
|
* JsDiff.diffLines: Line based diff
|
|
|
|
|
|
*
|
|
|
|
|
|
* JsDiff.diffCss: Diff targeted at CSS content
|
|
|
|
|
|
*
|
|
|
|
|
|
* These methods are based on the implementation proposed in
|
|
|
|
|
|
* "An O(ND) Difference Algorithm and its Variations" (Myers, 1986).
|
|
|
|
|
|
* http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.4.6927
|
|
|
|
|
|
*/
|
2015-10-31 21:55:15 +00:00
|
|
|
|
'use strict';
|
2015-08-08 00:11:35 +00:00
|
|
|
|
|
2015-10-31 21:55:15 +00:00
|
|
|
|
exports.__esModule = true;
|
|
|
|
|
|
// istanbul ignore next
|
|
|
|
|
|
|
|
|
|
|
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
|
|
|
|
|
|
|
|
|
|
|
|
var _diffBase = __webpack_require__(6);
|
|
|
|
|
|
|
|
|
|
|
|
var _diffBase2 = _interopRequireDefault(_diffBase);
|
|
|
|
|
|
|
|
|
|
|
|
var _diffCharacter = __webpack_require__(7);
|
|
|
|
|
|
|
|
|
|
|
|
var _diffWord = __webpack_require__(8);
|
|
|
|
|
|
|
|
|
|
|
|
var _diffLine = __webpack_require__(10);
|
|
|
|
|
|
|
|
|
|
|
|
var _diffSentence = __webpack_require__(11);
|
|
|
|
|
|
|
|
|
|
|
|
var _diffCss = __webpack_require__(12);
|
|
|
|
|
|
|
|
|
|
|
|
var _diffJson = __webpack_require__(13);
|
|
|
|
|
|
|
|
|
|
|
|
var _patchApply = __webpack_require__(14);
|
|
|
|
|
|
|
|
|
|
|
|
var _patchParse = __webpack_require__(15);
|
|
|
|
|
|
|
|
|
|
|
|
var _patchCreate = __webpack_require__(17);
|
|
|
|
|
|
|
|
|
|
|
|
var _convertDmp = __webpack_require__(18);
|
|
|
|
|
|
|
|
|
|
|
|
var _convertXml = __webpack_require__(19);
|
|
|
|
|
|
|
|
|
|
|
|
exports.Diff = _diffBase2['default'];
|
|
|
|
|
|
exports.diffChars = _diffCharacter.diffChars;
|
|
|
|
|
|
exports.diffWords = _diffWord.diffWords;
|
|
|
|
|
|
exports.diffWordsWithSpace = _diffWord.diffWordsWithSpace;
|
|
|
|
|
|
exports.diffLines = _diffLine.diffLines;
|
|
|
|
|
|
exports.diffTrimmedLines = _diffLine.diffTrimmedLines;
|
|
|
|
|
|
exports.diffSentences = _diffSentence.diffSentences;
|
|
|
|
|
|
exports.diffCss = _diffCss.diffCss;
|
|
|
|
|
|
exports.diffJson = _diffJson.diffJson;
|
|
|
|
|
|
exports.structuredPatch = _patchCreate.structuredPatch;
|
|
|
|
|
|
exports.createTwoFilesPatch = _patchCreate.createTwoFilesPatch;
|
|
|
|
|
|
exports.createPatch = _patchCreate.createPatch;
|
|
|
|
|
|
exports.applyPatch = _patchApply.applyPatch;
|
|
|
|
|
|
exports.applyPatches = _patchApply.applyPatches;
|
|
|
|
|
|
exports.parsePatch = _patchParse.parsePatch;
|
|
|
|
|
|
exports.convertChangesToDMP = _convertDmp.convertChangesToDMP;
|
|
|
|
|
|
exports.convertChangesToXML = _convertXml.convertChangesToXML;
|
|
|
|
|
|
exports.canonicalize = _diffJson.canonicalize;
|
|
|
|
|
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uL3NyYy9pbmRleC5qcyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozt3QkFnQmlCLGFBQWE7Ozs7NkJBQ04sa0JBQWtCOzt3QkFDRSxhQUFhOzt3QkFDZixhQUFhOzs0QkFDM0IsaUJBQWlCOzt1QkFFdkIsWUFBWTs7d0JBQ0csYUFBYTs7MEJBRVgsZUFBZTs7MEJBQzdCLGVBQWU7OzJCQUN3QixnQkFBZ0I7OzBCQUU5QyxlQUFlOzswQkFDZixlQUFlOztRQUcvQyxJQUFJO1FBRUosU0FBUztRQUNULFNBQVM7UUFDVCxrQkFBa0I7UUFDbEIsU0FBUztRQUNULGdCQUFnQjtRQUNoQixhQUFhO1FBRWIsT0FBTztRQUNQLFFBQVE7UUFFUixlQUFlO1FBQ2YsbUJBQW1CO1FBQ25CLFdBQVc7UUFDWCxVQUFVO1FBQ1YsWUFBWTtRQUNaLFVBQVU7UUFDVixtQkFBbUI7UUFDbkIsbUJBQW1CO1FBQ25CLFlBQVkiLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VzQ29udGVudCI6WyIvKiBTZWUgTElDRU5TRSBmaWxlIGZvciB0ZXJtcyBvZiB1c2UgKi9cblxuLypcbiAqIFRleHQgZGlmZiBpbXBsZW1lbnRhdGlvbi5cbiAqXG4gKiBUa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mYvanNvbic7XG5cbmltcG9ydCB7YXBwbHlQYXRjaCwgYXBwbHlQYXRjaGVzfSBmcm9tICcuL3BhdGNoL2FwcGx5JztcbmltcG9ydCB7cGFyc2VQYXRjaH0gZnJvbSAnLi9wYXRjaC9wYXJzZSc7XG5pbXBvcnQge3N0cnVjdHVyZWRQYXRjaCwgY3JlYXRlVHdvRmlsZXNQYXRjaCwgY3JlYXRlUGF0Y2h9IGZyb20gJy4vcGF0Y2gvY3JlYXRlJztcblxuaW1wb3J0IHtjb252ZXJ0Q2hhbmdlc1RvRE1QfSBmcm9tICcuL2NvbnZlcnQvZG1wJztcbmltcG9ydCB7Y29udmVydENoYW5nZXNUb1hNTH0gZnJvbSAnLi9jb252ZXJ0L3htbCc7XG5cbmV4cG9ydCB7XG4gIERpZmYsXG5cbiAgZGlmZkNoYXJzLFxuICBkaWZmV29yZHMsXG4gIGRpZmZXb3Jkc1dpdGhTcGFjZSxcbiAgZGlmZkxpbmVzLFxuICBkaWZmVHJpbW1lZExpbmVzLFxuICBkaWZmU2VudGVuY2VzLFxuXG4gIGRpZmZDc3MsXG4gIGRpZmZKc29uLFxuXG4gIHN0cnVjdHVyZWRQYXRjaCxcbiAgY3JlYXRlVHdvRmlsZXNQYXRjaCxcbiAgY3JlYXRlUGF0Y2gsXG4gIGFwcGx5UGF0Y2gsXG4gIGFwcGx5UGF0Y2hlcyxcbiAgcGFyc2VQYXRjaCxcbiAgY29udmVydENoYW5nZXNUb0RNUCxcbiAgY29udmVydENoYW5nZXNUb1hNTCxcbiAgY2Fub25pY2FsaXplXG59O1xuIl19
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/***/ },
|
|
|
|
|
|
/* 6 */
|
|
|
|
|
|
/***/ function(module, exports) {
|
|
|
|
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
|
|
exports.__esModule = true;
|
|
|
|
|
|
exports['default'] = Diff;
|
|
|
|
|
|
|
|
|
|
|
|
function Diff() {}
|
|
|
|
|
|
|
|
|
|
|
|
Diff.prototype = {
|
|
|
|
|
|
diff: function diff(oldString, newString) {
|
|
|
|
|
|
var options = arguments.length <= 2 || arguments[2] === undefined ? {} : arguments[2];
|
|
|
|
|
|
|
|
|
|
|
|
var callback = options.callback;
|
|
|
|
|
|
if (typeof options === 'function') {
|
|
|
|
|
|
callback = options;
|
|
|
|
|
|
options = {};
|
2015-08-08 00:11:35 +00:00
|
|
|
|
}
|
2015-10-31 21:55:15 +00:00
|
|
|
|
this.options = options;
|
2015-08-08 00:11:35 +00:00
|
|
|
|
|
2015-10-31 21:55:15 +00:00
|
|
|
|
var self = this;
|
2015-08-08 00:11:35 +00:00
|
|
|
|
|
2015-10-31 21:55:15 +00:00
|
|
|
|
function done(value) {
|
|
|
|
|
|
if (callback) {
|
|
|
|
|
|
setTimeout(function () {
|
|
|
|
|
|
callback(undefined, value);
|
|
|
|
|
|
}, 0);
|
|
|
|
|
|
return true;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
return value;
|
|
|
|
|
|
}
|
2015-08-08 00:11:35 +00:00
|
|
|
|
}
|
2015-10-31 21:55:15 +00:00
|
|
|
|
|
|
|
|
|
|
// Allow subclasses to massage the input prior to running
|
|
|
|
|
|
oldString = this.castInput(oldString);
|
|
|
|
|
|
newString = this.castInput(newString);
|
|
|
|
|
|
|
|
|
|
|
|
oldString = this.removeEmpty(this.tokenize(oldString));
|
|
|
|
|
|
newString = this.removeEmpty(this.tokenize(newString));
|
|
|
|
|
|
|
|
|
|
|
|
var newLen = newString.length,
|
|
|
|
|
|
oldLen = oldString.length;
|
|
|
|
|
|
var editLength = 1;
|
|
|
|
|
|
var maxEditLength = newLen + oldLen;
|
|
|
|
|
|
var bestPath = [{ newPos: -1, components: [] }];
|
|
|
|
|
|
|
|
|
|
|
|
// Seed editLength = 0, i.e. the content starts with the same values
|
|
|
|
|
|
var oldPos = this.extractCommon(bestPath[0], newString, oldString, 0);
|
|
|
|
|
|
if (bestPath[0].newPos + 1 >= newLen && oldPos + 1 >= oldLen) {
|
|
|
|
|
|
// Identity per the equality and tokenizer
|
|
|
|
|
|
return done([{ value: newString.join(''), count: newString.length }]);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Main worker method. checks all permutations of a given edit length for acceptance.
|
|
|
|
|
|
function execEditLength() {
|
|
|
|
|
|
for (var diagonalPath = -1 * editLength; diagonalPath <= editLength; diagonalPath += 2) {
|
|
|
|
|
|
var basePath = undefined;
|
|
|
|
|
|
var addPath = bestPath[diagonalPath - 1],
|
|
|
|
|
|
removePath = bestPath[diagonalPath + 1],
|
|
|
|
|
|
_oldPos = (removePath ? removePath.newPos : 0) - diagonalPath;
|
|
|
|
|
|
if (addPath) {
|
|
|
|
|
|
// No one else is going to attempt to use this value, clear it
|
|
|
|
|
|
bestPath[diagonalPath - 1] = undefined;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var canAdd = addPath && addPath.newPos + 1 < newLen,
|
|
|
|
|
|
canRemove = removePath && 0 <= _oldPos && _oldPos < oldLen;
|
|
|
|
|
|
if (!canAdd && !canRemove) {
|
|
|
|
|
|
// If this path is a terminal then prune
|
|
|
|
|
|
bestPath[diagonalPath] = undefined;
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Select the diagonal that we want to branch from. We select the prior
|
|
|
|
|
|
// path whose position in the new string is the farthest from the origin
|
|
|
|
|
|
// and does not pass the bounds of the diff graph
|
|
|
|
|
|
if (!canAdd || canRemove && addPath.newPos < removePath.newPos) {
|
|
|
|
|
|
basePath = clonePath(removePath);
|
|
|
|
|
|
self.pushComponent(basePath.components, undefined, true);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
basePath = addPath; // No need to clone, we've pulled it from the list
|
|
|
|
|
|
basePath.newPos++;
|
|
|
|
|
|
self.pushComponent(basePath.components, true, undefined);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
_oldPos = self.extractCommon(basePath, newString, oldString, diagonalPath);
|
|
|
|
|
|
|
|
|
|
|
|
// If we have hit the end of both strings, then we are done
|
|
|
|
|
|
if (basePath.newPos + 1 >= newLen && _oldPos + 1 >= oldLen) {
|
|
|
|
|
|
return done(buildValues(self, basePath.components, newString, oldString, self.useLongestToken));
|
|
|
|
|
|
} else {
|
|
|
|
|
|
// Otherwise track this path as a potential candidate and continue.
|
|
|
|
|
|
bestPath[diagonalPath] = basePath;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
editLength++;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Performs the length of edit iteration. Is a bit fugly as this has to support the
|
|
|
|
|
|
// sync and async mode which is never fun. Loops over execEditLength until a value
|
|
|
|
|
|
// is produced.
|
|
|
|
|
|
if (callback) {
|
|
|
|
|
|
(function exec() {
|
|
|
|
|
|
setTimeout(function () {
|
|
|
|
|
|
// This should not happen, but we want to be safe.
|
|
|
|
|
|
/* istanbul ignore next */
|
|
|
|
|
|
if (editLength > maxEditLength) {
|
|
|
|
|
|
return callback();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!execEditLength()) {
|
|
|
|
|
|
exec();
|
|
|
|
|
|
}
|
|
|
|
|
|
}, 0);
|
|
|
|
|
|
})();
|
|
|
|
|
|
} else {
|
|
|
|
|
|
while (editLength <= maxEditLength) {
|
|
|
|
|
|
var ret = execEditLength();
|
|
|
|
|
|
if (ret) {
|
|
|
|
|
|
return ret;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
pushComponent: function pushComponent(components, added, removed) {
|
|
|
|
|
|
var last = components[components.length - 1];
|
|
|
|
|
|
if (last && last.added === added && last.removed === removed) {
|
|
|
|
|
|
// We need to clone here as the component clone operation is just
|
|
|
|
|
|
// as shallow array clone
|
|
|
|
|
|
components[components.length - 1] = { count: last.count + 1, added: added, removed: removed };
|
|
|
|
|
|
} else {
|
|
|
|
|
|
components.push({ count: 1, added: added, removed: removed });
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
extractCommon: function extractCommon(basePath, newString, oldString, diagonalPath) {
|
|
|
|
|
|
var newLen = newString.length,
|
|
|
|
|
|
oldLen = oldString.length,
|
|
|
|
|
|
newPos = basePath.newPos,
|
|
|
|
|
|
oldPos = newPos - diagonalPath,
|
|
|
|
|
|
commonCount = 0;
|
|
|
|
|
|
while (newPos + 1 < newLen && oldPos + 1 < oldLen && this.equals(newString[newPos + 1], oldString[oldPos + 1])) {
|
|
|
|
|
|
newPos++;
|
|
|
|
|
|
oldPos++;
|
|
|
|
|
|
commonCount++;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (commonCount) {
|
|
|
|
|
|
basePath.components.push({ count: commonCount });
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
basePath.newPos = newPos;
|
|
|
|
|
|
return oldPos;
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
equals: function equals(left, right) {
|
|
|
|
|
|
return left === right;
|
|
|
|
|
|
},
|
|
|
|
|
|
removeEmpty: function removeEmpty(array) {
|
2015-08-08 00:11:35 +00:00
|
|
|
|
var ret = [];
|
|
|
|
|
|
for (var i = 0; i < array.length; i++) {
|
|
|
|
|
|
if (array[i]) {
|
|
|
|
|
|
ret.push(array[i]);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return ret;
|
2015-10-31 21:55:15 +00:00
|
|
|
|
},
|
|
|
|
|
|
castInput: function castInput(value) {
|
|
|
|
|
|
return value;
|
|
|
|
|
|
},
|
|
|
|
|
|
tokenize: function tokenize(value) {
|
|
|
|
|
|
return value.split('');
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
function buildValues(diff, components, newString, oldString, useLongestToken) {
|
|
|
|
|
|
var componentPos = 0,
|
|
|
|
|
|
componentLen = components.length,
|
|
|
|
|
|
newPos = 0,
|
|
|
|
|
|
oldPos = 0;
|
|
|
|
|
|
|
|
|
|
|
|
for (; componentPos < componentLen; componentPos++) {
|
|
|
|
|
|
var component = components[componentPos];
|
|
|
|
|
|
if (!component.removed) {
|
|
|
|
|
|
if (!component.added && useLongestToken) {
|
|
|
|
|
|
var value = newString.slice(newPos, newPos + component.count);
|
|
|
|
|
|
value = value.map(function (value, i) {
|
|
|
|
|
|
var oldValue = oldString[oldPos + i];
|
|
|
|
|
|
return oldValue.length > value.length ? oldValue : value;
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
component.value = value.join('');
|
|
|
|
|
|
} else {
|
|
|
|
|
|
component.value = newString.slice(newPos, newPos + component.count).join('');
|
|
|
|
|
|
}
|
|
|
|
|
|
newPos += component.count;
|
|
|
|
|
|
|
|
|
|
|
|
// Common case
|
|
|
|
|
|
if (!component.added) {
|
|
|
|
|
|
oldPos += component.count;
|
|
|
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
|
|
|
component.value = oldString.slice(oldPos, oldPos + component.count).join('');
|
|
|
|
|
|
oldPos += component.count;
|
|
|
|
|
|
|
|
|
|
|
|
// Reverse add and remove so removes are output first to match common convention
|
|
|
|
|
|
// The diffing algorithm is tied to add then remove output and this is the simplest
|
|
|
|
|
|
// route to get the desired output with minimal overhead.
|
|
|
|
|
|
if (componentPos && components[componentPos - 1].added) {
|
|
|
|
|
|
var tmp = components[componentPos - 1];
|
|
|
|
|
|
components[componentPos - 1] = components[componentPos];
|
|
|
|
|
|
components[componentPos] = tmp;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2015-08-08 00:11:35 +00:00
|
|
|
|
}
|
2015-10-31 21:55:15 +00:00
|
|
|
|
|
|
|
|
|
|
// Special case handle for when one terminal is ignored. For this case we merge the
|
|
|
|
|
|
// terminal into the prior string and drop the change.
|
|
|
|
|
|
var lastComponent = components[componentLen - 1];
|
|
|
|
|
|
if ((lastComponent.added || lastComponent.removed) && diff.equals('', lastComponent.value)) {
|
|
|
|
|
|
components[componentLen - 2].value += lastComponent.value;
|
|
|
|
|
|
components.pop();
|
2015-08-08 00:11:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2015-10-31 21:55:15 +00:00
|
|
|
|
return components;
|
|
|
|
|
|
}
|
2015-08-08 00:11:35 +00:00
|
|
|
|
|
2015-10-31 21:55:15 +00:00
|
|
|
|
function clonePath(path) {
|
|
|
|
|
|
return { newPos: path.newPos, components: path.components.slice(0) };
|
|
|
|
|
|
}
|
|
|
|
|
|
module.exports = exports['default'];
|
|
|
|
|
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9kaWZmL2Jhc2UuanMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7O3FCQUF3QixJQUFJOztBQUFiLFNBQVMsSUFBSSxHQUFHLEVBQUU7O0FBRWpDLElBQUksQ0FBQyxTQUFTLEdBQUc7QUFDZixNQUFJLEVBQUEsY0FBQyxTQUFTLEVBQUUsU0FBUyxFQUFnQjtRQUFkLE9BQU8seURBQUcsRUFBRTs7QUFDckMsUUFBSSxRQUFRLEdBQUcsT0FBTyxDQUFDLFFBQVEsQ0FBQztBQUNoQyxRQUFJLE9BQU8sT0FBTyxLQUFLLFVBQVUsRUFBRTtBQUNqQyxjQUFRLEdBQUcsT0FBTyxDQUFDO0FBQ25CLGFBQU8sR0FBRyxFQUFFLENBQUM7S0FDZDtBQUNELFFBQUksQ0FBQyxPQUFPLEdBQUcsT0FBTyxDQUFDOztBQUV2QixRQUFJLElBQUksR0FBRyxJQUFJLENBQUM7O0FBRWhCLGFBQVMsSUFBSSxDQUFDLEtBQUssRUFBRTtBQUNuQixVQUFJLFFBQVEsRUFBRTtBQUNaLGtCQUFVLENBQUMsWUFBVztBQUFFLGtCQUFRLENBQUMsU0FBUyxFQUFF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QUFVLEdBQUcsYUFBYSxFQUFFO0FBQzlCLG1CQUFPLFFBQVEsRUFBRSxDQUFDO1dBQ25COztBQUVELGNBQUksQ0FBQyxjQUFjLEVBQUUsRUFBRTtBQUNyQixnQkFBSSxFQUFFLENBQUM7V0FDUjtTQUNGLEVBQUUsQ0FBQyxDQUFDLENBQUM7T0FDUCxDQUFBLEVBQUUsQ0FBRTtLQUNOLE1BQU07QUFDTCxhQUFPLFVBQVUsSUFBSSxhQUFhLEVB
|
2015-08-08 00:11:35 +00:00
|
|
|
|
|
2015-10-31 21:55:15 +00:00
|
|
|
|
|
|
|
|
|
|
/***/ },
|
|
|
|
|
|
/* 7 */
|
|
|
|
|
|
/***/ function(module, exports, __webpack_require__) {
|
|
|
|
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
|
|
exports.__esModule = true;
|
|
|
|
|
|
exports.diffChars = diffChars;
|
|
|
|
|
|
// istanbul ignore next
|
|
|
|
|
|
|
|
|
|
|
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
|
|
|
|
|
|
|
|
|
|
|
|
var _base = __webpack_require__(6);
|
|
|
|
|
|
|
|
|
|
|
|
var _base2 = _interopRequireDefault(_base);
|
|
|
|
|
|
|
|
|
|
|
|
var characterDiff = new _base2['default']();
|
|
|
|
|
|
exports.characterDiff = characterDiff;
|
|
|
|
|
|
|
|
|
|
|
|
function diffChars(oldStr, newStr, callback) {
|
|
|
|
|
|
return characterDiff.diff(oldStr, newStr, callback);
|
|
|
|
|
|
}
|
|
|
|
|
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9kaWZmL2NoYXJhY3Rlci5qcyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7OztvQkFBaUIsUUFBUTs7OztBQUVsQixJQUFNLGFBQWEsR0FBRyx1QkFBVSxDQUFDOzs7QUFDakMsU0FBUyxTQUFTLENBQUMsTUFBTSxFQUFFLE1BQU0sRUFBRSxRQUFRLEVBQUU7QUFBRSxTQUFPLGFBQWEsQ0FBQyxJQUFJLENBQUMsTUFBTSxFQUFFLE1BQU0sRUFBRSxRQUFRLENBQUMsQ0FBQztDQUFFIiwiZmlsZSI6ImNoYXJhY3Rlci5qcyIsInNvdXJjZXNDb250ZW50IjpbImltcG9ydCBEaWZmIGZyb20gJy4vYmFzZSc7XG5cbmV4cG9ydCBjb25zdCBjaGFyYWN0ZXJEaWZmID0gbmV3IERpZmYoKTtcbmV4cG9ydCBmdW5jdGlvbiBkaWZmQ2hhcnMob2xkU3RyLCBuZXdTdHIsIGNhbGxiYWNrKSB7IHJldHVybiBjaGFyYWN0ZXJEaWZmLmRpZmYob2xkU3RyLCBuZXdTdHIsIGNhbGxiYWNrKTsgfVxuIl19
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/***/ },
|
|
|
|
|
|
/* 8 */
|
|
|
|
|
|
/***/ function(module, exports, __webpack_require__) {
|
|
|
|
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
|
|
exports.__esModule = true;
|
|
|
|
|
|
exports.diffWords = diffWords;
|
|
|
|
|
|
exports.diffWordsWithSpace = diffWordsWithSpace;
|
|
|
|
|
|
// istanbul ignore next
|
|
|
|
|
|
|
|
|
|
|
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
|
|
|
|
|
|
|
|
|
|
|
|
var _base = __webpack_require__(6);
|
|
|
|
|
|
|
|
|
|
|
|
var _base2 = _interopRequireDefault(_base);
|
|
|
|
|
|
|
|
|
|
|
|
var _utilParams = __webpack_require__(9);
|
|
|
|
|
|
|
|
|
|
|
|
// Based on https://en.wikipedia.org/wiki/Latin_script_in_Unicode
|
|
|
|
|
|
//
|
|
|
|
|
|
// Ranges and exceptions:
|
|
|
|
|
|
// Latin-1 Supplement, 0080–00FF
|
|
|
|
|
|
// - U+00D7 × Multiplication sign
|
|
|
|
|
|
// - U+00F7 ÷ Division sign
|
|
|
|
|
|
// Latin Extended-A, 0100–017F
|
|
|
|
|
|
// Latin Extended-B, 0180–024F
|
|
|
|
|
|
// IPA Extensions, 0250–02AF
|
|
|
|
|
|
// Spacing Modifier Letters, 02B0–02FF
|
|
|
|
|
|
// - U+02C7 ˇ ˇ Caron
|
|
|
|
|
|
// - U+02D8 ˘ ˘ Breve
|
|
|
|
|
|
// - U+02D9 ˙ ˙ Dot Above
|
|
|
|
|
|
// - U+02DA ˚ ˚ Ring Above
|
|
|
|
|
|
// - U+02DB ˛ ˛ Ogonek
|
|
|
|
|
|
// - U+02DC ˜ ˜ Small Tilde
|
|
|
|
|
|
// - U+02DD ˝ ˝ Double Acute Accent
|
|
|
|
|
|
// Latin Extended Additional, 1E00–1EFF
|
|
|
|
|
|
var extendedWordChars = /^[A-Za-z\xC0-\u02C6\u02C8-\u02D7\u02DE-\u02FF\u1E00-\u1EFF]+$/;
|
|
|
|
|
|
|
|
|
|
|
|
var reWhitespace = /\S/;
|
|
|
|
|
|
|
|
|
|
|
|
var wordDiff = new _base2['default']();
|
|
|
|
|
|
exports.wordDiff = wordDiff;
|
|
|
|
|
|
wordDiff.equals = function (left, right) {
|
|
|
|
|
|
return left === right || this.options.ignoreWhitespace && !reWhitespace.test(left) && !reWhitespace.test(right);
|
|
|
|
|
|
};
|
|
|
|
|
|
wordDiff.tokenize = function (value) {
|
|
|
|
|
|
var tokens = value.split(/(\s+|\b)/);
|
|
|
|
|
|
|
|
|
|
|
|
// Join the boundary splits that we do not consider to be boundaries. This is primarily the extended Latin character set.
|
|
|
|
|
|
for (var i = 0; i < tokens.length - 1; i++) {
|
|
|
|
|
|
// If we have an empty string in the next field and we have only word chars before and after, merge
|
|
|
|
|
|
if (!tokens[i + 1] && tokens[i + 2] && extendedWordChars.test(tokens[i]) && extendedWordChars.test(tokens[i + 2])) {
|
|
|
|
|
|
tokens[i] += tokens[i + 2];
|
|
|
|
|
|
tokens.splice(i + 1, 2);
|
|
|
|
|
|
i--;
|
2015-08-08 00:11:35 +00:00
|
|
|
|
}
|
2015-10-31 21:55:15 +00:00
|
|
|
|
}
|
2015-08-08 00:11:35 +00:00
|
|
|
|
|
2015-10-31 21:55:15 +00:00
|
|
|
|
return tokens;
|
|
|
|
|
|
};
|
2015-08-08 00:11:35 +00:00
|
|
|
|
|
2015-10-31 21:55:15 +00:00
|
|
|
|
function diffWords(oldStr, newStr, callback) {
|
|
|
|
|
|
var options = _utilParams.generateOptions(callback, { ignoreWhitespace: true });
|
|
|
|
|
|
return wordDiff.diff(oldStr, newStr, options);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function diffWordsWithSpace(oldStr, newStr, callback) {
|
|
|
|
|
|
return wordDiff.diff(oldStr, newStr, callback);
|
|
|
|
|
|
}
|
|
|
|
|
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9kaWZmL3dvcmQuanMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7O29CQUFpQixRQUFROzs7OzBCQUNLLGdCQUFnQjs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7QUFvQjlDLElBQU0saUJBQWlCLEdBQUcsK0RBQXFHLENBQUM7O0FBRWhJLElBQU0sWUFBWSxHQUFHLElBQUksQ0FBQzs7QUFFbkIsSUFBTSxRQUFRLEdBQUcsdUJBQVUsQ0FBQzs7QUFDbkMsUUFBUSxDQUFDLE1BQU0sR0FBRyxVQUFTLElBQUksRUFBRSxLQUFLLEVBQUU7QUFDdEMsU0FBTyxJQUFJLEtBQUssS0FBSyxJQUFLLElBQUksQ0FBQyxPQUFPLENBQUMsZ0JBQWdCLElBQUksQ0FBQyxZQUFZLENBQUMsSUFBSSxDQUFDLElBQUksQ0FBQyxJQUFJLENBQUMsWUFBWSxDQUFDLElBQUksQ0FBQyxLQUFLLENBQUMsQUFBQyxDQ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IG9ubHkgd29yZCBjaGFycyBiZWZvcmUgYW5kIGFmdGVyLCBtZXJnZVxuICAgIGlmICghdG9rZW5zW2kgKyAxXSAmJiB0b2tlbnNbaSArIDJdXG4gICAgICAgICAgJiYgZXh0ZW5kZWRXb3JkQ2hhcnMudGVzdCh0b2tlbnNbaV0pXG4gICAgICAgICAgJiYgZXh0ZW5kZWRXb3JkQ2hhcnMudGVzdCh0b2tlbnNbaSArIDJdKSkge1xuICAgICAgdG9rZW5zW2ldICs9IHRva2Vuc1tpICsgMl07XG4gICAgICB0b2tl
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/***/ },
|
|
|
|
|
|
/* 9 */
|
|
|
|
|
|
/***/ function(module, exports) {
|
|
|
|
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
|
|
exports.__esModule = true;
|
|
|
|
|
|
exports.generateOptions = generateOptions;
|
|
|
|
|
|
|
|
|
|
|
|
function generateOptions(options, defaults) {
|
|
|
|
|
|
if (typeof options === 'function') {
|
|
|
|
|
|
defaults.callback = options;
|
|
|
|
|
|
} else if (options) {
|
|
|
|
|
|
for (var _name in options) {
|
|
|
|
|
|
/* istanbul ignore else */
|
|
|
|
|
|
if (options.hasOwnProperty(_name)) {
|
|
|
|
|
|
defaults[_name] = options[_name];
|
2015-08-08 00:11:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2015-10-31 21:55:15 +00:00
|
|
|
|
return defaults;
|
|
|
|
|
|
}
|
|
|
|
|
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy91dGlsL3BhcmFtcy5qcyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7OztBQUFPLFNBQVMsZUFBZSxDQUFDLE9BQU8sRUFBRSxRQUFRLEVBQUU7QUFDakQsTUFBSSxPQUFPLE9BQU8sS0FBSyxVQUFVLEVBQUU7QUFDakMsWUFBUSxDQUFDLFFBQVEsR0FBRyxPQUFPLENBQUM7R0FDN0IsTUFBTSxJQUFJLE9BQU8sRUFBRTtBQUNsQixTQUFLLElBQUksS0FBSSxJQUFJLE9BQU8sRUFBRTs7QUFFeEIsVUFBSSxPQUFPLENBQUMsY0FBYyxDQUFDLEtBQUksQ0FBQyxFQUFFO0FBQ2hDLGdCQUFRLENBQUMsS0FBSSxDQUFDLEdBQUcsT0FBTyxDQUFDLEtBQUksQ0FBQyxDQUFDO09BQ2hDO0tBQ0Y7R0FDRjtBQUNELFNBQU8sUUFBUSxDQUFDO0NBQ2pCIiwiZmlsZSI6InBhcmFtcy5qcyIsInNvdXJjZXNDb250ZW50IjpbImV4cG9ydCBmdW5jdGlvbiBnZW5lcmF0ZU9wdGlvbnMob3B0aW9ucywgZGVmYXVsdHMpIHtcbiAgaWYgKHR5cGVvZiBvcHRpb25zID09PSAnZnVuY3Rpb24nKSB7XG4gICAgZGVmYXVsdHMuY2FsbGJhY2sgPSBvcHRpb25zO1xuICB9IGVsc2UgaWYgKG9wdGlvbnMpIHtcbiAgICBmb3IgKGxldCBuYW1lIGluIG9wdGlvbnMpIHtcbiAgICAgIC8qIGlzdGFuYnVsIGlnbm9yZSBlbHNlICovXG4gICAgICBpZiAob3B0aW9ucy5oYXNPd25Qcm9wZXJ0eShuYW1lKSkge1xuICAgICAgICBkZWZhdWx0c1tuYW1lXSA9IG9wdGlvbnNbbmFtZV07XG4gICAgICB9XG4gICAgfVxuICB9XG4gIHJldHVybiBkZWZhdWx0cztcbn1cbiJdfQ==
|
2015-08-08 00:11:35 +00:00
|
|
|
|
|
|
|
|
|
|
|
2015-10-31 21:55:15 +00:00
|
|
|
|
/***/ },
|
|
|
|
|
|
/* 10 */
|
|
|
|
|
|
/***/ function(module, exports, __webpack_require__) {
|
2015-08-08 00:11:35 +00:00
|
|
|
|
|
2015-10-31 21:55:15 +00:00
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
|
|
exports.__esModule = true;
|
|
|
|
|
|
exports.diffLines = diffLines;
|
|
|
|
|
|
exports.diffTrimmedLines = diffTrimmedLines;
|
|
|
|
|
|
// istanbul ignore next
|
|
|
|
|
|
|
|
|
|
|
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
|
|
|
|
|
|
|
|
|
|
|
|
var _base = __webpack_require__(6);
|
|
|
|
|
|
|
|
|
|
|
|
var _base2 = _interopRequireDefault(_base);
|
|
|
|
|
|
|
|
|
|
|
|
var _utilParams = __webpack_require__(9);
|
|
|
|
|
|
|
|
|
|
|
|
var lineDiff = new _base2['default']();
|
|
|
|
|
|
exports.lineDiff = lineDiff;
|
|
|
|
|
|
lineDiff.tokenize = function (value) {
|
|
|
|
|
|
var retLines = [],
|
|
|
|
|
|
linesAndNewlines = value.split(/(\n|\r\n)/);
|
|
|
|
|
|
|
|
|
|
|
|
// Ignore the final empty token that occurs if the string ends with a new line
|
|
|
|
|
|
if (!linesAndNewlines[linesAndNewlines.length - 1]) {
|
|
|
|
|
|
linesAndNewlines.pop();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Merge the content and line separators into single tokens
|
|
|
|
|
|
for (var i = 0; i < linesAndNewlines.length; i++) {
|
|
|
|
|
|
var line = linesAndNewlines[i];
|
|
|
|
|
|
|
|
|
|
|
|
if (i % 2 && !this.options.newlineIsToken) {
|
|
|
|
|
|
retLines[retLines.length - 1] += line;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
if (this.options.ignoreWhitespace) {
|
|
|
|
|
|
line = line.trim();
|
2015-08-08 00:11:35 +00:00
|
|
|
|
}
|
2015-10-31 21:55:15 +00:00
|
|
|
|
retLines.push(line);
|
2015-08-08 00:11:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2015-10-31 21:55:15 +00:00
|
|
|
|
return retLines;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
function diffLines(oldStr, newStr, callback) {
|
|
|
|
|
|
return lineDiff.diff(oldStr, newStr, callback);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function diffTrimmedLines(oldStr, newStr, callback) {
|
|
|
|
|
|
var options = _utilParams.generateOptions(callback, { ignoreWhitespace: true });
|
|
|
|
|
|
return lineDiff.diff(oldStr, newStr, options);
|
|
|
|
|
|
}
|
|
|
|
|
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9kaWZmL2xpbmUuanMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7O29CQUFpQixRQUFROzs7OzBCQUNLLGdCQUFnQjs7QUFFdkMsSUFBTSxRQUFRLEdBQUcsdUJBQVUsQ0FBQzs7QUFDbkMsUUFBUSxDQUFDLFFBQVEsR0FBRyxVQUFTLEtBQUssRUFBRTtBQUNsQyxNQUFJLFFBQVEsR0FBRyxFQUFFO01BQ2IsZ0JBQWdCLEdBQUcsS0FBSyxDQUFDLEtBQUssQ0FBQyxXQUFXLENBQUMsQ0FBQzs7O0FBR2hELE1BQUksQ0FBQyxnQkFBZ0IsQ0FBQyxnQkFBZ0IsQ0FBQyxNQUFNLEdBQUcsQ0FBQyxDQUFDLEVBQUU7QUFDbEQsb0JBQWdCLENBQUMsR0FBRyxFQUFFLENBQUM7R0FDeEI7OztBQUdELE9BQUssSUFBSSxDQUFDLEdBQUcsQ0FBQyxFQUFFLENBQUMsR0FBRyxnQkFBZ0IsQ0FBQyxNQUFNLEVBQUUsQ0FBQyxFQUFFLEVBQUU7QUFDaEQsUUFBSSxJQUFJLEdBQUcsZ0JBQWdCLENBQUMsQ0FBQyxDQUFDLENBQUM7O0FBRS9CLFFBQUksQ0FBQyxHQUFHLENBQUMsSUFBSSxDQUFDLElBQUksQ0FBQyxPQUFPLENBQUMsY0FBYyxFQUFFO0FBQ3pDLGNBQVEsQ0FBQyxRQUFRLENBQUMsTUFBTSx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pZ25vcmVXaGl0ZXNwYWNlOiB0cnVlfSk7XG4gIHJldHVybiBsaW5lRGlmZi5kaWZmKG9sZFN0ciwgbmV3U3RyLCBvcHRpb25zKTtcbn1cbiJdfQ==
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/***/ },
|
|
|
|
|
|
/* 11 */
|
|
|
|
|
|
/***/ function(module, exports, __webpack_require__) {
|
|
|
|
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
|
|
exports.__esModule = true;
|
|
|
|
|
|
exports.diffSentences = diffSentences;
|
|
|
|
|
|
// istanbul ignore next
|
|
|
|
|
|
|
|
|
|
|
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
|
|
|
|
|
|
|
|
|
|
|
|
var _base = __webpack_require__(6);
|
|
|
|
|
|
|
|
|
|
|
|
var _base2 = _interopRequireDefault(_base);
|
|
|
|
|
|
|
|
|
|
|
|
var sentenceDiff = new _base2['default']();
|
|
|
|
|
|
exports.sentenceDiff = sentenceDiff;
|
|
|
|
|
|
sentenceDiff.tokenize = function (value) {
|
|
|
|
|
|
return value.split(/(\S.+?[.!?])(?=\s+|$)/);
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
function diffSentences(oldStr, newStr, callback) {
|
|
|
|
|
|
return sentenceDiff.diff(oldStr, newStr, callback);
|
|
|
|
|
|
}
|
|
|
|
|
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9kaWZmL3NlbnRlbmNlLmpzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7Ozs7O29CQUFpQixRQUFROzs7O0FBR2xCLElBQU0sWUFBWSxHQUFHLHVCQUFVLENBQUM7O0FBQ3ZDLFlBQVksQ0FBQyxRQUFRLEdBQUcsVUFBUyxLQUFLLEVBQUU7QUFDdEMsU0FBTyxLQUFLLENBQUMsS0FBSyxDQUFDLHVCQUF1QixDQUFDLENBQUM7Q0FDN0MsQ0FBQzs7QUFFSyxTQUFTLGFBQWEsQ0FBQyxNQUFNLEVBQUUsTUFBTSxFQUFFLFFBQVEsRUFBRTtBQUFFLFNBQU8sWUFBWSxDQUFDLElBQUksQ0FBQyxNQUFNLEVBQUUsTUFBTSxFQUFFLFFBQVEsQ0FBQyxDQUFDO0NBQUUiLCJmaWxlIjoic2VudGVuY2UuanMiLCJzb3VyY2VzQ29udGVudCI6WyJpbXBvcnQgRGlmZiBmcm9tICcuL2Jhc2UnO1xuXG5cbmV4cG9ydCBjb25zdCBzZW50ZW5jZURpZmYgPSBuZXcgRGlmZigpO1xuc2VudGVuY2VEaWZmLnRva2VuaXplID0gZnVuY3Rpb24odmFsdWUpIHtcbiAgcmV0dXJuIHZhbHVlLnNwbGl0KC8oXFxTLis/Wy4hP10pKD89XFxzK3wkKS8pO1xufTtcblxuZXhwb3J0IGZ1bmN0aW9uIGRpZmZTZW50ZW5jZXMob2xkU3RyLCBuZXdTdHIsIGNhbGxiYWNrKSB7IHJldHVybiBzZW50ZW5jZURpZmYuZGlmZihvbGRTdHIsIG5ld1N0ciwgY2FsbGJhY2spOyB9XG4iXX0=
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/***/ },
|
|
|
|
|
|
/* 12 */
|
|
|
|
|
|
/***/ function(module, exports, __webpack_require__) {
|
|
|
|
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
|
|
exports.__esModule = true;
|
|
|
|
|
|
exports.diffCss = diffCss;
|
|
|
|
|
|
// istanbul ignore next
|
|
|
|
|
|
|
|
|
|
|
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
|
|
|
|
|
|
|
|
|
|
|
|
var _base = __webpack_require__(6);
|
|
|
|
|
|
|
|
|
|
|
|
var _base2 = _interopRequireDefault(_base);
|
|
|
|
|
|
|
|
|
|
|
|
var cssDiff = new _base2['default']();
|
|
|
|
|
|
exports.cssDiff = cssDiff;
|
|
|
|
|
|
cssDiff.tokenize = function (value) {
|
|
|
|
|
|
return value.split(/([{}:;,]|\s+)/);
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
function diffCss(oldStr, newStr, callback) {
|
|
|
|
|
|
return cssDiff.diff(oldStr, newStr, callback);
|
|
|
|
|
|
}
|
|
|
|
|
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9kaWZmL2Nzcy5qcyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7OztvQkFBaUIsUUFBUTs7OztBQUVsQixJQUFNLE9BQU8sR0FBRyx1QkFBVSxDQUFDOztBQUNsQyxPQUFPLENBQUMsUUFBUSxHQUFHLFVBQVMsS0FBSyxFQUFFO0FBQ2pDLFNBQU8sS0FBSyxDQUFDLEtBQUssQ0FBQyxlQUFlLENBQUMsQ0FBQztDQUNyQyxDQUFDOztBQUVLLFNBQVMsT0FBTyxDQUFDLE1BQU0sRUFBRSxNQUFNLEVBQUUsUUFBUSxFQUFFO0FBQUUsU0FBTyxPQUFPLENBQUMsSUFBSSxDQUFDLE1BQU0sRUFBRSxNQUFNLEVBQUUsUUFBUSxDQUFDLENBQUM7Q0FBRSIsImZpbGUiOiJjc3MuanMiLCJzb3VyY2VzQ29udGVudCI6WyJpbXBvcnQgRGlmZiBmcm9tICcuL2Jhc2UnO1xuXG5leHBvcnQgY29uc3QgY3NzRGlmZiA9IG5ldyBEaWZmKCk7XG5jc3NEaWZmLnRva2VuaXplID0gZnVuY3Rpb24odmFsdWUpIHtcbiAgcmV0dXJuIHZhbHVlLnNwbGl0KC8oW3t9OjssXXxcXHMrKS8pO1xufTtcblxuZXhwb3J0IGZ1bmN0aW9uIGRpZmZDc3Mob2xkU3RyLCBuZXdTdHIsIGNhbGxiYWNrKSB7IHJldHVybiBjc3NEaWZmLmRpZmYob2xkU3RyLCBuZXdTdHIsIGNhbGxiYWNrKTsgfVxuIl19
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/***/ },
|
|
|
|
|
|
/* 13 */
|
|
|
|
|
|
/***/ function(module, exports, __webpack_require__) {
|
|
|
|
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
|
|
exports.__esModule = true;
|
|
|
|
|
|
exports.diffJson = diffJson;
|
|
|
|
|
|
exports.canonicalize = canonicalize;
|
|
|
|
|
|
// istanbul ignore next
|
|
|
|
|
|
|
|
|
|
|
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
|
|
|
|
|
|
|
|
|
|
|
|
var _base = __webpack_require__(6);
|
|
|
|
|
|
|
|
|
|
|
|
var _base2 = _interopRequireDefault(_base);
|
|
|
|
|
|
|
|
|
|
|
|
var _line = __webpack_require__(10);
|
|
|
|
|
|
|
|
|
|
|
|
var objectPrototypeToString = Object.prototype.toString;
|
|
|
|
|
|
|
|
|
|
|
|
var jsonDiff = new _base2['default']();
|
|
|
|
|
|
exports.jsonDiff = jsonDiff;
|
|
|
|
|
|
// Discriminate between two lines of pretty-printed, serialized JSON where one of them has a
|
|
|
|
|
|
// dangling comma and the other doesn't. Turns out including the dangling comma yields the nicest output:
|
|
|
|
|
|
jsonDiff.useLongestToken = true;
|
|
|
|
|
|
|
|
|
|
|
|
jsonDiff.tokenize = _line.lineDiff.tokenize;
|
|
|
|
|
|
jsonDiff.castInput = function (value) {
|
|
|
|
|
|
return typeof value === 'string' ? value : JSON.stringify(canonicalize(value), undefined, ' ');
|
|
|
|
|
|
};
|
|
|
|
|
|
jsonDiff.equals = function (left, right) {
|
|
|
|
|
|
return _base2['default'].prototype.equals(left.replace(/,([\r\n])/g, '$1'), right.replace(/,([\r\n])/g, '$1'));
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
function diffJson(oldObj, newObj, callback) {
|
|
|
|
|
|
return jsonDiff.diff(oldObj, newObj, callback);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// This function handles the presence of circular references by bailing out when encountering an
|
|
|
|
|
|
// object that is already on the "stack" of items being processed.
|
|
|
|
|
|
|
|
|
|
|
|
function canonicalize(obj, stack, replacementStack) {
|
|
|
|
|
|
stack = stack || [];
|
|
|
|
|
|
replacementStack = replacementStack || [];
|
|
|
|
|
|
|
|
|
|
|
|
var i = undefined;
|
|
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < stack.length; i += 1) {
|
|
|
|
|
|
if (stack[i] === obj) {
|
|
|
|
|
|
return replacementStack[i];
|
|
|
|
|
|
}
|
2015-08-08 00:11:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2015-10-31 21:55:15 +00:00
|
|
|
|
var canonicalizedObj = undefined;
|
|
|
|
|
|
|
|
|
|
|
|
if ('[object Array]' === objectPrototypeToString.call(obj)) {
|
|
|
|
|
|
stack.push(obj);
|
|
|
|
|
|
canonicalizedObj = new Array(obj.length);
|
|
|
|
|
|
replacementStack.push(canonicalizedObj);
|
|
|
|
|
|
for (i = 0; i < obj.length; i += 1) {
|
|
|
|
|
|
canonicalizedObj[i] = canonicalize(obj[i], stack, replacementStack);
|
|
|
|
|
|
}
|
|
|
|
|
|
stack.pop();
|
|
|
|
|
|
replacementStack.pop();
|
|
|
|
|
|
} else if (typeof obj === 'object' && obj !== null) {
|
|
|
|
|
|
stack.push(obj);
|
|
|
|
|
|
canonicalizedObj = {};
|
|
|
|
|
|
replacementStack.push(canonicalizedObj);
|
|
|
|
|
|
var sortedKeys = [],
|
|
|
|
|
|
key = undefined;
|
|
|
|
|
|
for (key in obj) {
|
|
|
|
|
|
/* istanbul ignore else */
|
|
|
|
|
|
if (obj.hasOwnProperty(key)) {
|
|
|
|
|
|
sortedKeys.push(key);
|
2015-08-08 00:11:35 +00:00
|
|
|
|
}
|
2015-10-31 21:55:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
sortedKeys.sort();
|
|
|
|
|
|
for (i = 0; i < sortedKeys.length; i += 1) {
|
|
|
|
|
|
key = sortedKeys[i];
|
|
|
|
|
|
canonicalizedObj[key] = canonicalize(obj[key], stack, replacementStack);
|
|
|
|
|
|
}
|
|
|
|
|
|
stack.pop();
|
|
|
|
|
|
replacementStack.pop();
|
|
|
|
|
|
} else {
|
|
|
|
|
|
canonicalizedObj = obj;
|
|
|
|
|
|
}
|
|
|
|
|
|
return canonicalizedObj;
|
|
|
|
|
|
}
|
|
|
|
|
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9kaWZmL2pzb24uanMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7O29CQUFpQixRQUFROzs7O29CQUNGLFFBQVE7O0FBRS9CLElBQU0sdUJBQXVCLEdBQUcsTUFBTSxDQUFDLFNBQVMsQ0FBQyxRQUFRLENBQUM7O0FBR25ELElBQU0sUUFBUSxHQUFHLHVCQUFVLENBQUM7Ozs7QUFHbkMsUUFBUSxDQUFDLGVBQWUsR0FBRyxJQUFJLENBQUM7O0FBRWhDLFFBQVEsQ0FBQyxRQUFRLEdBQUcsZUFBUyxRQUFRLENBQUM7QUFDdEMsUUFBUSxDQUFDLFNBQVMsR0FBRyxVQUFTLEtBQUssRUFBRTtBQUNuQyxTQUFPLE9BQU8sS0FBSyxLQUFLLFFBQVEsR0FBRyxLQUFLLEdBQUcsSUFBSSxDQUFDLFNBQVMsQ0FBQyxZQUFZLENBQUMsS0FBSyxDQUFDLEVBQUUsU0FBUyxFQUFFLElBQUksQ0FBQyxDQUFDO0NBQ2pHLENBQUM7QUFDRixRQUFRLENBQUMsTUFBTSxHQUFHLFVBQVMsSUFBSSxFQUFFLEtBQUssRUFBRTtBQUN0QyxTQUFPLGtCQUFLLFNBQVMsQ0FBQyxNQUFNLENBQUMsSUFBSSxDQUFDLE9BQU8sQ0FBQyxZQUFZLEVBQUUsSUFBSSxDQUFD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7XG59O1xuanNvbkRpZmYuZXF1YWxzID0gZnVuY3Rpb24obGVmdCwgcmlnaHQpIHtcbiAgcmV0dXJuIERpZmYucHJvdG90eXBlLmVxdWFscyhsZWZ0LnJlcGxhY2UoLywoW1xcclxcbl0pL2cs
|
2015-08-08 00:11:35 +00:00
|
|
|
|
|
|
|
|
|
|
|
2015-10-31 21:55:15 +00:00
|
|
|
|
/***/ },
|
|
|
|
|
|
/* 14 */
|
|
|
|
|
|
/***/ function(module, exports, __webpack_require__) {
|
2015-08-08 00:11:35 +00:00
|
|
|
|
|
2015-10-31 21:55:15 +00:00
|
|
|
|
'use strict';
|
2015-08-08 00:11:35 +00:00
|
|
|
|
|
2015-10-31 21:55:15 +00:00
|
|
|
|
exports.__esModule = true;
|
|
|
|
|
|
exports.applyPatch = applyPatch;
|
|
|
|
|
|
exports.applyPatches = applyPatches;
|
|
|
|
|
|
// istanbul ignore next
|
2015-08-08 00:11:35 +00:00
|
|
|
|
|
2015-10-31 21:55:15 +00:00
|
|
|
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
|
2015-08-08 00:11:35 +00:00
|
|
|
|
|
2015-10-31 21:55:15 +00:00
|
|
|
|
var _parse = __webpack_require__(15);
|
2015-08-08 00:11:35 +00:00
|
|
|
|
|
2015-10-31 21:55:15 +00:00
|
|
|
|
var _utilDistanceIterator = __webpack_require__(16);
|
2015-08-08 00:11:35 +00:00
|
|
|
|
|
2015-10-31 21:55:15 +00:00
|
|
|
|
var _utilDistanceIterator2 = _interopRequireDefault(_utilDistanceIterator);
|
|
|
|
|
|
|
|
|
|
|
|
function applyPatch(source, uniDiff) {
|
|
|
|
|
|
var options = arguments.length <= 2 || arguments[2] === undefined ? {} : arguments[2];
|
|
|
|
|
|
|
|
|
|
|
|
if (typeof uniDiff === 'string') {
|
|
|
|
|
|
uniDiff = _parse.parsePatch(uniDiff);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (Array.isArray(uniDiff)) {
|
|
|
|
|
|
if (uniDiff.length > 1) {
|
|
|
|
|
|
throw new Error('applyPatch only works with a single input.');
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
uniDiff = uniDiff[0];
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Apply the diff to the input
|
|
|
|
|
|
var lines = source.split('\n'),
|
|
|
|
|
|
hunks = uniDiff.hunks,
|
|
|
|
|
|
compareLine = options.compareLine || function (lineNumber, line, operation, patchContent) {
|
|
|
|
|
|
return line === patchContent;
|
|
|
|
|
|
},
|
|
|
|
|
|
errorCount = 0,
|
|
|
|
|
|
fuzzFactor = options.fuzzFactor || 0,
|
|
|
|
|
|
minLine = 0,
|
|
|
|
|
|
offset = 0,
|
|
|
|
|
|
removeEOFNL = undefined,
|
|
|
|
|
|
addEOFNL = undefined;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Checks if the hunk exactly fits on the provided location
|
|
|
|
|
|
*/
|
|
|
|
|
|
function hunkFits(hunk, toPos) {
|
|
|
|
|
|
for (var j = 0; j < hunk.lines.length; j++) {
|
|
|
|
|
|
var line = hunk.lines[j],
|
|
|
|
|
|
operation = line[0],
|
|
|
|
|
|
content = line.substr(1);
|
|
|
|
|
|
|
|
|
|
|
|
if (operation === ' ' || operation === '-') {
|
|
|
|
|
|
// Context sanity check
|
|
|
|
|
|
if (!compareLine(toPos + 1, lines[toPos], operation, content)) {
|
|
|
|
|
|
errorCount++;
|
|
|
|
|
|
|
|
|
|
|
|
if (errorCount > fuzzFactor) {
|
|
|
|
|
|
return false;
|
2015-08-08 00:11:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2015-10-31 21:55:15 +00:00
|
|
|
|
toPos++;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Search best fit offsets for each hunk based on the previous ones
|
|
|
|
|
|
for (var i = 0; i < hunks.length; i++) {
|
|
|
|
|
|
var hunk = hunks[i],
|
|
|
|
|
|
maxLine = lines.length - hunk.oldLines,
|
|
|
|
|
|
localOffset = 0,
|
|
|
|
|
|
toPos = offset + hunk.oldStart - 1;
|
|
|
|
|
|
|
|
|
|
|
|
var iterator = _utilDistanceIterator2['default'](toPos, minLine, maxLine);
|
2015-08-08 00:11:35 +00:00
|
|
|
|
|
2015-10-31 21:55:15 +00:00
|
|
|
|
for (; localOffset !== undefined; localOffset = iterator()) {
|
|
|
|
|
|
if (hunkFits(hunk, toPos + localOffset)) {
|
|
|
|
|
|
hunk.offset = offset += localOffset;
|
|
|
|
|
|
break;
|
2015-08-08 00:11:35 +00:00
|
|
|
|
}
|
2015-10-31 21:55:15 +00:00
|
|
|
|
}
|
2015-08-08 00:11:35 +00:00
|
|
|
|
|
2015-10-31 21:55:15 +00:00
|
|
|
|
if (localOffset === undefined) {
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
2015-08-08 00:11:35 +00:00
|
|
|
|
|
2015-10-31 21:55:15 +00:00
|
|
|
|
// Set lower text limit to end of the current hunk, so next ones don't try
|
|
|
|
|
|
// to fit over already patched text
|
|
|
|
|
|
minLine = hunk.offset + hunk.oldStart + hunk.oldLines;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Apply patch hunks
|
|
|
|
|
|
for (var i = 0; i < hunks.length; i++) {
|
|
|
|
|
|
var hunk = hunks[i],
|
|
|
|
|
|
toPos = hunk.offset + hunk.newStart - 1;
|
|
|
|
|
|
|
|
|
|
|
|
for (var j = 0; j < hunk.lines.length; j++) {
|
|
|
|
|
|
var line = hunk.lines[j],
|
|
|
|
|
|
operation = line[0],
|
|
|
|
|
|
content = line.substr(1);
|
|
|
|
|
|
|
|
|
|
|
|
if (operation === ' ') {
|
|
|
|
|
|
toPos++;
|
|
|
|
|
|
} else if (operation === '-') {
|
|
|
|
|
|
lines.splice(toPos, 1);
|
|
|
|
|
|
/* istanbul ignore else */
|
|
|
|
|
|
} else if (operation === '+') {
|
|
|
|
|
|
lines.splice(toPos, 0, content);
|
|
|
|
|
|
toPos++;
|
|
|
|
|
|
} else if (operation === '\\') {
|
|
|
|
|
|
var previousOperation = hunk.lines[j - 1] ? hunk.lines[j - 1][0] : null;
|
|
|
|
|
|
if (previousOperation === '+') {
|
|
|
|
|
|
removeEOFNL = true;
|
|
|
|
|
|
} else if (previousOperation === '-') {
|
|
|
|
|
|
addEOFNL = true;
|
2015-08-08 00:11:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2015-10-31 21:55:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2015-08-08 00:11:35 +00:00
|
|
|
|
|
2015-10-31 21:55:15 +00:00
|
|
|
|
// Handle EOFNL insertion/removal
|
|
|
|
|
|
if (removeEOFNL) {
|
|
|
|
|
|
while (!lines[lines.length - 1]) {
|
|
|
|
|
|
lines.pop();
|
|
|
|
|
|
}
|
|
|
|
|
|
} else if (addEOFNL) {
|
|
|
|
|
|
lines.push('');
|
|
|
|
|
|
}
|
|
|
|
|
|
return lines.join('\n');
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Wrapper that supports multiple file patches via callbacks.
|
2015-08-08 00:11:35 +00:00
|
|
|
|
|
2015-10-31 21:55:15 +00:00
|
|
|
|
function applyPatches(uniDiff, options) {
|
|
|
|
|
|
if (typeof uniDiff === 'string') {
|
|
|
|
|
|
uniDiff = _parse.parsePatch(uniDiff);
|
|
|
|
|
|
}
|
2015-08-08 00:11:35 +00:00
|
|
|
|
|
2015-10-31 21:55:15 +00:00
|
|
|
|
var currentIndex = 0;
|
|
|
|
|
|
function processIndex() {
|
|
|
|
|
|
var index = uniDiff[currentIndex++];
|
|
|
|
|
|
if (!index) {
|
|
|
|
|
|
return options.complete();
|
2015-08-08 00:11:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2015-10-31 21:55:15 +00:00
|
|
|
|
options.loadFile(index, function (err, data) {
|
|
|
|
|
|
if (err) {
|
|
|
|
|
|
return options.complete(err);
|
|
|
|
|
|
}
|
2015-08-08 00:11:35 +00:00
|
|
|
|
|
2015-10-31 21:55:15 +00:00
|
|
|
|
var updatedContent = applyPatch(data, index, options);
|
|
|
|
|
|
options.patched(index, updatedContent);
|
|
|
|
|
|
|
|
|
|
|
|
setTimeout(processIndex, 0);
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
processIndex();
|
|
|
|
|
|
}
|
|
|
|
|
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9wYXRjaC9hcHBseS5qcyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7cUJBQXlCLFNBQVM7O29DQUNMLDJCQUEyQjs7OztBQUVqRCxTQUFTLFVBQVUsQ0FBQyxNQUFNLEVBQUUsT0FBTyxFQUFnQjtNQUFkLE9BQU8seURBQUcsRUFBRTs7QUFDdEQsTUFBSSxPQUFPLE9BQU8sS0FBSyxRQUFRLEVBQUU7QUFDL0IsV0FBTyxHQUFHLGtCQUFXLE9BQU8sQ0FBQyxDQUFDO0dBQy9COztBQUVELE1BQUksS0FBSyxDQUFDLE9BQU8sQ0FBQyxPQUFPLENBQUMsRUFBRTtBQUMxQixRQUFJLE9BQU8sQ0FBQyxNQUFNLEdBQUcsQ0FBQyxFQUFFO0FBQ3RCLFlBQU0sSUFBSSxLQUFLLENBQUMsNENBQTRDLENBQUMsQ0FBQztLQUMvRDs7QUFFRCxXQUFPLEdBQUcsT0FBTyxDQUFDLENBQUMsQ0FBQyxDQUFDO0dBQ3RCOzs7QUFHRCxNQUFJLEtBQUssR0FBRyxNQUFNLENBQUMsS0FBSyxDQUFDLElBQUksQ0FBQztNQUMxQixLQUFLLEdBQUcsT0FBTyxDQUFDLEtBQUs7TUFFckIsV0FBVyxHQUFHLE9BQU8sQ0FBQy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QixLQUFLLEdBQUcsRUFBRTtBQUNwQyxvQkFBUSxHQUFHLElBQUksQ0FBQztXQUNqQjtTQUNGO0tBQ0Y7R0FDRjs7O0FBR0QsTUFBSSxXQUFXLEVBQUU7QUFDZixXQUFPLENBQUMsS0FBSyxDQUFDLEtBQUssQ0FBQyxNQUFNLEdBQUcsQ0FBQyxDQUFD
|
2015-08-08 00:11:35 +00:00
|
|
|
|
|
|
|
|
|
|
|
2015-10-31 21:55:15 +00:00
|
|
|
|
/***/ },
|
|
|
|
|
|
/* 15 */
|
|
|
|
|
|
/***/ function(module, exports) {
|
2015-08-08 00:11:35 +00:00
|
|
|
|
|
2015-10-31 21:55:15 +00:00
|
|
|
|
'use strict';
|
2015-08-08 00:11:35 +00:00
|
|
|
|
|
2015-10-31 21:55:15 +00:00
|
|
|
|
exports.__esModule = true;
|
|
|
|
|
|
exports.parsePatch = parsePatch;
|
2015-08-08 00:11:35 +00:00
|
|
|
|
|
2015-10-31 21:55:15 +00:00
|
|
|
|
function parsePatch(uniDiff) {
|
|
|
|
|
|
var options = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1];
|
|
|
|
|
|
|
|
|
|
|
|
var diffstr = uniDiff.split('\n'),
|
|
|
|
|
|
list = [],
|
|
|
|
|
|
i = 0;
|
|
|
|
|
|
|
|
|
|
|
|
function parseIndex() {
|
|
|
|
|
|
var index = {};
|
|
|
|
|
|
list.push(index);
|
|
|
|
|
|
|
2015-12-19 21:09:31 +00:00
|
|
|
|
// Parse diff metadata
|
2015-10-31 21:55:15 +00:00
|
|
|
|
while (i < diffstr.length) {
|
2015-12-19 21:09:31 +00:00
|
|
|
|
var line = diffstr[i];
|
|
|
|
|
|
|
|
|
|
|
|
// File header found, end parsing diff metadata
|
|
|
|
|
|
if (/^(\-\-\-|\+\+\+|@@)\s/.test(line)) {
|
2015-10-31 21:55:15 +00:00
|
|
|
|
break;
|
2015-08-08 00:11:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2015-12-19 21:09:31 +00:00
|
|
|
|
// Diff index
|
|
|
|
|
|
var header = /^(?:Index:|diff(?: -r \w+)+)\s+(.+?)\s*$/.exec(line);
|
|
|
|
|
|
if (header) {
|
|
|
|
|
|
index.index = header[1];
|
2015-10-31 21:55:15 +00:00
|
|
|
|
}
|
2015-08-08 00:11:35 +00:00
|
|
|
|
|
2015-12-19 21:09:31 +00:00
|
|
|
|
i++;
|
2015-08-08 00:11:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2015-12-19 21:09:31 +00:00
|
|
|
|
// Parse file headers if they are defined. Unified diff requires them, but
|
|
|
|
|
|
// there's no technical issues to have an isolated hunk without file header
|
|
|
|
|
|
parseFileHeader(index);
|
|
|
|
|
|
parseFileHeader(index);
|
|
|
|
|
|
|
|
|
|
|
|
// Parse hunks
|
2015-10-31 21:55:15 +00:00
|
|
|
|
index.hunks = [];
|
2015-08-08 00:11:35 +00:00
|
|
|
|
|
2015-10-31 21:55:15 +00:00
|
|
|
|
while (i < diffstr.length) {
|
2015-12-19 21:09:31 +00:00
|
|
|
|
var line = diffstr[i];
|
|
|
|
|
|
|
|
|
|
|
|
if (/^(Index:|diff|\-\-\-|\+\+\+)\s/.test(line)) {
|
2015-10-31 21:55:15 +00:00
|
|
|
|
break;
|
2015-12-19 21:09:31 +00:00
|
|
|
|
} else if (/^@@/.test(line)) {
|
2015-10-31 21:55:15 +00:00
|
|
|
|
index.hunks.push(parseHunk());
|
2015-12-19 21:09:31 +00:00
|
|
|
|
} else if (line && options.strict) {
|
2015-10-31 21:55:15 +00:00
|
|
|
|
// Ignore unexpected content unless in strict mode
|
2015-12-19 21:09:31 +00:00
|
|
|
|
throw new Error('Unknown line ' + (i + 1) + ' ' + JSON.stringify(line));
|
2015-08-08 00:11:35 +00:00
|
|
|
|
} else {
|
2015-10-31 21:55:15 +00:00
|
|
|
|
i++;
|
2015-08-08 00:11:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2015-10-31 21:55:15 +00:00
|
|
|
|
}
|
2015-08-08 00:11:35 +00:00
|
|
|
|
|
2015-10-31 21:55:15 +00:00
|
|
|
|
// Parses the --- and +++ headers, if none are found, no lines
|
|
|
|
|
|
// are consumed.
|
|
|
|
|
|
function parseFileHeader(index) {
|
2015-12-19 21:09:31 +00:00
|
|
|
|
var fileHeader = /^(\-\-\-|\+\+\+)\s+(\S+)\s?(.+?)\s*$/.exec(diffstr[i]);
|
2015-10-31 21:55:15 +00:00
|
|
|
|
if (fileHeader) {
|
|
|
|
|
|
var keyPrefix = fileHeader[1] === '---' ? 'old' : 'new';
|
|
|
|
|
|
index[keyPrefix + 'FileName'] = fileHeader[2];
|
|
|
|
|
|
index[keyPrefix + 'Header'] = fileHeader[3];
|
2015-08-08 00:11:35 +00:00
|
|
|
|
|
2015-10-31 21:55:15 +00:00
|
|
|
|
i++;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2015-08-08 00:11:35 +00:00
|
|
|
|
|
2015-10-31 21:55:15 +00:00
|
|
|
|
// Parses a hunk
|
|
|
|
|
|
// This assumes that we are at the start of a hunk.
|
|
|
|
|
|
function parseHunk() {
|
|
|
|
|
|
var chunkHeaderIndex = i,
|
|
|
|
|
|
chunkHeaderLine = diffstr[i++],
|
|
|
|
|
|
chunkHeader = chunkHeaderLine.split(/@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@/);
|
|
|
|
|
|
|
|
|
|
|
|
var hunk = {
|
|
|
|
|
|
oldStart: +chunkHeader[1],
|
|
|
|
|
|
oldLines: +chunkHeader[2] || 1,
|
|
|
|
|
|
newStart: +chunkHeader[3],
|
|
|
|
|
|
newLines: +chunkHeader[4] || 1,
|
|
|
|
|
|
lines: []
|
|
|
|
|
|
};
|
2015-08-08 00:11:35 +00:00
|
|
|
|
|
2015-10-31 21:55:15 +00:00
|
|
|
|
var addCount = 0,
|
|
|
|
|
|
removeCount = 0;
|
|
|
|
|
|
for (; i < diffstr.length; i++) {
|
|
|
|
|
|
var operation = diffstr[i][0];
|
|
|
|
|
|
|
|
|
|
|
|
if (operation === '+' || operation === '-' || operation === ' ' || operation === '\\') {
|
|
|
|
|
|
hunk.lines.push(diffstr[i]);
|
|
|
|
|
|
|
|
|
|
|
|
if (operation === '+') {
|
|
|
|
|
|
addCount++;
|
|
|
|
|
|
} else if (operation === '-') {
|
|
|
|
|
|
removeCount++;
|
|
|
|
|
|
} else if (operation === ' ') {
|
|
|
|
|
|
addCount++;
|
|
|
|
|
|
removeCount++;
|
|
|
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2015-08-08 00:11:35 +00:00
|
|
|
|
|
2015-10-31 21:55:15 +00:00
|
|
|
|
// Handle the empty block count case
|
|
|
|
|
|
if (!addCount && hunk.newLines === 1) {
|
|
|
|
|
|
hunk.newLines = 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (!removeCount && hunk.oldLines === 1) {
|
|
|
|
|
|
hunk.oldLines = 0;
|
|
|
|
|
|
}
|
2015-08-08 00:11:35 +00:00
|
|
|
|
|
2015-10-31 21:55:15 +00:00
|
|
|
|
// Perform optional sanity checking
|
|
|
|
|
|
if (options.strict) {
|
|
|
|
|
|
if (addCount !== hunk.newLines) {
|
|
|
|
|
|
throw new Error('Added line count did not match for hunk at line ' + (chunkHeaderIndex + 1));
|
|
|
|
|
|
}
|
|
|
|
|
|
if (removeCount !== hunk.oldLines) {
|
|
|
|
|
|
throw new Error('Removed line count did not match for hunk at line ' + (chunkHeaderIndex + 1));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2015-08-08 00:11:35 +00:00
|
|
|
|
|
2015-10-31 21:55:15 +00:00
|
|
|
|
return hunk;
|
|
|
|
|
|
}
|
2015-08-08 00:11:35 +00:00
|
|
|
|
|
2015-10-31 21:55:15 +00:00
|
|
|
|
while (i < diffstr.length) {
|
|
|
|
|
|
parseIndex();
|
|
|
|
|
|
}
|
2015-08-08 00:11:35 +00:00
|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2015-10-31 21:55:15 +00:00
|
|
|
|
/***/ },
|
|
|
|
|
|
/* 16 */
|
|
|
|
|
|
/***/ function(module, exports) {
|
2015-08-08 00:11:35 +00:00
|
|
|
|
|
2015-10-31 21:55:15 +00:00
|
|
|
|
// Iterator that traverses in the range of [min, max], stepping
|
|
|
|
|
|
// by distance from a given start position. I.e. for [0, 4], with
|
|
|
|
|
|
"use strict";
|
2015-08-08 00:11:35 +00:00
|
|
|
|
|
2015-10-31 21:55:15 +00:00
|
|
|
|
exports.__esModule = true;
|
2015-08-08 00:11:35 +00:00
|
|
|
|
|
2015-10-31 21:55:15 +00:00
|
|
|
|
exports["default"] = function (start, minLine, maxLine) {
|
|
|
|
|
|
var wantForward = true,
|
|
|
|
|
|
backwardExhausted = false,
|
|
|
|
|
|
forwardExhausted = false,
|
|
|
|
|
|
localOffset = 1;
|
2015-08-08 00:11:35 +00:00
|
|
|
|
|
2015-10-31 21:55:15 +00:00
|
|
|
|
return function iterator() {
|
|
|
|
|
|
var _again = true;
|
2015-08-08 00:11:35 +00:00
|
|
|
|
|
2015-10-31 21:55:15 +00:00
|
|
|
|
_function: while (_again) {
|
|
|
|
|
|
_again = false;
|
2015-08-08 00:11:35 +00:00
|
|
|
|
|
2015-10-31 21:55:15 +00:00
|
|
|
|
if (wantForward && !forwardExhausted) {
|
|
|
|
|
|
if (backwardExhausted) {
|
|
|
|
|
|
localOffset++;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
wantForward = false;
|
|
|
|
|
|
}
|
2015-08-08 00:11:35 +00:00
|
|
|
|
|
2015-10-31 21:55:15 +00:00
|
|
|
|
// Check if trying to fit beyond text length, and if not, check it fits
|
|
|
|
|
|
// after offset location (or desired location on first iteration)
|
|
|
|
|
|
if (start + localOffset <= maxLine) {
|
|
|
|
|
|
return localOffset;
|
|
|
|
|
|
}
|
2015-08-08 00:11:35 +00:00
|
|
|
|
|
2015-10-31 21:55:15 +00:00
|
|
|
|
forwardExhausted = true;
|
2015-08-08 00:11:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2015-10-31 21:55:15 +00:00
|
|
|
|
if (!backwardExhausted) {
|
|
|
|
|
|
if (!forwardExhausted) {
|
|
|
|
|
|
wantForward = true;
|
2015-08-08 00:11:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2015-10-31 21:55:15 +00:00
|
|
|
|
// Check if trying to fit before text beginning, and if not, check it fits
|
|
|
|
|
|
// before offset location
|
|
|
|
|
|
if (minLine <= start - localOffset) {
|
|
|
|
|
|
return - localOffset++;
|
2015-08-08 00:11:35 +00:00
|
|
|
|
}
|
2015-10-31 21:55:15 +00:00
|
|
|
|
|
|
|
|
|
|
backwardExhausted = true;
|
|
|
|
|
|
_again = true;
|
|
|
|
|
|
continue _function;
|
2015-08-08 00:11:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2015-10-31 21:55:15 +00:00
|
|
|
|
// We tried to fit hunk before text beginning and beyond text lenght, then
|
|
|
|
|
|
// hunk can't fit on the text. Return undefined
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
module.exports = exports["default"];
|
|
|
|
|
|
// start of 2, this will iterate 2, 3, 1, 4, 0.
|
|
|
|
|
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy91dGlsL2Rpc3RhbmNlLWl0ZXJhdG9yLmpzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7OztxQkFHZSxVQUFTLEtBQUssRUFBRSxPQUFPLEVBQUUsT0FBTyxFQUFFO0FBQy9DLE1BQUksV0FBVyxHQUFHLElBQUk7TUFDbEIsaUJBQWlCLEdBQUcsS0FBSztNQUN6QixnQkFBZ0IsR0FBRyxLQUFLO01BQ3hCLFdBQVcsR0FBRyxDQUFDLENBQUM7O0FBRXBCLFNBQU8sU0FBUyxRQUFROzs7OEJBQUc7OztBQUN6QixVQU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zZXQrKztcbiAgICAgIH1cblxuICAgICAgYmFja3dhcmRFeGhhdXN0ZWQgPSB0cnVlO1xuICAgICAgcmV0dXJuIGl0ZXJhdG9yKCk7XG4gICAgfVxuXG4gICAgLy8gV2UgdHJpZWQgdG8gZml0IGh1bmsgYmVmb3JlIHRleHQgYmVnaW5uaW5nIGFuZCBiZXlvbmQgdGV4dCBsZW5naHQsIHRoZW5cbiAgICAvLyBodW5rIGNhbid0IGZpdCBvbiB0aGUgdGV4dC4gUmV0dXJuIHVuZGVmaW5lZFxuICB9O1xufVxuIl19
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/***/ },
|
|
|
|
|
|
/* 17 */
|
|
|
|
|
|
/***/ function(module, exports, __webpack_require__) {
|
|
|
|
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
|
|
exports.__esModule = true;
|
|
|
|
|
|
exports.structuredPatch = structuredPatch;
|
|
|
|
|
|
exports.createTwoFilesPatch = createTwoFilesPatch;
|
|
|
|
|
|
exports.createPatch = createPatch;
|
|
|
|
|
|
// istanbul ignore next
|
|
|
|
|
|
|
|
|
|
|
|
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) arr2[i] = arr[i]; return arr2; } else { return Array.from(arr); } }
|
|
|
|
|
|
|
|
|
|
|
|
var _diffLine = __webpack_require__(10);
|
|
|
|
|
|
|
|
|
|
|
|
function structuredPatch(oldFileName, newFileName, oldStr, newStr, oldHeader, newHeader, options) {
|
|
|
|
|
|
if (!options) {
|
|
|
|
|
|
options = { context: 4 };
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var diff = _diffLine.diffLines(oldStr, newStr);
|
|
|
|
|
|
diff.push({ value: '', lines: [] }); // Append an empty value to make cleanup easier
|
|
|
|
|
|
|
|
|
|
|
|
function contextLines(lines) {
|
|
|
|
|
|
return lines.map(function (entry) {
|
|
|
|
|
|
return ' ' + entry;
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var hunks = [];
|
|
|
|
|
|
var oldRangeStart = 0,
|
|
|
|
|
|
newRangeStart = 0,
|
|
|
|
|
|
curRange = [],
|
|
|
|
|
|
oldLine = 1,
|
|
|
|
|
|
newLine = 1;
|
|
|
|
|
|
|
|
|
|
|
|
var _loop = function (i) {
|
|
|
|
|
|
var current = diff[i],
|
|
|
|
|
|
lines = current.lines || current.value.replace(/\n$/, '').split('\n');
|
|
|
|
|
|
current.lines = lines;
|
|
|
|
|
|
|
|
|
|
|
|
if (current.added || current.removed) {
|
|
|
|
|
|
// istanbul ignore next
|
|
|
|
|
|
|
|
|
|
|
|
var _curRange;
|
|
|
|
|
|
|
|
|
|
|
|
// If we have previous context, start with that
|
|
|
|
|
|
if (!oldRangeStart) {
|
|
|
|
|
|
var prev = diff[i - 1];
|
|
|
|
|
|
oldRangeStart = oldLine;
|
|
|
|
|
|
newRangeStart = newLine;
|
|
|
|
|
|
|
|
|
|
|
|
if (prev) {
|
|
|
|
|
|
curRange = options.context > 0 ? contextLines(prev.lines.slice(-options.context)) : [];
|
|
|
|
|
|
oldRangeStart -= curRange.length;
|
|
|
|
|
|
newRangeStart -= curRange.length;
|
2015-08-08 00:11:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2015-10-31 21:55:15 +00:00
|
|
|
|
// Output our changes
|
|
|
|
|
|
(_curRange = curRange).push.apply(_curRange, _toConsumableArray(lines.map(function (entry) {
|
|
|
|
|
|
return (current.added ? '+' : '-') + entry;
|
|
|
|
|
|
})));
|
2015-08-08 00:11:35 +00:00
|
|
|
|
|
2015-10-31 21:55:15 +00:00
|
|
|
|
// Track the updated file position
|
|
|
|
|
|
if (current.added) {
|
|
|
|
|
|
newLine += lines.length;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
oldLine += lines.length;
|
2015-08-08 00:11:35 +00:00
|
|
|
|
}
|
2015-10-31 21:55:15 +00:00
|
|
|
|
} else {
|
|
|
|
|
|
// Identical context lines. Track line changes
|
|
|
|
|
|
if (oldRangeStart) {
|
|
|
|
|
|
// Close out any changes that have been output (or join overlapping)
|
|
|
|
|
|
if (lines.length <= options.context * 2 && i < diff.length - 2) {
|
|
|
|
|
|
// istanbul ignore next
|
|
|
|
|
|
|
|
|
|
|
|
var _curRange2;
|
|
|
|
|
|
|
|
|
|
|
|
// Overlapping
|
|
|
|
|
|
(_curRange2 = curRange).push.apply(_curRange2, _toConsumableArray(contextLines(lines)));
|
2015-08-08 00:11:35 +00:00
|
|
|
|
} else {
|
2015-10-31 21:55:15 +00:00
|
|
|
|
// istanbul ignore next
|
|
|
|
|
|
|
|
|
|
|
|
var _curRange3;
|
|
|
|
|
|
|
|
|
|
|
|
// end the range and output
|
|
|
|
|
|
var contextSize = Math.min(lines.length, options.context);
|
|
|
|
|
|
(_curRange3 = curRange).push.apply(_curRange3, _toConsumableArray(contextLines(lines.slice(0, contextSize))));
|
|
|
|
|
|
|
|
|
|
|
|
var hunk = {
|
|
|
|
|
|
oldStart: oldRangeStart,
|
|
|
|
|
|
oldLines: oldLine - oldRangeStart + contextSize,
|
|
|
|
|
|
newStart: newRangeStart,
|
|
|
|
|
|
newLines: newLine - newRangeStart + contextSize,
|
|
|
|
|
|
lines: curRange
|
|
|
|
|
|
};
|
|
|
|
|
|
if (i >= diff.length - 2 && lines.length <= options.context) {
|
|
|
|
|
|
// EOF is inside this hunk
|
|
|
|
|
|
var oldEOFNewline = /\n$/.test(oldStr);
|
|
|
|
|
|
var newEOFNewline = /\n$/.test(newStr);
|
|
|
|
|
|
if (lines.length == 0 && !oldEOFNewline) {
|
|
|
|
|
|
// special case: old has no eol and no trailing context; no-nl can end up before adds
|
|
|
|
|
|
curRange.splice(hunk.oldLines, 0, '\\ No newline at end of file');
|
|
|
|
|
|
} else if (!oldEOFNewline || !newEOFNewline) {
|
|
|
|
|
|
curRange.push('\\ No newline at end of file');
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
hunks.push(hunk);
|
2015-08-08 00:11:35 +00:00
|
|
|
|
|
2015-10-31 21:55:15 +00:00
|
|
|
|
oldRangeStart = 0;
|
|
|
|
|
|
newRangeStart = 0;
|
|
|
|
|
|
curRange = [];
|
|
|
|
|
|
}
|
2015-08-08 00:11:35 +00:00
|
|
|
|
}
|
2015-10-31 21:55:15 +00:00
|
|
|
|
oldLine += lines.length;
|
|
|
|
|
|
newLine += lines.length;
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
2015-08-08 00:11:35 +00:00
|
|
|
|
|
2015-10-31 21:55:15 +00:00
|
|
|
|
for (var i = 0; i < diff.length; i++) {
|
|
|
|
|
|
_loop(i);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
|
oldFileName: oldFileName, newFileName: newFileName,
|
|
|
|
|
|
oldHeader: oldHeader, newHeader: newHeader,
|
|
|
|
|
|
hunks: hunks
|
2015-08-08 00:11:35 +00:00
|
|
|
|
};
|
2015-10-31 21:55:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function createTwoFilesPatch(oldFileName, newFileName, oldStr, newStr, oldHeader, newHeader, options) {
|
|
|
|
|
|
var diff = structuredPatch(oldFileName, newFileName, oldStr, newStr, oldHeader, newHeader, options);
|
2015-08-08 00:11:35 +00:00
|
|
|
|
|
2015-10-31 21:55:15 +00:00
|
|
|
|
var ret = [];
|
|
|
|
|
|
if (oldFileName == newFileName) {
|
|
|
|
|
|
ret.push('Index: ' + oldFileName);
|
2015-08-08 00:11:35 +00:00
|
|
|
|
}
|
2015-10-31 21:55:15 +00:00
|
|
|
|
ret.push('===================================================================');
|
|
|
|
|
|
ret.push('--- ' + diff.oldFileName + (typeof diff.oldHeader === 'undefined' ? '' : '\t' + diff.oldHeader));
|
|
|
|
|
|
ret.push('+++ ' + diff.newFileName + (typeof diff.newHeader === 'undefined' ? '' : '\t' + diff.newHeader));
|
|
|
|
|
|
|
|
|
|
|
|
for (var i = 0; i < diff.hunks.length; i++) {
|
|
|
|
|
|
var hunk = diff.hunks[i];
|
|
|
|
|
|
ret.push('@@ -' + hunk.oldStart + ',' + hunk.oldLines + ' +' + hunk.newStart + ',' + hunk.newLines + ' @@');
|
|
|
|
|
|
ret.push.apply(ret, hunk.lines);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return ret.join('\n') + '\n';
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function createPatch(fileName, oldStr, newStr, oldHeader, newHeader, options) {
|
|
|
|
|
|
return createTwoFilesPatch(fileName, fileName, oldStr, newStr, oldHeader, newHeader, options);
|
|
|
|
|
|
}
|
|
|
|
|
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9wYXRjaC9jcmVhdGUuanMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7Ozt3QkFBd0IsY0FBYzs7QUFFL0IsU0FBUyxlQUFlLENBQUMsV0FBVyxFQUFFLFdBQVcsRUFBRSxNQUFNLEVBQUUsTUFBTSxFQUFFLFNBQVMsRUFBRSxTQUFTLEVBQUUsT0FBTyxFQUFFO0FBQ3ZHLE1BQUksQ0FBQyxPQUFPLEVBQUU7QUFDWixXQUFPLEdBQUcsRUFBRSxPQUFPLEVBQUUsQ0FBQyxFQUFFLENBQUM7R0FDMUI7O0FBRUQsTUFBTSxJQUFJLEdBQUcsb0JBQVUsTUFBTSxFQUFFLE1BQU0sQ0FBQyxDQUFDO0FBQ3ZDLE1BQUksQ0FBQyxJQUFJLENBQUMsRUFBQyxLQUFLLEVBQUUsRUFBRSxFQUFFLEtBQUssRUFBRSxFQUFFLEVBQUMsQ0FBQyxDQUFDOztBQUVsQyxXQUFTLFlBQVksQ0FBQyxLQUFLLEVBQUU7QUFDM0IsV0FBTyxLQUFLLENBQUMsR0FBRyxDQU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QztBQUN4QixhQUFPLElBQUksS0FBSyxDQUFDLE1BQU0sQ0FBQztLQUN6Qjs7O0FBckVILE9BQUssSUFBSSxDQUFDLEdBQUcsQ0FBQyxFQUFFLENBQUMsR0FBRyxJQUFJLENBQUMsTUFBTSxFQUFFLENBQUMsRUFBRSxFQUFFO1VBQTdCLENBQUM7R0FzRVQ7O0FBRUQsU0FBTztBQUNMLGVBQVcsRUFBRSxXQUFXLEVBQUUsV0FBVyxFQUFFLFdBQVc7QUFDbEQsYUFBUyxFQUFFLFNBQVMsRUFBRSxTQUFT
|
2015-08-08 00:11:35 +00:00
|
|
|
|
|
|
|
|
|
|
|
2015-10-19 11:47:49 +00:00
|
|
|
|
/***/ },
|
2015-10-31 21:55:15 +00:00
|
|
|
|
/* 18 */
|
|
|
|
|
|
/***/ function(module, exports) {
|
|
|
|
|
|
|
|
|
|
|
|
// See: http://code.google.com/p/google-diff-match-patch/wiki/API
|
|
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
|
|
|
|
exports.__esModule = true;
|
|
|
|
|
|
exports.convertChangesToDMP = convertChangesToDMP;
|
|
|
|
|
|
|
|
|
|
|
|
function convertChangesToDMP(changes) {
|
|
|
|
|
|
var ret = [],
|
|
|
|
|
|
change = undefined,
|
|
|
|
|
|
operation = undefined;
|
|
|
|
|
|
for (var i = 0; i < changes.length; i++) {
|
|
|
|
|
|
change = changes[i];
|
|
|
|
|
|
if (change.added) {
|
|
|
|
|
|
operation = 1;
|
|
|
|
|
|
} else if (change.removed) {
|
|
|
|
|
|
operation = -1;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
operation = 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ret.push([operation, change.value]);
|
|
|
|
|
|
}
|
|
|
|
|
|
return ret;
|
|
|
|
|
|
}
|
|
|
|
|
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9jb252ZXJ0L2Rt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zW2ldO1xuICAgIGlmIChjaGFuZ2UuYWRkZWQpIHtcbiAgICAgIG9wZXJhdGlvbiA9IDE7XG4gICAgfSBlbHNlIGlmIChjaGFuZ2UucmVtb3ZlZCkge1xuICAgICAgb3BlcmF0aW9uID0gLTE7XG4gICAgfSBlbHNlIHtcbiAgICAgIG9wZXJhdGlvbiA9IDA7XG4gICAgfVxuXG4gICAgcmV0LnB1c2goW29wZXJhdGlvbiwgY2hhbmdlLnZhbHVlXSk7XG4gIH1cbiAgcmV0dXJuIHJldDtcbn1cbiJdfQ==
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/***/ },
|
|
|
|
|
|
/* 19 */
|
|
|
|
|
|
/***/ function(module, exports) {
|
|
|
|
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
|
|
exports.__esModule = true;
|
|
|
|
|
|
exports.convertChangesToXML = convertChangesToXML;
|
|
|
|
|
|
|
|
|
|
|
|
function convertChangesToXML(changes) {
|
|
|
|
|
|
var ret = [];
|
|
|
|
|
|
for (var i = 0; i < changes.length; i++) {
|
|
|
|
|
|
var change = changes[i];
|
|
|
|
|
|
if (change.added) {
|
|
|
|
|
|
ret.push('<ins>');
|
|
|
|
|
|
} else if (change.removed) {
|
|
|
|
|
|
ret.push('<del>');
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ret.push(escapeHTML(change.value));
|
|
|
|
|
|
|
|
|
|
|
|
if (change.added) {
|
|
|
|
|
|
ret.push('</ins>');
|
|
|
|
|
|
} else if (change.removed) {
|
|
|
|
|
|
ret.push('</del>');
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return ret.join('');
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function escapeHTML(s) {
|
|
|
|
|
|
var n = s;
|
|
|
|
|
|
n = n.replace(/&/g, '&');
|
|
|
|
|
|
n = n.replace(/</g, '<');
|
|
|
|
|
|
n = n.replace(/>/g, '>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VybiByZXQuam9pbignJyk7XG59XG5cbmZ1bmN0aW9uIGVzY2FwZUhUTUwocykge1xuICBsZXQgbiA9IHM7XG4gIG4gPSBuLnJlcGxhY2UoLyYvZywgJyZhbXA7Jyk7XG4gIG4gPSBuLnJlcGxhY2UoLzwvZywgJyZsdDsnKTtcbiAgbiA9IG4ucmVwbGFjZSgvPi9nLCAnJmd0OycpO1xuICBuID0gbi5yZXBsYWNlKC9cIi9nLCAnJnF1b3Q7Jyk7XG5cbiAgcmV0dXJuIG47XG59XG4iXX0=
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/***/ },
|
|
|
|
|
|
/* 20 */
|
2015-12-19 21:09:31 +00:00
|
|
|
|
/***/ function(module, exports) {
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
*
|
|
|
|
|
|
* Rematch (rematch.js)
|
|
|
|
|
|
* Matching two sequences of objects by similarity
|
|
|
|
|
|
* Author: W. Illmeyer, Nexxar GmbH
|
|
|
|
|
|
*
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
2015-12-20 22:22:58 +00:00
|
|
|
|
(function() {
|
|
|
|
|
|
|
2015-12-19 21:09:31 +00:00
|
|
|
|
var Rematch = {};
|
|
|
|
|
|
Rematch.arrayToString = function arrayToString(a) {
|
2015-12-20 22:22:58 +00:00
|
|
|
|
if (Object.prototype.toString.apply(a, []) === "[object Array]") {
|
2015-12-19 21:09:31 +00:00
|
|
|
|
return "[" + a.map(arrayToString).join(", ") + "]";
|
|
|
|
|
|
} else {
|
|
|
|
|
|
return a;
|
|
|
|
|
|
}
|
2015-12-20 22:22:58 +00:00
|
|
|
|
};
|
2015-12-19 21:09:31 +00:00
|
|
|
|
|
|
|
|
|
|
/*
|
2015-12-20 22:22:58 +00:00
|
|
|
|
Copyright (c) 2011 Andrei Mackenzie
|
2016-02-07 14:19:23 +00:00
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
|
|
|
|
|
|
documentation files (the "Software"), to deal in the Software without restriction, including without limitation
|
|
|
|
|
|
the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
|
|
|
|
|
|
and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
2015-12-20 22:22:58 +00:00
|
|
|
|
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
2016-02-07 14:19:23 +00:00
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
|
|
|
|
|
|
THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
|
|
|
|
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
2015-12-20 22:22:58 +00:00
|
|
|
|
*/
|
|
|
|
|
|
function levenshtein(a, b) {
|
2016-02-07 14:19:23 +00:00
|
|
|
|
if (a.length == 0) {
|
|
|
|
|
|
return b.length;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (b.length == 0) {
|
|
|
|
|
|
return a.length;
|
|
|
|
|
|
}
|
2015-12-19 21:09:31 +00:00
|
|
|
|
|
|
|
|
|
|
var matrix = [];
|
|
|
|
|
|
|
2016-02-07 14:19:23 +00:00
|
|
|
|
// Increment along the first column of each row
|
2015-12-19 21:09:31 +00:00
|
|
|
|
var i;
|
2015-12-20 22:22:58 +00:00
|
|
|
|
for (i = 0; i <= b.length; i++) {
|
2015-12-19 21:09:31 +00:00
|
|
|
|
matrix[i] = [i];
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-02-07 14:19:23 +00:00
|
|
|
|
// Increment each column in the first row
|
2015-12-19 21:09:31 +00:00
|
|
|
|
var j;
|
2015-12-20 22:22:58 +00:00
|
|
|
|
for (j = 0; j <= a.length; j++) {
|
2015-12-19 21:09:31 +00:00
|
|
|
|
matrix[0][j] = j;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Fill in the rest of the matrix
|
2015-12-20 22:22:58 +00:00
|
|
|
|
for (i = 1; i <= b.length; i++) {
|
|
|
|
|
|
for (j = 1; j <= a.length; j++) {
|
|
|
|
|
|
if (b.charAt(i - 1) == a.charAt(j - 1)) {
|
|
|
|
|
|
matrix[i][j] = matrix[i - 1][j - 1];
|
2015-12-19 21:09:31 +00:00
|
|
|
|
} else {
|
2016-02-07 14:19:23 +00:00
|
|
|
|
matrix[i][j] = Math.min(matrix[i - 1][j - 1] + 1, // Substitution
|
|
|
|
|
|
Math.min(matrix[i][j - 1] + 1, // Insertion
|
|
|
|
|
|
matrix[i - 1][j] + 1)); // Deletion
|
2015-12-19 21:09:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2015-12-20 22:22:58 +00:00
|
|
|
|
|
2015-12-19 21:09:31 +00:00
|
|
|
|
return matrix[b.length][a.length];
|
|
|
|
|
|
}
|
2015-12-20 22:22:58 +00:00
|
|
|
|
|
2015-12-19 21:09:31 +00:00
|
|
|
|
Rematch.levenshtein = levenshtein;
|
|
|
|
|
|
|
2015-12-20 22:22:58 +00:00
|
|
|
|
Rematch.distance = function distance(x, y) {
|
|
|
|
|
|
x = x.trim();
|
|
|
|
|
|
y = y.trim();
|
|
|
|
|
|
var lev = levenshtein(x, y);
|
|
|
|
|
|
var score = lev / (x.length + y.length);
|
|
|
|
|
|
|
2015-12-19 21:09:31 +00:00
|
|
|
|
return score;
|
2015-12-20 22:22:58 +00:00
|
|
|
|
};
|
2015-12-19 21:09:31 +00:00
|
|
|
|
|
|
|
|
|
|
Rematch.rematch = function rematch(distanceFunction) {
|
|
|
|
|
|
function findBestMatch(a, b, cache) {
|
|
|
|
|
|
var cachecount = 0;
|
|
|
|
|
|
|
2015-12-20 22:22:58 +00:00
|
|
|
|
for (var key in cache) {
|
2015-12-19 21:09:31 +00:00
|
|
|
|
cachecount++;
|
|
|
|
|
|
}
|
2015-12-20 22:22:58 +00:00
|
|
|
|
|
2015-12-19 21:09:31 +00:00
|
|
|
|
var bestMatchDist = Infinity;
|
|
|
|
|
|
var bestMatch;
|
|
|
|
|
|
for (var i = 0; i < a.length; ++i) {
|
|
|
|
|
|
for (var j = 0; j < b.length; ++j) {
|
|
|
|
|
|
var cacheKey = JSON.stringify([a[i], b[j]]);
|
|
|
|
|
|
var md;
|
|
|
|
|
|
if (cache.hasOwnProperty(cacheKey)) {
|
|
|
|
|
|
md = cache[cacheKey];
|
|
|
|
|
|
} else {
|
|
|
|
|
|
md = distanceFunction(a[i], b[j]);
|
|
|
|
|
|
cache[cacheKey] = md;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (md < bestMatchDist) {
|
|
|
|
|
|
bestMatchDist = md;
|
2015-12-20 22:22:58 +00:00
|
|
|
|
bestMatch = {indexA: i, indexB: j, score: bestMatchDist};
|
2015-12-19 21:09:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2015-12-20 22:22:58 +00:00
|
|
|
|
|
2015-12-19 21:09:31 +00:00
|
|
|
|
return bestMatch;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2015-12-20 22:22:58 +00:00
|
|
|
|
function group(a, b, level, cache) {
|
2016-02-07 14:19:23 +00:00
|
|
|
|
if (typeof (cache) === "undefined") {
|
2015-12-19 21:09:31 +00:00
|
|
|
|
cache = {};
|
|
|
|
|
|
}
|
2015-12-20 22:22:58 +00:00
|
|
|
|
|
|
|
|
|
|
var bm = findBestMatch(a, b, cache);
|
|
|
|
|
|
|
2015-12-19 21:09:31 +00:00
|
|
|
|
if (!level) {
|
|
|
|
|
|
level = 0;
|
|
|
|
|
|
}
|
2015-12-20 22:22:58 +00:00
|
|
|
|
|
2015-12-19 21:09:31 +00:00
|
|
|
|
if (!bm || (a.length + b.length < 3)) {
|
|
|
|
|
|
return [[a, b]];
|
|
|
|
|
|
}
|
2015-12-20 22:22:58 +00:00
|
|
|
|
|
2016-02-07 14:19:23 +00:00
|
|
|
|
var a1 = a.slice(0, bm.indexA);
|
|
|
|
|
|
var b1 = b.slice(0, bm.indexB);
|
|
|
|
|
|
var aMatch = [a[bm.indexA]];
|
|
|
|
|
|
var bMatch = [b[bm.indexB]];
|
|
|
|
|
|
var tailA = bm.indexA + 1;
|
|
|
|
|
|
var tailB = bm.indexB + 1;
|
|
|
|
|
|
var a2 = a.slice(tailA);
|
|
|
|
|
|
var b2 = b.slice(tailB);
|
2015-12-19 21:09:31 +00:00
|
|
|
|
|
2015-12-20 22:22:58 +00:00
|
|
|
|
var group1 = group(a1, b1, level + 1, cache);
|
|
|
|
|
|
var groupMatch = group(aMatch, bMatch, level + 1, cache);
|
|
|
|
|
|
var group2 = group(a2, b2, level + 1, cache);
|
2015-12-19 21:09:31 +00:00
|
|
|
|
var result = groupMatch;
|
2015-12-20 22:22:58 +00:00
|
|
|
|
|
2015-12-19 21:09:31 +00:00
|
|
|
|
if (bm.indexA > 0 || bm.indexB > 0) {
|
|
|
|
|
|
result = group1.concat(result);
|
|
|
|
|
|
}
|
2015-12-20 22:22:58 +00:00
|
|
|
|
|
|
|
|
|
|
if (a.length > tailA || b.length > tailB) {
|
2015-12-19 21:09:31 +00:00
|
|
|
|
result = result.concat(group2);
|
|
|
|
|
|
}
|
2015-12-20 22:22:58 +00:00
|
|
|
|
|
2015-12-19 21:09:31 +00:00
|
|
|
|
return result;
|
|
|
|
|
|
}
|
2015-12-20 22:22:58 +00:00
|
|
|
|
|
2015-12-19 21:09:31 +00:00
|
|
|
|
return group;
|
2015-12-20 22:22:58 +00:00
|
|
|
|
};
|
2015-12-19 21:09:31 +00:00
|
|
|
|
|
2015-12-20 22:22:58 +00:00
|
|
|
|
module.exports.Rematch = Rematch;
|
2015-12-19 21:09:31 +00:00
|
|
|
|
|
2015-12-20 22:22:58 +00:00
|
|
|
|
})();
|
2015-12-19 21:09:31 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/***/ },
|
|
|
|
|
|
/* 21 */
|
2015-10-19 11:47:49 +00:00
|
|
|
|
/***/ function(module, exports, __webpack_require__) {
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
*
|
|
|
|
|
|
* HtmlPrinter (html-printer.js)
|
|
|
|
|
|
* Author: rtfpessoa
|
|
|
|
|
|
*
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
2015-12-20 22:22:58 +00:00
|
|
|
|
(function() {
|
2015-10-19 11:47:49 +00:00
|
|
|
|
|
2015-12-20 22:22:58 +00:00
|
|
|
|
var LineByLinePrinter = __webpack_require__(22).LineByLinePrinter;
|
2016-01-31 18:33:33 +00:00
|
|
|
|
var SideBySidePrinter = __webpack_require__(39).SideBySidePrinter;
|
2015-10-19 11:47:49 +00:00
|
|
|
|
|
|
|
|
|
|
function HtmlPrinter() {
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2015-12-20 22:22:58 +00:00
|
|
|
|
HtmlPrinter.prototype.generateLineByLineJsonHtml = function(diffFiles, config) {
|
|
|
|
|
|
var lineByLinePrinter = new LineByLinePrinter(config);
|
|
|
|
|
|
return lineByLinePrinter.generateLineByLineJsonHtml(diffFiles);
|
|
|
|
|
|
};
|
2015-10-19 11:47:49 +00:00
|
|
|
|
|
2016-02-07 14:19:23 +00:00
|
|
|
|
HtmlPrinter.prototype.generateSideBySideJsonHtml = function(diffFiles, config) {
|
|
|
|
|
|
var sideBySidePrinter = new SideBySidePrinter(config);
|
|
|
|
|
|
return sideBySidePrinter.generateSideBySideJsonHtml(diffFiles);
|
|
|
|
|
|
};
|
2015-10-19 11:47:49 +00:00
|
|
|
|
|
2015-12-20 22:22:58 +00:00
|
|
|
|
module.exports.HtmlPrinter = new HtmlPrinter();
|
2015-10-19 11:47:49 +00:00
|
|
|
|
|
2015-12-20 22:22:58 +00:00
|
|
|
|
})();
|
2015-10-19 11:47:49 +00:00
|
|
|
|
|
|
|
|
|
|
|
2015-08-08 00:11:35 +00:00
|
|
|
|
/***/ },
|
2015-12-19 21:09:31 +00:00
|
|
|
|
/* 22 */
|
2015-10-19 11:47:49 +00:00
|
|
|
|
/***/ function(module, exports, __webpack_require__) {
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
*
|
|
|
|
|
|
* LineByLinePrinter (line-by-line-printer.js)
|
|
|
|
|
|
* Author: rtfpessoa
|
|
|
|
|
|
*
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
2015-12-20 22:22:58 +00:00
|
|
|
|
(function() {
|
2015-10-19 11:47:49 +00:00
|
|
|
|
|
|
|
|
|
|
var diffParser = __webpack_require__(1).DiffParser;
|
|
|
|
|
|
var printerUtils = __webpack_require__(4).PrinterUtils;
|
|
|
|
|
|
var utils = __webpack_require__(2).Utils;
|
2015-12-19 21:09:31 +00:00
|
|
|
|
var Rematch = __webpack_require__(20).Rematch;
|
2015-10-19 11:47:49 +00:00
|
|
|
|
|
2016-01-31 18:33:33 +00:00
|
|
|
|
var nunjucksUtils = __webpack_require__(23).NunjucksUtils;
|
|
|
|
|
|
var baseTemplatesPath = 'line-by-line';
|
|
|
|
|
|
|
2015-12-20 22:22:58 +00:00
|
|
|
|
function LineByLinePrinter(config) {
|
|
|
|
|
|
this.config = config;
|
2015-10-19 11:47:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2016-02-07 14:19:23 +00:00
|
|
|
|
LineByLinePrinter.prototype.makeFileDiffHtml = function(file, diffs) {
|
2016-01-31 18:33:33 +00:00
|
|
|
|
return nunjucksUtils.render(baseTemplatesPath, 'file-diff.html', {'file': file, 'diffs': diffs});
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
LineByLinePrinter.prototype.makeLineByLineHtmlWrapper = function(content) {
|
|
|
|
|
|
return nunjucksUtils.render(baseTemplatesPath, 'wrapper.html', {'content': content});
|
2016-02-07 14:19:23 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
2015-12-20 22:22:58 +00:00
|
|
|
|
LineByLinePrinter.prototype.generateLineByLineJsonHtml = function(diffFiles) {
|
|
|
|
|
|
var that = this;
|
2016-02-07 14:19:23 +00:00
|
|
|
|
var htmlDiffs = diffFiles.map(function(file) {
|
2016-01-31 18:33:33 +00:00
|
|
|
|
var diffs;
|
|
|
|
|
|
if (file.blocks.length) {
|
|
|
|
|
|
diffs = that._generateFileHtml(file);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
diffs = that._generateEmptyDiff();
|
|
|
|
|
|
}
|
|
|
|
|
|
return that.makeFileDiffHtml(file, diffs);
|
|
|
|
|
|
});
|
2015-10-19 11:47:49 +00:00
|
|
|
|
|
2016-01-31 18:33:33 +00:00
|
|
|
|
return this.makeLineByLineHtmlWrapper(htmlDiffs.join('\n'));
|
2015-10-19 11:47:49 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
2015-12-20 22:22:58 +00:00
|
|
|
|
var matcher = Rematch.rematch(function(a, b) {
|
|
|
|
|
|
var amod = a.content.substr(1);
|
|
|
|
|
|
var bmod = b.content.substr(1);
|
|
|
|
|
|
|
2015-12-19 21:09:31 +00:00
|
|
|
|
return Rematch.distance(amod, bmod);
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2016-02-07 14:19:23 +00:00
|
|
|
|
LineByLinePrinter.prototype.makeColumnLineNumberHtml = function(block) {
|
2016-01-31 18:33:33 +00:00
|
|
|
|
return nunjucksUtils.render(baseTemplatesPath, 'column-line-number.html', {block: block});
|
2016-02-07 14:19:23 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
LineByLinePrinter.prototype._generateFileHtml = function(file) {
|
|
|
|
|
|
var that = this;
|
|
|
|
|
|
return file.blocks.map(function(block) {
|
2015-10-19 11:47:49 +00:00
|
|
|
|
|
2016-02-07 14:19:23 +00:00
|
|
|
|
var lines = that.makeColumnLineNumberHtml(block);
|
2015-10-19 11:47:49 +00:00
|
|
|
|
var oldLines = [];
|
|
|
|
|
|
var newLines = [];
|
2015-12-20 22:22:58 +00:00
|
|
|
|
|
2015-12-19 21:09:31 +00:00
|
|
|
|
function processChangeBlock() {
|
|
|
|
|
|
var matches;
|
|
|
|
|
|
var insertType;
|
|
|
|
|
|
var deleteType;
|
2015-12-20 22:22:58 +00:00
|
|
|
|
|
|
|
|
|
|
var doMatching = that.config.matching === 'lines' || that.config.matching === 'words';
|
|
|
|
|
|
|
2015-12-19 21:09:31 +00:00
|
|
|
|
if (doMatching) {
|
|
|
|
|
|
matches = matcher(oldLines, newLines);
|
|
|
|
|
|
insertType = diffParser.LINE_TYPE.INSERT_CHANGES;
|
|
|
|
|
|
deleteType = diffParser.LINE_TYPE.DELETE_CHANGES;
|
2015-10-19 11:47:49 +00:00
|
|
|
|
} else {
|
2015-12-20 22:22:58 +00:00
|
|
|
|
matches = [[oldLines, newLines]];
|
2015-12-19 21:09:31 +00:00
|
|
|
|
insertType = diffParser.LINE_TYPE.INSERTS;
|
|
|
|
|
|
deleteType = diffParser.LINE_TYPE.DELETES;
|
|
|
|
|
|
}
|
2015-12-20 22:22:58 +00:00
|
|
|
|
|
|
|
|
|
|
matches.forEach(function(match) {
|
|
|
|
|
|
oldLines = match[0];
|
|
|
|
|
|
newLines = match[1];
|
|
|
|
|
|
|
2015-12-19 21:09:31 +00:00
|
|
|
|
var processedOldLines = [];
|
|
|
|
|
|
var processedNewLines = [];
|
2015-10-19 11:47:49 +00:00
|
|
|
|
|
2015-12-20 22:22:58 +00:00
|
|
|
|
var common = Math.min(oldLines.length, newLines.length);
|
|
|
|
|
|
|
|
|
|
|
|
var oldLine, newLine;
|
|
|
|
|
|
for (var j = 0; j < common; j++) {
|
|
|
|
|
|
oldLine = oldLines[j];
|
|
|
|
|
|
newLine = newLines[j];
|
|
|
|
|
|
|
|
|
|
|
|
that.config.isCombined = file.isCombined;
|
|
|
|
|
|
var diff = printerUtils.diffHighlight(oldLine.content, newLine.content, that.config);
|
2015-12-19 21:09:31 +00:00
|
|
|
|
|
2015-12-20 22:22:58 +00:00
|
|
|
|
processedOldLines +=
|
2016-01-31 18:33:33 +00:00
|
|
|
|
that.makeLineHtml(deleteType, oldLine.oldNumber, oldLine.newNumber,
|
2015-12-20 22:22:58 +00:00
|
|
|
|
diff.first.line, diff.first.prefix);
|
|
|
|
|
|
processedNewLines +=
|
2016-01-31 18:33:33 +00:00
|
|
|
|
that.makeLineHtml(insertType, newLine.oldNumber, newLine.newNumber,
|
2015-12-20 22:22:58 +00:00
|
|
|
|
diff.second.line, diff.second.prefix);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
lines += processedOldLines + processedNewLines;
|
|
|
|
|
|
lines += that._processLines(oldLines.slice(common), newLines.slice(common));
|
2015-12-19 21:09:31 +00:00
|
|
|
|
});
|
2015-12-20 22:22:58 +00:00
|
|
|
|
|
2015-12-19 21:09:31 +00:00
|
|
|
|
oldLines = [];
|
|
|
|
|
|
newLines = [];
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
for (var i = 0; i < block.lines.length; i++) {
|
|
|
|
|
|
var line = block.lines[i];
|
|
|
|
|
|
var escapedLine = utils.escape(line.content);
|
2015-10-19 11:47:49 +00:00
|
|
|
|
|
2015-12-20 22:22:58 +00:00
|
|
|
|
if (line.type !== diffParser.LINE_TYPE.INSERTS &&
|
|
|
|
|
|
(newLines.length > 0 || (line.type !== diffParser.LINE_TYPE.DELETES && oldLines.length > 0))) {
|
2015-12-19 21:09:31 +00:00
|
|
|
|
processChangeBlock();
|
|
|
|
|
|
}
|
2015-12-20 22:22:58 +00:00
|
|
|
|
|
|
|
|
|
|
if (line.type === diffParser.LINE_TYPE.CONTEXT) {
|
2016-01-31 18:33:33 +00:00
|
|
|
|
lines += that.makeLineHtml(line.type, line.oldNumber, line.newNumber, escapedLine);
|
2015-12-20 22:22:58 +00:00
|
|
|
|
} else if (line.type === diffParser.LINE_TYPE.INSERTS && !oldLines.length) {
|
2016-01-31 18:33:33 +00:00
|
|
|
|
lines += that.makeLineHtml(line.type, line.oldNumber, line.newNumber, escapedLine);
|
2015-12-20 22:22:58 +00:00
|
|
|
|
} else if (line.type === diffParser.LINE_TYPE.DELETES) {
|
2015-12-19 21:09:31 +00:00
|
|
|
|
oldLines.push(line);
|
2015-12-20 22:22:58 +00:00
|
|
|
|
} else if (line.type === diffParser.LINE_TYPE.INSERTS && Boolean(oldLines.length)) {
|
2015-12-19 21:09:31 +00:00
|
|
|
|
newLines.push(line);
|
|
|
|
|
|
} else {
|
2015-12-20 22:22:58 +00:00
|
|
|
|
console.error('Unknown state in html line-by-line generator');
|
2015-12-19 21:09:31 +00:00
|
|
|
|
processChangeBlock();
|
2015-10-19 11:47:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2015-12-19 21:09:31 +00:00
|
|
|
|
processChangeBlock();
|
2015-10-19 11:47:49 +00:00
|
|
|
|
|
|
|
|
|
|
return lines;
|
|
|
|
|
|
}).join('\n');
|
2015-12-20 22:22:58 +00:00
|
|
|
|
};
|
2015-10-19 11:47:49 +00:00
|
|
|
|
|
2015-12-20 22:22:58 +00:00
|
|
|
|
LineByLinePrinter.prototype._processLines = function(oldLines, newLines) {
|
2015-10-19 11:47:49 +00:00
|
|
|
|
var lines = '';
|
|
|
|
|
|
|
2015-12-20 22:22:58 +00:00
|
|
|
|
for (var i = 0; i < oldLines.length; i++) {
|
|
|
|
|
|
var oldLine = oldLines[i];
|
2015-10-19 11:47:49 +00:00
|
|
|
|
var oldEscapedLine = utils.escape(oldLine.content);
|
2016-01-31 18:33:33 +00:00
|
|
|
|
lines += this.makeLineHtml(oldLine.type, oldLine.oldNumber, oldLine.newNumber, oldEscapedLine);
|
2015-10-19 11:47:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2015-12-20 22:22:58 +00:00
|
|
|
|
for (var j = 0; j < newLines.length; j++) {
|
2015-10-19 11:47:49 +00:00
|
|
|
|
var newLine = newLines[j];
|
|
|
|
|
|
var newEscapedLine = utils.escape(newLine.content);
|
2016-01-31 18:33:33 +00:00
|
|
|
|
lines += this.makeLineHtml(newLine.type, newLine.oldNumber, newLine.newNumber, newEscapedLine);
|
2015-10-19 11:47:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return lines;
|
2015-12-20 22:22:58 +00:00
|
|
|
|
};
|
2015-10-19 11:47:49 +00:00
|
|
|
|
|
2016-01-31 18:33:33 +00:00
|
|
|
|
LineByLinePrinter.prototype.makeLineHtml = function(type, oldNumber, newNumber, content, prefix) {
|
|
|
|
|
|
return nunjucksUtils.render(baseTemplatesPath, 'line.html',
|
|
|
|
|
|
{
|
|
|
|
|
|
type: type,
|
|
|
|
|
|
oldNumber: oldNumber,
|
|
|
|
|
|
newNumber: newNumber,
|
|
|
|
|
|
prefix: prefix,
|
|
|
|
|
|
content: content
|
|
|
|
|
|
});
|
2015-12-20 22:22:58 +00:00
|
|
|
|
};
|
2015-10-19 11:47:49 +00:00
|
|
|
|
|
2015-12-20 22:22:58 +00:00
|
|
|
|
LineByLinePrinter.prototype._generateEmptyDiff = function() {
|
2016-01-31 18:33:33 +00:00
|
|
|
|
return nunjucksUtils.render(baseTemplatesPath, 'empty-diff.html', {});
|
2015-12-20 22:22:58 +00:00
|
|
|
|
};
|
2015-10-19 11:47:49 +00:00
|
|
|
|
|
2015-12-20 22:22:58 +00:00
|
|
|
|
module.exports.LineByLinePrinter = LineByLinePrinter;
|
2015-10-19 11:47:49 +00:00
|
|
|
|
|
2015-12-20 22:22:58 +00:00
|
|
|
|
})();
|
2015-10-19 11:47:49 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/***/ },
|
2015-12-19 21:09:31 +00:00
|
|
|
|
/* 23 */
|
2016-01-31 18:33:33 +00:00
|
|
|
|
/***/ function(module, exports, __webpack_require__) {
|
|
|
|
|
|
|
|
|
|
|
|
/* WEBPACK VAR INJECTION */(function(__dirname) {/*
|
|
|
|
|
|
*
|
|
|
|
|
|
* Utils (utils.js)
|
|
|
|
|
|
* Author: rtfpessoa
|
|
|
|
|
|
*
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
(function() {
|
|
|
|
|
|
|
|
|
|
|
|
var path = __webpack_require__(24);
|
|
|
|
|
|
|
|
|
|
|
|
var nunjucks = __webpack_require__(26);
|
|
|
|
|
|
var templatesPath = path.resolve(__dirname, 'templates');
|
|
|
|
|
|
|
|
|
|
|
|
var diffParser = __webpack_require__(1).DiffParser;
|
|
|
|
|
|
var printerUtils = __webpack_require__(4).PrinterUtils;
|
|
|
|
|
|
var utils = __webpack_require__(2).Utils;
|
|
|
|
|
|
|
|
|
|
|
|
var nunjucksEnv = nunjucks.configure(templatesPath, {"autoescape": false})
|
|
|
|
|
|
.addGlobal('printerUtils', printerUtils)
|
|
|
|
|
|
.addGlobal('utils', utils)
|
|
|
|
|
|
.addGlobal('diffParser', diffParser);
|
|
|
|
|
|
|
|
|
|
|
|
function NunjucksUtils() {
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NunjucksUtils.prototype.render = function(namespace, view, params) {
|
|
|
|
|
|
var viewPath = path.join(namespace, view);
|
|
|
|
|
|
return nunjucksEnv.render(viewPath, params);
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
module.exports.NunjucksUtils = new NunjucksUtils();
|
|
|
|
|
|
|
|
|
|
|
|
})();
|
|
|
|
|
|
|
|
|
|
|
|
/* WEBPACK VAR INJECTION */}.call(exports, "/"))
|
|
|
|
|
|
|
|
|
|
|
|
/***/ },
|
|
|
|
|
|
/* 24 */
|
|
|
|
|
|
/***/ function(module, exports, __webpack_require__) {
|
|
|
|
|
|
|
|
|
|
|
|
/* WEBPACK VAR INJECTION */(function(process) {// Copyright Joyent, Inc. and other Node contributors.
|
|
|
|
|
|
//
|
|
|
|
|
|
// Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
|
|
// copy of this software and associated documentation files (the
|
|
|
|
|
|
// "Software"), to deal in the Software without restriction, including
|
|
|
|
|
|
// without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
|
|
// distribute, sublicense, and/or sell copies of the Software, and to permit
|
|
|
|
|
|
// persons to whom the Software is furnished to do so, subject to the
|
|
|
|
|
|
// following conditions:
|
|
|
|
|
|
//
|
|
|
|
|
|
// The above copyright notice and this permission notice shall be included
|
|
|
|
|
|
// in all copies or substantial portions of the Software.
|
|
|
|
|
|
//
|
|
|
|
|
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
|
|
|
|
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
|
|
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
|
|
|
|
|
|
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
|
|
|
|
|
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
|
|
|
|
|
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
|
|
|
|
|
// USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
|
|
|
|
|
|
|
|
// resolves . and .. elements in a path array with directory names there
|
|
|
|
|
|
// must be no slashes, empty elements, or device names (c:\) in the array
|
|
|
|
|
|
// (so also no leading and trailing slashes - it does not distinguish
|
|
|
|
|
|
// relative and absolute paths)
|
|
|
|
|
|
function normalizeArray(parts, allowAboveRoot) {
|
|
|
|
|
|
// if the path tries to go above the root, `up` ends up > 0
|
|
|
|
|
|
var up = 0;
|
|
|
|
|
|
for (var i = parts.length - 1; i >= 0; i--) {
|
|
|
|
|
|
var last = parts[i];
|
|
|
|
|
|
if (last === '.') {
|
|
|
|
|
|
parts.splice(i, 1);
|
|
|
|
|
|
} else if (last === '..') {
|
|
|
|
|
|
parts.splice(i, 1);
|
|
|
|
|
|
up++;
|
|
|
|
|
|
} else if (up) {
|
|
|
|
|
|
parts.splice(i, 1);
|
|
|
|
|
|
up--;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// if the path is allowed to go above the root, restore leading ..s
|
|
|
|
|
|
if (allowAboveRoot) {
|
|
|
|
|
|
for (; up--; up) {
|
|
|
|
|
|
parts.unshift('..');
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return parts;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Split a filename into [root, dir, basename, ext], unix version
|
|
|
|
|
|
// 'root' is just a slash, or nothing.
|
|
|
|
|
|
var splitPathRe =
|
|
|
|
|
|
/^(\/?|)([\s\S]*?)((?:\.{1,2}|[^\/]+?|)(\.[^.\/]*|))(?:[\/]*)$/;
|
|
|
|
|
|
var splitPath = function(filename) {
|
|
|
|
|
|
return splitPathRe.exec(filename).slice(1);
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// path.resolve([from ...], to)
|
|
|
|
|
|
// posix version
|
|
|
|
|
|
exports.resolve = function() {
|
|
|
|
|
|
var resolvedPath = '',
|
|
|
|
|
|
resolvedAbsolute = false;
|
|
|
|
|
|
|
|
|
|
|
|
for (var i = arguments.length - 1; i >= -1 && !resolvedAbsolute; i--) {
|
|
|
|
|
|
var path = (i >= 0) ? arguments[i] : process.cwd();
|
|
|
|
|
|
|
|
|
|
|
|
// Skip empty and invalid entries
|
|
|
|
|
|
if (typeof path !== 'string') {
|
|
|
|
|
|
throw new TypeError('Arguments to path.resolve must be strings');
|
|
|
|
|
|
} else if (!path) {
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
resolvedPath = path + '/' + resolvedPath;
|
|
|
|
|
|
resolvedAbsolute = path.charAt(0) === '/';
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// At this point the path should be resolved to a full absolute path, but
|
|
|
|
|
|
// handle relative paths to be safe (might happen when process.cwd() fails)
|
|
|
|
|
|
|
|
|
|
|
|
// Normalize the path
|
|
|
|
|
|
resolvedPath = normalizeArray(filter(resolvedPath.split('/'), function(p) {
|
|
|
|
|
|
return !!p;
|
|
|
|
|
|
}), !resolvedAbsolute).join('/');
|
|
|
|
|
|
|
|
|
|
|
|
return ((resolvedAbsolute ? '/' : '') + resolvedPath) || '.';
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// path.normalize(path)
|
|
|
|
|
|
// posix version
|
|
|
|
|
|
exports.normalize = function(path) {
|
|
|
|
|
|
var isAbsolute = exports.isAbsolute(path),
|
|
|
|
|
|
trailingSlash = substr(path, -1) === '/';
|
|
|
|
|
|
|
|
|
|
|
|
// Normalize the path
|
|
|
|
|
|
path = normalizeArray(filter(path.split('/'), function(p) {
|
|
|
|
|
|
return !!p;
|
|
|
|
|
|
}), !isAbsolute).join('/');
|
|
|
|
|
|
|
|
|
|
|
|
if (!path && !isAbsolute) {
|
|
|
|
|
|
path = '.';
|
|
|
|
|
|
}
|
|
|
|
|
|
if (path && trailingSlash) {
|
|
|
|
|
|
path += '/';
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return (isAbsolute ? '/' : '') + path;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// posix version
|
|
|
|
|
|
exports.isAbsolute = function(path) {
|
|
|
|
|
|
return path.charAt(0) === '/';
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// posix version
|
|
|
|
|
|
exports.join = function() {
|
|
|
|
|
|
var paths = Array.prototype.slice.call(arguments, 0);
|
|
|
|
|
|
return exports.normalize(filter(paths, function(p, index) {
|
|
|
|
|
|
if (typeof p !== 'string') {
|
|
|
|
|
|
throw new TypeError('Arguments to path.join must be strings');
|
|
|
|
|
|
}
|
|
|
|
|
|
return p;
|
|
|
|
|
|
}).join('/'));
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// path.relative(from, to)
|
|
|
|
|
|
// posix version
|
|
|
|
|
|
exports.relative = function(from, to) {
|
|
|
|
|
|
from = exports.resolve(from).substr(1);
|
|
|
|
|
|
to = exports.resolve(to).substr(1);
|
|
|
|
|
|
|
|
|
|
|
|
function trim(arr) {
|
|
|
|
|
|
var start = 0;
|
|
|
|
|
|
for (; start < arr.length; start++) {
|
|
|
|
|
|
if (arr[start] !== '') break;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var end = arr.length - 1;
|
|
|
|
|
|
for (; end >= 0; end--) {
|
|
|
|
|
|
if (arr[end] !== '') break;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (start > end) return [];
|
|
|
|
|
|
return arr.slice(start, end - start + 1);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var fromParts = trim(from.split('/'));
|
|
|
|
|
|
var toParts = trim(to.split('/'));
|
|
|
|
|
|
|
|
|
|
|
|
var length = Math.min(fromParts.length, toParts.length);
|
|
|
|
|
|
var samePartsLength = length;
|
|
|
|
|
|
for (var i = 0; i < length; i++) {
|
|
|
|
|
|
if (fromParts[i] !== toParts[i]) {
|
|
|
|
|
|
samePartsLength = i;
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var outputParts = [];
|
|
|
|
|
|
for (var i = samePartsLength; i < fromParts.length; i++) {
|
|
|
|
|
|
outputParts.push('..');
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
outputParts = outputParts.concat(toParts.slice(samePartsLength));
|
|
|
|
|
|
|
|
|
|
|
|
return outputParts.join('/');
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
exports.sep = '/';
|
|
|
|
|
|
exports.delimiter = ':';
|
|
|
|
|
|
|
|
|
|
|
|
exports.dirname = function(path) {
|
|
|
|
|
|
var result = splitPath(path),
|
|
|
|
|
|
root = result[0],
|
|
|
|
|
|
dir = result[1];
|
|
|
|
|
|
|
|
|
|
|
|
if (!root && !dir) {
|
|
|
|
|
|
// No dirname whatsoever
|
|
|
|
|
|
return '.';
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (dir) {
|
|
|
|
|
|
// It has a dirname, strip trailing slash
|
|
|
|
|
|
dir = dir.substr(0, dir.length - 1);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return root + dir;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exports.basename = function(path, ext) {
|
|
|
|
|
|
var f = splitPath(path)[2];
|
|
|
|
|
|
// TODO: make this comparison case-insensitive on windows?
|
|
|
|
|
|
if (ext && f.substr(-1 * ext.length) === ext) {
|
|
|
|
|
|
f = f.substr(0, f.length - ext.length);
|
|
|
|
|
|
}
|
|
|
|
|
|
return f;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exports.extname = function(path) {
|
|
|
|
|
|
return splitPath(path)[3];
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
function filter (xs, f) {
|
|
|
|
|
|
if (xs.filter) return xs.filter(f);
|
|
|
|
|
|
var res = [];
|
|
|
|
|
|
for (var i = 0; i < xs.length; i++) {
|
|
|
|
|
|
if (f(xs[i], i, xs)) res.push(xs[i]);
|
|
|
|
|
|
}
|
|
|
|
|
|
return res;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// String.prototype.substr - negative index don't work in IE8
|
|
|
|
|
|
var substr = 'ab'.substr(-1) === 'b'
|
|
|
|
|
|
? function (str, start, len) { return str.substr(start, len) }
|
|
|
|
|
|
: function (str, start, len) {
|
|
|
|
|
|
if (start < 0) start = str.length + start;
|
|
|
|
|
|
return str.substr(start, len);
|
|
|
|
|
|
}
|
|
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
|
|
/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(25)))
|
|
|
|
|
|
|
|
|
|
|
|
/***/ },
|
|
|
|
|
|
/* 25 */
|
|
|
|
|
|
/***/ function(module, exports) {
|
|
|
|
|
|
|
|
|
|
|
|
// shim for using process in browser
|
|
|
|
|
|
|
|
|
|
|
|
var process = module.exports = {};
|
|
|
|
|
|
var queue = [];
|
|
|
|
|
|
var draining = false;
|
|
|
|
|
|
var currentQueue;
|
|
|
|
|
|
var queueIndex = -1;
|
|
|
|
|
|
|
|
|
|
|
|
function cleanUpNextTick() {
|
|
|
|
|
|
draining = false;
|
|
|
|
|
|
if (currentQueue.length) {
|
|
|
|
|
|
queue = currentQueue.concat(queue);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
queueIndex = -1;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (queue.length) {
|
|
|
|
|
|
drainQueue();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function drainQueue() {
|
|
|
|
|
|
if (draining) {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
var timeout = setTimeout(cleanUpNextTick);
|
|
|
|
|
|
draining = true;
|
|
|
|
|
|
|
|
|
|
|
|
var len = queue.length;
|
|
|
|
|
|
while(len) {
|
|
|
|
|
|
currentQueue = queue;
|
|
|
|
|
|
queue = [];
|
|
|
|
|
|
while (++queueIndex < len) {
|
|
|
|
|
|
if (currentQueue) {
|
|
|
|
|
|
currentQueue[queueIndex].run();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
queueIndex = -1;
|
|
|
|
|
|
len = queue.length;
|
|
|
|
|
|
}
|
|
|
|
|
|
currentQueue = null;
|
|
|
|
|
|
draining = false;
|
|
|
|
|
|
clearTimeout(timeout);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
process.nextTick = function (fun) {
|
|
|
|
|
|
var args = new Array(arguments.length - 1);
|
|
|
|
|
|
if (arguments.length > 1) {
|
|
|
|
|
|
for (var i = 1; i < arguments.length; i++) {
|
|
|
|
|
|
args[i - 1] = arguments[i];
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
queue.push(new Item(fun, args));
|
|
|
|
|
|
if (queue.length === 1 && !draining) {
|
|
|
|
|
|
setTimeout(drainQueue, 0);
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// v8 likes predictible objects
|
|
|
|
|
|
function Item(fun, array) {
|
|
|
|
|
|
this.fun = fun;
|
|
|
|
|
|
this.array = array;
|
|
|
|
|
|
}
|
|
|
|
|
|
Item.prototype.run = function () {
|
|
|
|
|
|
this.fun.apply(null, this.array);
|
|
|
|
|
|
};
|
|
|
|
|
|
process.title = 'browser';
|
|
|
|
|
|
process.browser = true;
|
|
|
|
|
|
process.env = {};
|
|
|
|
|
|
process.argv = [];
|
|
|
|
|
|
process.version = ''; // empty string to avoid regexp issues
|
|
|
|
|
|
process.versions = {};
|
|
|
|
|
|
|
|
|
|
|
|
function noop() {}
|
|
|
|
|
|
|
|
|
|
|
|
process.on = noop;
|
|
|
|
|
|
process.addListener = noop;
|
|
|
|
|
|
process.once = noop;
|
|
|
|
|
|
process.off = noop;
|
|
|
|
|
|
process.removeListener = noop;
|
|
|
|
|
|
process.removeAllListeners = noop;
|
|
|
|
|
|
process.emit = noop;
|
|
|
|
|
|
|
|
|
|
|
|
process.binding = function (name) {
|
|
|
|
|
|
throw new Error('process.binding is not supported');
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
process.cwd = function () { return '/' };
|
|
|
|
|
|
process.chdir = function (dir) {
|
|
|
|
|
|
throw new Error('process.chdir is not supported');
|
|
|
|
|
|
};
|
|
|
|
|
|
process.umask = function() { return 0; };
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/***/ },
|
|
|
|
|
|
/* 26 */
|
|
|
|
|
|
/***/ function(module, exports, __webpack_require__) {
|
|
|
|
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
|
|
var lib = __webpack_require__(27);
|
|
|
|
|
|
var env = __webpack_require__(28);
|
|
|
|
|
|
var Loader = __webpack_require__(37);
|
|
|
|
|
|
var loaders = __webpack_require__(32);
|
|
|
|
|
|
var precompile = __webpack_require__(32);
|
|
|
|
|
|
|
|
|
|
|
|
module.exports = {};
|
|
|
|
|
|
module.exports.Environment = env.Environment;
|
|
|
|
|
|
module.exports.Template = env.Template;
|
|
|
|
|
|
|
|
|
|
|
|
module.exports.Loader = Loader;
|
|
|
|
|
|
module.exports.FileSystemLoader = loaders.FileSystemLoader;
|
|
|
|
|
|
module.exports.PrecompiledLoader = loaders.PrecompiledLoader;
|
|
|
|
|
|
module.exports.WebLoader = loaders.WebLoader;
|
|
|
|
|
|
|
|
|
|
|
|
module.exports.compiler = __webpack_require__(32);
|
|
|
|
|
|
module.exports.parser = __webpack_require__(32);
|
|
|
|
|
|
module.exports.lexer = __webpack_require__(32);
|
|
|
|
|
|
module.exports.runtime = __webpack_require__(34);
|
|
|
|
|
|
module.exports.lib = lib;
|
|
|
|
|
|
module.exports.nodes = __webpack_require__(32);
|
|
|
|
|
|
|
|
|
|
|
|
module.exports.installJinjaCompat = __webpack_require__(38);
|
|
|
|
|
|
|
|
|
|
|
|
// A single instance of an environment, since this is so commonly used
|
|
|
|
|
|
|
|
|
|
|
|
var e;
|
|
|
|
|
|
module.exports.configure = function(templatesPath, opts) {
|
|
|
|
|
|
opts = opts || {};
|
|
|
|
|
|
if(lib.isObject(templatesPath)) {
|
|
|
|
|
|
opts = templatesPath;
|
|
|
|
|
|
templatesPath = null;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var TemplateLoader;
|
|
|
|
|
|
if(loaders.FileSystemLoader) {
|
|
|
|
|
|
TemplateLoader = new loaders.FileSystemLoader(templatesPath, {
|
|
|
|
|
|
watch: opts.watch,
|
|
|
|
|
|
noCache: opts.noCache
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
else if(loaders.WebLoader) {
|
|
|
|
|
|
TemplateLoader = new loaders.WebLoader(templatesPath, {
|
|
|
|
|
|
useCache: opts.web && opts.web.useCache,
|
|
|
|
|
|
async: opts.web && opts.web.async
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
e = new env.Environment(TemplateLoader, opts);
|
|
|
|
|
|
|
|
|
|
|
|
if(opts && opts.express) {
|
|
|
|
|
|
e.express(opts.express);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return e;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
module.exports.compile = function(src, env, path, eagerCompile) {
|
|
|
|
|
|
if(!e) {
|
|
|
|
|
|
module.exports.configure();
|
|
|
|
|
|
}
|
|
|
|
|
|
return new module.exports.Template(src, env, path, eagerCompile);
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
module.exports.render = function(name, ctx, cb) {
|
|
|
|
|
|
if(!e) {
|
|
|
|
|
|
module.exports.configure();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return e.render(name, ctx, cb);
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
module.exports.renderString = function(src, ctx, cb) {
|
|
|
|
|
|
if(!e) {
|
|
|
|
|
|
module.exports.configure();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return e.renderString(src, ctx, cb);
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
if(precompile) {
|
|
|
|
|
|
module.exports.precompile = precompile.precompile;
|
|
|
|
|
|
module.exports.precompileString = precompile.precompileString;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/***/ },
|
|
|
|
|
|
/* 27 */
|
|
|
|
|
|
/***/ function(module, exports) {
|
|
|
|
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
|
|
var ArrayProto = Array.prototype;
|
|
|
|
|
|
var ObjProto = Object.prototype;
|
|
|
|
|
|
|
|
|
|
|
|
var escapeMap = {
|
|
|
|
|
|
'&': '&',
|
|
|
|
|
|
'"': '"',
|
|
|
|
|
|
'\'': ''',
|
|
|
|
|
|
'<': '<',
|
|
|
|
|
|
'>': '>'
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
var escapeRegex = /[&"'<>]/g;
|
|
|
|
|
|
|
|
|
|
|
|
var lookupEscape = function(ch) {
|
|
|
|
|
|
return escapeMap[ch];
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
var exports = module.exports = {};
|
|
|
|
|
|
|
|
|
|
|
|
exports.prettifyError = function(path, withInternals, err) {
|
|
|
|
|
|
// jshint -W022
|
|
|
|
|
|
// http://jslinterrors.com/do-not-assign-to-the-exception-parameter
|
|
|
|
|
|
if (!err.Update) {
|
|
|
|
|
|
// not one of ours, cast it
|
|
|
|
|
|
err = new exports.TemplateError(err);
|
|
|
|
|
|
}
|
|
|
|
|
|
err.Update(path);
|
|
|
|
|
|
|
|
|
|
|
|
// Unless they marked the dev flag, show them a trace from here
|
|
|
|
|
|
if (!withInternals) {
|
|
|
|
|
|
var old = err;
|
|
|
|
|
|
err = new Error(old.message);
|
|
|
|
|
|
err.name = old.name;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return err;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
exports.TemplateError = function(message, lineno, colno) {
|
|
|
|
|
|
var err = this;
|
|
|
|
|
|
|
|
|
|
|
|
if (message instanceof Error) { // for casting regular js errors
|
|
|
|
|
|
err = message;
|
|
|
|
|
|
message = message.name + ': ' + message.message;
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
if(err.name = '') {}
|
|
|
|
|
|
}
|
|
|
|
|
|
catch(e) {
|
|
|
|
|
|
// If we can't set the name of the error object in this
|
|
|
|
|
|
// environment, don't use it
|
|
|
|
|
|
err = this;
|
|
|
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
|
|
|
if(Error.captureStackTrace) {
|
|
|
|
|
|
Error.captureStackTrace(err);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
err.name = 'Template render error';
|
|
|
|
|
|
err.message = message;
|
|
|
|
|
|
err.lineno = lineno;
|
|
|
|
|
|
err.colno = colno;
|
|
|
|
|
|
err.firstUpdate = true;
|
|
|
|
|
|
|
|
|
|
|
|
err.Update = function(path) {
|
|
|
|
|
|
var message = '(' + (path || 'unknown path') + ')';
|
|
|
|
|
|
|
|
|
|
|
|
// only show lineno + colno next to path of template
|
|
|
|
|
|
// where error occurred
|
|
|
|
|
|
if (this.firstUpdate) {
|
|
|
|
|
|
if(this.lineno && this.colno) {
|
|
|
|
|
|
message += ' [Line ' + this.lineno + ', Column ' + this.colno + ']';
|
|
|
|
|
|
}
|
|
|
|
|
|
else if(this.lineno) {
|
|
|
|
|
|
message += ' [Line ' + this.lineno + ']';
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
message += '\n ';
|
|
|
|
|
|
if (this.firstUpdate) {
|
|
|
|
|
|
message += ' ';
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
this.message = message + (this.message || '');
|
|
|
|
|
|
this.firstUpdate = false;
|
|
|
|
|
|
return this;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
return err;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
exports.TemplateError.prototype = Error.prototype;
|
|
|
|
|
|
|
|
|
|
|
|
exports.escape = function(val) {
|
|
|
|
|
|
return val.replace(escapeRegex, lookupEscape);
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
exports.isFunction = function(obj) {
|
|
|
|
|
|
return ObjProto.toString.call(obj) === '[object Function]';
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
exports.isArray = Array.isArray || function(obj) {
|
|
|
|
|
|
return ObjProto.toString.call(obj) === '[object Array]';
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
exports.isString = function(obj) {
|
|
|
|
|
|
return ObjProto.toString.call(obj) === '[object String]';
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
exports.isObject = function(obj) {
|
|
|
|
|
|
return ObjProto.toString.call(obj) === '[object Object]';
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
exports.groupBy = function(obj, val) {
|
|
|
|
|
|
var result = {};
|
|
|
|
|
|
var iterator = exports.isFunction(val) ? val : function(obj) { return obj[val]; };
|
|
|
|
|
|
for(var i=0; i<obj.length; i++) {
|
|
|
|
|
|
var value = obj[i];
|
|
|
|
|
|
var key = iterator(value, i);
|
|
|
|
|
|
(result[key] || (result[key] = [])).push(value);
|
|
|
|
|
|
}
|
|
|
|
|
|
return result;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
exports.toArray = function(obj) {
|
|
|
|
|
|
return Array.prototype.slice.call(obj);
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
exports.without = function(array) {
|
|
|
|
|
|
var result = [];
|
|
|
|
|
|
if (!array) {
|
|
|
|
|
|
return result;
|
|
|
|
|
|
}
|
|
|
|
|
|
var index = -1,
|
|
|
|
|
|
length = array.length,
|
|
|
|
|
|
contains = exports.toArray(arguments).slice(1);
|
|
|
|
|
|
|
|
|
|
|
|
while(++index < length) {
|
|
|
|
|
|
if(exports.indexOf(contains, array[index]) === -1) {
|
|
|
|
|
|
result.push(array[index]);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return result;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
exports.extend = function(obj, obj2) {
|
|
|
|
|
|
for(var k in obj2) {
|
|
|
|
|
|
obj[k] = obj2[k];
|
|
|
|
|
|
}
|
|
|
|
|
|
return obj;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
exports.repeat = function(char_, n) {
|
|
|
|
|
|
var str = '';
|
|
|
|
|
|
for(var i=0; i<n; i++) {
|
|
|
|
|
|
str += char_;
|
|
|
|
|
|
}
|
|
|
|
|
|
return str;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
exports.each = function(obj, func, context) {
|
|
|
|
|
|
if(obj == null) {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if(ArrayProto.each && obj.each === ArrayProto.each) {
|
|
|
|
|
|
obj.forEach(func, context);
|
|
|
|
|
|
}
|
|
|
|
|
|
else if(obj.length === +obj.length) {
|
|
|
|
|
|
for(var i=0, l=obj.length; i<l; i++) {
|
|
|
|
|
|
func.call(context, obj[i], i, obj);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
exports.map = function(obj, func) {
|
|
|
|
|
|
var results = [];
|
|
|
|
|
|
if(obj == null) {
|
|
|
|
|
|
return results;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if(ArrayProto.map && obj.map === ArrayProto.map) {
|
|
|
|
|
|
return obj.map(func);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
for(var i=0; i<obj.length; i++) {
|
|
|
|
|
|
results[results.length] = func(obj[i], i);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if(obj.length === +obj.length) {
|
|
|
|
|
|
results.length = obj.length;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return results;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
exports.asyncIter = function(arr, iter, cb) {
|
|
|
|
|
|
var i = -1;
|
|
|
|
|
|
|
|
|
|
|
|
function next() {
|
|
|
|
|
|
i++;
|
|
|
|
|
|
|
|
|
|
|
|
if(i < arr.length) {
|
|
|
|
|
|
iter(arr[i], i, next, cb);
|
|
|
|
|
|
}
|
|
|
|
|
|
else {
|
|
|
|
|
|
cb();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
next();
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
exports.asyncFor = function(obj, iter, cb) {
|
|
|
|
|
|
var keys = exports.keys(obj);
|
|
|
|
|
|
var len = keys.length;
|
|
|
|
|
|
var i = -1;
|
|
|
|
|
|
|
|
|
|
|
|
function next() {
|
|
|
|
|
|
i++;
|
|
|
|
|
|
var k = keys[i];
|
|
|
|
|
|
|
|
|
|
|
|
if(i < len) {
|
|
|
|
|
|
iter(k, obj[k], i, len, next);
|
|
|
|
|
|
}
|
|
|
|
|
|
else {
|
|
|
|
|
|
cb();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
next();
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/indexOf#Polyfill
|
|
|
|
|
|
exports.indexOf = Array.prototype.indexOf ?
|
|
|
|
|
|
function (arr, searchElement, fromIndex) {
|
|
|
|
|
|
return Array.prototype.indexOf.call(arr, searchElement, fromIndex);
|
|
|
|
|
|
} :
|
|
|
|
|
|
function (arr, searchElement, fromIndex) {
|
|
|
|
|
|
var length = this.length >>> 0; // Hack to convert object.length to a UInt32
|
|
|
|
|
|
|
|
|
|
|
|
fromIndex = +fromIndex || 0;
|
|
|
|
|
|
|
|
|
|
|
|
if(Math.abs(fromIndex) === Infinity) {
|
|
|
|
|
|
fromIndex = 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if(fromIndex < 0) {
|
|
|
|
|
|
fromIndex += length;
|
|
|
|
|
|
if (fromIndex < 0) {
|
|
|
|
|
|
fromIndex = 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
for(;fromIndex < length; fromIndex++) {
|
|
|
|
|
|
if (arr[fromIndex] === searchElement) {
|
|
|
|
|
|
return fromIndex;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
if(!Array.prototype.map) {
|
|
|
|
|
|
Array.prototype.map = function() {
|
|
|
|
|
|
throw new Error('map is unimplemented for this js engine');
|
|
|
|
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
exports.keys = function(obj) {
|
|
|
|
|
|
if(Object.prototype.keys) {
|
|
|
|
|
|
return obj.keys();
|
|
|
|
|
|
}
|
|
|
|
|
|
else {
|
|
|
|
|
|
var keys = [];
|
|
|
|
|
|
for(var k in obj) {
|
|
|
|
|
|
if(obj.hasOwnProperty(k)) {
|
|
|
|
|
|
keys.push(k);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return keys;
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/***/ },
|
|
|
|
|
|
/* 28 */
|
|
|
|
|
|
/***/ function(module, exports, __webpack_require__) {
|
|
|
|
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
|
|
var path = __webpack_require__(24);
|
|
|
|
|
|
var asap = __webpack_require__(29);
|
|
|
|
|
|
var lib = __webpack_require__(27);
|
|
|
|
|
|
var Obj = __webpack_require__(31);
|
|
|
|
|
|
var compiler = __webpack_require__(32);
|
|
|
|
|
|
var builtin_filters = __webpack_require__(33);
|
|
|
|
|
|
var builtin_loaders = __webpack_require__(32);
|
|
|
|
|
|
var runtime = __webpack_require__(34);
|
|
|
|
|
|
var globals = __webpack_require__(35);
|
|
|
|
|
|
var Frame = runtime.Frame;
|
|
|
|
|
|
var Template;
|
|
|
|
|
|
|
|
|
|
|
|
// Unconditionally load in this loader, even if no other ones are
|
|
|
|
|
|
// included (possible in the slim browser build)
|
|
|
|
|
|
builtin_loaders.PrecompiledLoader = __webpack_require__(36);
|
|
|
|
|
|
|
|
|
|
|
|
// If the user is using the async API, *always* call it
|
|
|
|
|
|
// asynchronously even if the template was synchronous.
|
|
|
|
|
|
function callbackAsap(cb, err, res) {
|
|
|
|
|
|
asap(function() { cb(err, res); });
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var Environment = Obj.extend({
|
|
|
|
|
|
init: function(loaders, opts) {
|
|
|
|
|
|
// The dev flag determines the trace that'll be shown on errors.
|
|
|
|
|
|
// If set to true, returns the full trace from the error point,
|
|
|
|
|
|
// otherwise will return trace starting from Template.render
|
|
|
|
|
|
// (the full trace from within nunjucks may confuse developers using
|
|
|
|
|
|
// the library)
|
|
|
|
|
|
// defaults to false
|
|
|
|
|
|
opts = this.opts = opts || {};
|
|
|
|
|
|
this.opts.dev = !!opts.dev;
|
|
|
|
|
|
|
|
|
|
|
|
// The autoescape flag sets global autoescaping. If true,
|
|
|
|
|
|
// every string variable will be escaped by default.
|
|
|
|
|
|
// If false, strings can be manually escaped using the `escape` filter.
|
|
|
|
|
|
// defaults to true
|
|
|
|
|
|
this.opts.autoescape = opts.autoescape != null ? opts.autoescape : true;
|
|
|
|
|
|
|
|
|
|
|
|
// If true, this will make the system throw errors if trying
|
|
|
|
|
|
// to output a null or undefined value
|
|
|
|
|
|
this.opts.throwOnUndefined = !!opts.throwOnUndefined;
|
|
|
|
|
|
this.opts.trimBlocks = !!opts.trimBlocks;
|
|
|
|
|
|
this.opts.lstripBlocks = !!opts.lstripBlocks;
|
|
|
|
|
|
|
|
|
|
|
|
this.loaders = [];
|
|
|
|
|
|
|
|
|
|
|
|
if(!loaders) {
|
|
|
|
|
|
// The filesystem loader is only available server-side
|
|
|
|
|
|
if(builtin_loaders.FileSystemLoader) {
|
|
|
|
|
|
this.loaders = [new builtin_loaders.FileSystemLoader('views')];
|
|
|
|
|
|
}
|
|
|
|
|
|
else if(builtin_loaders.WebLoader) {
|
|
|
|
|
|
this.loaders = [new builtin_loaders.WebLoader('/views')];
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else {
|
|
|
|
|
|
this.loaders = lib.isArray(loaders) ? loaders : [loaders];
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// It's easy to use precompiled templates: just include them
|
|
|
|
|
|
// before you configure nunjucks and this will automatically
|
|
|
|
|
|
// pick it up and use it
|
|
|
|
|
|
if((true) && window.nunjucksPrecompiled) {
|
|
|
|
|
|
this.loaders.unshift(
|
|
|
|
|
|
new builtin_loaders.PrecompiledLoader(window.nunjucksPrecompiled)
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
this.initCache();
|
|
|
|
|
|
|
|
|
|
|
|
this.globals = globals();
|
|
|
|
|
|
this.filters = {};
|
|
|
|
|
|
this.asyncFilters = [];
|
|
|
|
|
|
this.extensions = {};
|
|
|
|
|
|
this.extensionsList = [];
|
|
|
|
|
|
|
|
|
|
|
|
for(var name in builtin_filters) {
|
|
|
|
|
|
this.addFilter(name, builtin_filters[name]);
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
initCache: function() {
|
|
|
|
|
|
// Caching and cache busting
|
|
|
|
|
|
lib.each(this.loaders, function(loader) {
|
|
|
|
|
|
loader.cache = {};
|
|
|
|
|
|
|
|
|
|
|
|
if(typeof loader.on === 'function') {
|
|
|
|
|
|
loader.on('update', function(template) {
|
|
|
|
|
|
loader.cache[template] = null;
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
addExtension: function(name, extension) {
|
|
|
|
|
|
extension._name = name;
|
|
|
|
|
|
this.extensions[name] = extension;
|
|
|
|
|
|
this.extensionsList.push(extension);
|
|
|
|
|
|
return this;
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
removeExtension: function(name) {
|
|
|
|
|
|
var extension = this.getExtension(name);
|
|
|
|
|
|
if (!extension) return;
|
|
|
|
|
|
|
|
|
|
|
|
this.extensionsList = lib.without(this.extensionsList, extension);
|
|
|
|
|
|
delete this.extensions[name];
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
getExtension: function(name) {
|
|
|
|
|
|
return this.extensions[name];
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
hasExtension: function(name) {
|
|
|
|
|
|
return !!this.extensions[name];
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
addGlobal: function(name, value) {
|
|
|
|
|
|
this.globals[name] = value;
|
|
|
|
|
|
return this;
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
getGlobal: function(name) {
|
|
|
|
|
|
if(!this.globals[name]) {
|
|
|
|
|
|
throw new Error('global not found: ' + name);
|
|
|
|
|
|
}
|
|
|
|
|
|
return this.globals[name];
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
addFilter: function(name, func, async) {
|
|
|
|
|
|
var wrapped = func;
|
|
|
|
|
|
|
|
|
|
|
|
if(async) {
|
|
|
|
|
|
this.asyncFilters.push(name);
|
|
|
|
|
|
}
|
|
|
|
|
|
this.filters[name] = wrapped;
|
|
|
|
|
|
return this;
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
getFilter: function(name) {
|
|
|
|
|
|
if(!this.filters[name]) {
|
|
|
|
|
|
throw new Error('filter not found: ' + name);
|
|
|
|
|
|
}
|
|
|
|
|
|
return this.filters[name];
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
resolveTemplate: function(loader, parentName, filename) {
|
|
|
|
|
|
var isRelative = (loader.isRelative && parentName)? loader.isRelative(filename) : false;
|
|
|
|
|
|
return (isRelative && loader.resolve)? loader.resolve(parentName, filename) : filename;
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
getTemplate: function(name, eagerCompile, parentName, ignoreMissing, cb) {
|
|
|
|
|
|
var that = this;
|
|
|
|
|
|
var tmpl = null;
|
|
|
|
|
|
if(name && name.raw) {
|
|
|
|
|
|
// this fixes autoescape for templates referenced in symbols
|
|
|
|
|
|
name = name.raw;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if(lib.isFunction(parentName)) {
|
|
|
|
|
|
cb = parentName;
|
|
|
|
|
|
parentName = null;
|
|
|
|
|
|
eagerCompile = eagerCompile || false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if(lib.isFunction(eagerCompile)) {
|
|
|
|
|
|
cb = eagerCompile;
|
|
|
|
|
|
eagerCompile = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (name instanceof Template) {
|
|
|
|
|
|
tmpl = name;
|
|
|
|
|
|
}
|
|
|
|
|
|
else if(typeof name !== 'string') {
|
|
|
|
|
|
throw new Error('template names must be a string: ' + name);
|
|
|
|
|
|
}
|
|
|
|
|
|
else {
|
|
|
|
|
|
for (var i = 0; i < this.loaders.length; i++) {
|
|
|
|
|
|
var _name = this.resolveTemplate(this.loaders[i], parentName, name);
|
|
|
|
|
|
tmpl = this.loaders[i].cache[_name];
|
|
|
|
|
|
if (tmpl) break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if(tmpl) {
|
|
|
|
|
|
if(eagerCompile) {
|
|
|
|
|
|
tmpl.compile();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if(cb) {
|
|
|
|
|
|
cb(null, tmpl);
|
|
|
|
|
|
}
|
|
|
|
|
|
else {
|
|
|
|
|
|
return tmpl;
|
|
|
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
|
|
|
var syncResult;
|
|
|
|
|
|
var _this = this;
|
|
|
|
|
|
|
|
|
|
|
|
var createTemplate = function(err, info) {
|
|
|
|
|
|
if(!info && !err) {
|
|
|
|
|
|
if(!ignoreMissing) {
|
|
|
|
|
|
err = new Error('template not found: ' + name);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (err) {
|
|
|
|
|
|
if(cb) {
|
|
|
|
|
|
cb(err);
|
|
|
|
|
|
}
|
|
|
|
|
|
else {
|
|
|
|
|
|
throw err;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else {
|
|
|
|
|
|
var tmpl;
|
|
|
|
|
|
if(info) {
|
|
|
|
|
|
tmpl = new Template(info.src, _this,
|
|
|
|
|
|
info.path, eagerCompile);
|
|
|
|
|
|
|
|
|
|
|
|
if(!info.noCache) {
|
|
|
|
|
|
info.loader.cache[name] = tmpl;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else {
|
|
|
|
|
|
tmpl = new Template('', _this,
|
|
|
|
|
|
'', eagerCompile);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if(cb) {
|
|
|
|
|
|
cb(null, tmpl);
|
|
|
|
|
|
}
|
|
|
|
|
|
else {
|
|
|
|
|
|
syncResult = tmpl;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
lib.asyncIter(this.loaders, function(loader, i, next, done) {
|
|
|
|
|
|
function handle(err, src) {
|
|
|
|
|
|
if(err) {
|
|
|
|
|
|
done(err);
|
|
|
|
|
|
}
|
|
|
|
|
|
else if(src) {
|
|
|
|
|
|
src.loader = loader;
|
|
|
|
|
|
done(null, src);
|
|
|
|
|
|
}
|
|
|
|
|
|
else {
|
|
|
|
|
|
next();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Resolve name relative to parentName
|
|
|
|
|
|
name = that.resolveTemplate(loader, parentName, name);
|
|
|
|
|
|
|
|
|
|
|
|
if(loader.async) {
|
|
|
|
|
|
loader.getSource(name, handle);
|
|
|
|
|
|
}
|
|
|
|
|
|
else {
|
|
|
|
|
|
handle(null, loader.getSource(name));
|
|
|
|
|
|
}
|
|
|
|
|
|
}, createTemplate);
|
|
|
|
|
|
|
|
|
|
|
|
return syncResult;
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
express: function(app) {
|
|
|
|
|
|
var env = this;
|
|
|
|
|
|
|
|
|
|
|
|
function NunjucksView(name, opts) {
|
|
|
|
|
|
this.name = name;
|
|
|
|
|
|
this.path = name;
|
|
|
|
|
|
this.defaultEngine = opts.defaultEngine;
|
|
|
|
|
|
this.ext = path.extname(name);
|
|
|
|
|
|
if (!this.ext && !this.defaultEngine) throw new Error('No default engine was specified and no extension was provided.');
|
|
|
|
|
|
if (!this.ext) this.name += (this.ext = ('.' !== this.defaultEngine[0] ? '.' : '') + this.defaultEngine);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NunjucksView.prototype.render = function(opts, cb) {
|
|
|
|
|
|
env.render(this.name, opts, cb);
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
app.set('view', NunjucksView);
|
|
|
|
|
|
return this;
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
render: function(name, ctx, cb) {
|
|
|
|
|
|
if(lib.isFunction(ctx)) {
|
|
|
|
|
|
cb = ctx;
|
|
|
|
|
|
ctx = null;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// We support a synchronous API to make it easier to migrate
|
|
|
|
|
|
// existing code to async. This works because if you don't do
|
|
|
|
|
|
// anything async work, the whole thing is actually run
|
|
|
|
|
|
// synchronously.
|
|
|
|
|
|
var syncResult = null;
|
|
|
|
|
|
|
|
|
|
|
|
this.getTemplate(name, function(err, tmpl) {
|
|
|
|
|
|
if(err && cb) {
|
|
|
|
|
|
callbackAsap(cb, err);
|
|
|
|
|
|
}
|
|
|
|
|
|
else if(err) {
|
|
|
|
|
|
throw err;
|
|
|
|
|
|
}
|
|
|
|
|
|
else {
|
|
|
|
|
|
syncResult = tmpl.render(ctx, cb);
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
return syncResult;
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
renderString: function(src, ctx, opts, cb) {
|
|
|
|
|
|
if(lib.isFunction(opts)) {
|
|
|
|
|
|
cb = opts;
|
|
|
|
|
|
opts = {};
|
|
|
|
|
|
}
|
|
|
|
|
|
opts = opts || {};
|
|
|
|
|
|
|
|
|
|
|
|
var tmpl = new Template(src, this, opts.path);
|
|
|
|
|
|
return tmpl.render(ctx, cb);
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
var Context = Obj.extend({
|
|
|
|
|
|
init: function(ctx, blocks, env) {
|
|
|
|
|
|
// Has to be tied to an environment so we can tap into its globals.
|
|
|
|
|
|
this.env = env || new Environment();
|
|
|
|
|
|
|
|
|
|
|
|
// Make a duplicate of ctx
|
|
|
|
|
|
this.ctx = {};
|
|
|
|
|
|
for(var k in ctx) {
|
|
|
|
|
|
if(ctx.hasOwnProperty(k)) {
|
|
|
|
|
|
this.ctx[k] = ctx[k];
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
this.blocks = {};
|
|
|
|
|
|
this.exported = [];
|
|
|
|
|
|
|
|
|
|
|
|
for(var name in blocks) {
|
|
|
|
|
|
this.addBlock(name, blocks[name]);
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
lookup: function(name) {
|
|
|
|
|
|
// This is one of the most called functions, so optimize for
|
|
|
|
|
|
// the typical case where the name isn't in the globals
|
|
|
|
|
|
if(name in this.env.globals && !(name in this.ctx)) {
|
|
|
|
|
|
return this.env.globals[name];
|
|
|
|
|
|
}
|
|
|
|
|
|
else {
|
|
|
|
|
|
return this.ctx[name];
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
setVariable: function(name, val) {
|
|
|
|
|
|
this.ctx[name] = val;
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
getVariables: function() {
|
|
|
|
|
|
return this.ctx;
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
addBlock: function(name, block) {
|
|
|
|
|
|
this.blocks[name] = this.blocks[name] || [];
|
|
|
|
|
|
this.blocks[name].push(block);
|
|
|
|
|
|
return this;
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
getBlock: function(name) {
|
|
|
|
|
|
if(!this.blocks[name]) {
|
|
|
|
|
|
throw new Error('unknown block "' + name + '"');
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return this.blocks[name][0];
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
getSuper: function(env, name, block, frame, runtime, cb) {
|
|
|
|
|
|
var idx = lib.indexOf(this.blocks[name] || [], block);
|
|
|
|
|
|
var blk = this.blocks[name][idx + 1];
|
|
|
|
|
|
var context = this;
|
|
|
|
|
|
|
|
|
|
|
|
if(idx === -1 || !blk) {
|
|
|
|
|
|
throw new Error('no super block available for "' + name + '"');
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
blk(env, context, frame, runtime, cb);
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
addExport: function(name) {
|
|
|
|
|
|
this.exported.push(name);
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
getExported: function() {
|
|
|
|
|
|
var exported = {};
|
|
|
|
|
|
for(var i=0; i<this.exported.length; i++) {
|
|
|
|
|
|
var name = this.exported[i];
|
|
|
|
|
|
exported[name] = this.ctx[name];
|
|
|
|
|
|
}
|
|
|
|
|
|
return exported;
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
Template = Obj.extend({
|
|
|
|
|
|
init: function (src, env, path, eagerCompile) {
|
|
|
|
|
|
this.env = env || new Environment();
|
|
|
|
|
|
|
|
|
|
|
|
if(lib.isObject(src)) {
|
|
|
|
|
|
switch(src.type) {
|
|
|
|
|
|
case 'code': this.tmplProps = src.obj; break;
|
|
|
|
|
|
case 'string': this.tmplStr = src.obj; break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else if(lib.isString(src)) {
|
|
|
|
|
|
this.tmplStr = src;
|
|
|
|
|
|
}
|
|
|
|
|
|
else {
|
|
|
|
|
|
throw new Error('src must be a string or an object describing ' +
|
|
|
|
|
|
'the source');
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
this.path = path;
|
|
|
|
|
|
|
|
|
|
|
|
if(eagerCompile) {
|
|
|
|
|
|
var _this = this;
|
|
|
|
|
|
try {
|
|
|
|
|
|
_this._compile();
|
|
|
|
|
|
}
|
|
|
|
|
|
catch(err) {
|
|
|
|
|
|
throw lib.prettifyError(this.path, this.env.dev, err);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else {
|
|
|
|
|
|
this.compiled = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
render: function(ctx, parentFrame, cb) {
|
|
|
|
|
|
if (typeof ctx === 'function') {
|
|
|
|
|
|
cb = ctx;
|
|
|
|
|
|
ctx = {};
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (typeof parentFrame === 'function') {
|
|
|
|
|
|
cb = parentFrame;
|
|
|
|
|
|
parentFrame = null;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var forceAsync = true;
|
|
|
|
|
|
if(parentFrame) {
|
|
|
|
|
|
// If there is a frame, we are being called from internal
|
|
|
|
|
|
// code of another template, and the internal system
|
|
|
|
|
|
// depends on the sync/async nature of the parent template
|
|
|
|
|
|
// to be inherited, so force an async callback
|
|
|
|
|
|
forceAsync = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var _this = this;
|
|
|
|
|
|
// Catch compile errors for async rendering
|
|
|
|
|
|
try {
|
|
|
|
|
|
_this.compile();
|
|
|
|
|
|
} catch (_err) {
|
|
|
|
|
|
var err = lib.prettifyError(this.path, this.env.dev, _err);
|
|
|
|
|
|
if (cb) return callbackAsap(cb, err);
|
|
|
|
|
|
else throw err;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var context = new Context(ctx || {}, _this.blocks, _this.env);
|
|
|
|
|
|
var frame = parentFrame ? parentFrame.push() : new Frame();
|
|
|
|
|
|
frame.topLevel = true;
|
|
|
|
|
|
var syncResult = null;
|
|
|
|
|
|
|
|
|
|
|
|
_this.rootRenderFunc(
|
|
|
|
|
|
_this.env,
|
|
|
|
|
|
context,
|
|
|
|
|
|
frame || new Frame(),
|
|
|
|
|
|
runtime,
|
|
|
|
|
|
function(err, res) {
|
|
|
|
|
|
if(err) {
|
|
|
|
|
|
err = lib.prettifyError(_this.path, _this.env.dev, err);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if(cb) {
|
|
|
|
|
|
if(forceAsync) {
|
|
|
|
|
|
callbackAsap(cb, err, res);
|
|
|
|
|
|
}
|
|
|
|
|
|
else {
|
|
|
|
|
|
cb(err, res);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else {
|
|
|
|
|
|
if(err) { throw err; }
|
|
|
|
|
|
syncResult = res;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
return syncResult;
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
getExported: function(ctx, parentFrame, cb) {
|
|
|
|
|
|
if (typeof ctx === 'function') {
|
|
|
|
|
|
cb = ctx;
|
|
|
|
|
|
ctx = {};
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (typeof parentFrame === 'function') {
|
|
|
|
|
|
cb = parentFrame;
|
|
|
|
|
|
parentFrame = null;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Catch compile errors for async rendering
|
|
|
|
|
|
try {
|
|
|
|
|
|
this.compile();
|
|
|
|
|
|
} catch (e) {
|
|
|
|
|
|
if (cb) return cb(e);
|
|
|
|
|
|
else throw e;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var frame = parentFrame ? parentFrame.push() : new Frame();
|
|
|
|
|
|
frame.topLevel = true;
|
|
|
|
|
|
|
|
|
|
|
|
// Run the rootRenderFunc to populate the context with exported vars
|
|
|
|
|
|
var context = new Context(ctx || {}, this.blocks, this.env);
|
|
|
|
|
|
this.rootRenderFunc(this.env,
|
|
|
|
|
|
context,
|
|
|
|
|
|
frame,
|
|
|
|
|
|
runtime,
|
|
|
|
|
|
function(err) {
|
|
|
|
|
|
if ( err ) {
|
|
|
|
|
|
cb(err, null);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
cb(null, context.getExported());
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
compile: function() {
|
|
|
|
|
|
if(!this.compiled) {
|
|
|
|
|
|
this._compile();
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
_compile: function() {
|
|
|
|
|
|
var props;
|
|
|
|
|
|
|
|
|
|
|
|
if(this.tmplProps) {
|
|
|
|
|
|
props = this.tmplProps;
|
|
|
|
|
|
}
|
|
|
|
|
|
else {
|
|
|
|
|
|
var source = compiler.compile(this.tmplStr,
|
|
|
|
|
|
this.env.asyncFilters,
|
|
|
|
|
|
this.env.extensionsList,
|
|
|
|
|
|
this.path,
|
|
|
|
|
|
this.env.opts);
|
|
|
|
|
|
|
|
|
|
|
|
/* jslint evil: true */
|
|
|
|
|
|
var func = new Function(source);
|
|
|
|
|
|
props = func();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
this.blocks = this._getBlocks(props);
|
|
|
|
|
|
this.rootRenderFunc = props.root;
|
|
|
|
|
|
this.compiled = true;
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
_getBlocks: function(props) {
|
|
|
|
|
|
var blocks = {};
|
|
|
|
|
|
|
|
|
|
|
|
for(var k in props) {
|
|
|
|
|
|
if(k.slice(0, 2) === 'b_') {
|
|
|
|
|
|
blocks[k.slice(2)] = props[k];
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return blocks;
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
|
|
Environment: Environment,
|
|
|
|
|
|
Template: Template
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/***/ },
|
|
|
|
|
|
/* 29 */
|
|
|
|
|
|
/***/ function(module, exports, __webpack_require__) {
|
|
|
|
|
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
|
|
|
|
// rawAsap provides everything we need except exception management.
|
|
|
|
|
|
var rawAsap = __webpack_require__(30);
|
|
|
|
|
|
// RawTasks are recycled to reduce GC churn.
|
|
|
|
|
|
var freeTasks = [];
|
|
|
|
|
|
// We queue errors to ensure they are thrown in right order (FIFO).
|
|
|
|
|
|
// Array-as-queue is good enough here, since we are just dealing with exceptions.
|
|
|
|
|
|
var pendingErrors = [];
|
|
|
|
|
|
var requestErrorThrow = rawAsap.makeRequestCallFromTimer(throwFirstError);
|
|
|
|
|
|
|
|
|
|
|
|
function throwFirstError() {
|
|
|
|
|
|
if (pendingErrors.length) {
|
|
|
|
|
|
throw pendingErrors.shift();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Calls a task as soon as possible after returning, in its own event, with priority
|
|
|
|
|
|
* over other events like animation, reflow, and repaint. An error thrown from an
|
|
|
|
|
|
* event will not interrupt, nor even substantially slow down the processing of
|
|
|
|
|
|
* other events, but will be rather postponed to a lower priority event.
|
|
|
|
|
|
* @param {{call}} task A callable object, typically a function that takes no
|
|
|
|
|
|
* arguments.
|
|
|
|
|
|
*/
|
|
|
|
|
|
module.exports = asap;
|
|
|
|
|
|
function asap(task) {
|
|
|
|
|
|
var rawTask;
|
|
|
|
|
|
if (freeTasks.length) {
|
|
|
|
|
|
rawTask = freeTasks.pop();
|
|
|
|
|
|
} else {
|
|
|
|
|
|
rawTask = new RawTask();
|
|
|
|
|
|
}
|
|
|
|
|
|
rawTask.task = task;
|
|
|
|
|
|
rawAsap(rawTask);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// We wrap tasks with recyclable task objects. A task object implements
|
|
|
|
|
|
// `call`, just like a function.
|
|
|
|
|
|
function RawTask() {
|
|
|
|
|
|
this.task = null;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// The sole purpose of wrapping the task is to catch the exception and recycle
|
|
|
|
|
|
// the task object after its single use.
|
|
|
|
|
|
RawTask.prototype.call = function () {
|
|
|
|
|
|
try {
|
|
|
|
|
|
this.task.call();
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
if (asap.onerror) {
|
|
|
|
|
|
// This hook exists purely for testing purposes.
|
|
|
|
|
|
// Its name will be periodically randomized to break any code that
|
|
|
|
|
|
// depends on its existence.
|
|
|
|
|
|
asap.onerror(error);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
// In a web browser, exceptions are not fatal. However, to avoid
|
|
|
|
|
|
// slowing down the queue of pending tasks, we rethrow the error in a
|
|
|
|
|
|
// lower priority turn.
|
|
|
|
|
|
pendingErrors.push(error);
|
|
|
|
|
|
requestErrorThrow();
|
|
|
|
|
|
}
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
this.task = null;
|
|
|
|
|
|
freeTasks[freeTasks.length] = this;
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/***/ },
|
|
|
|
|
|
/* 30 */
|
|
|
|
|
|
/***/ function(module, exports) {
|
|
|
|
|
|
|
|
|
|
|
|
/* WEBPACK VAR INJECTION */(function(global) {"use strict";
|
|
|
|
|
|
|
|
|
|
|
|
// Use the fastest means possible to execute a task in its own turn, with
|
|
|
|
|
|
// priority over other events including IO, animation, reflow, and redraw
|
|
|
|
|
|
// events in browsers.
|
|
|
|
|
|
//
|
|
|
|
|
|
// An exception thrown by a task will permanently interrupt the processing of
|
|
|
|
|
|
// subsequent tasks. The higher level `asap` function ensures that if an
|
|
|
|
|
|
// exception is thrown by a task, that the task queue will continue flushing as
|
|
|
|
|
|
// soon as possible, but if you use `rawAsap` directly, you are responsible to
|
|
|
|
|
|
// either ensure that no exceptions are thrown from your task, or to manually
|
|
|
|
|
|
// call `rawAsap.requestFlush` if an exception is thrown.
|
|
|
|
|
|
module.exports = rawAsap;
|
|
|
|
|
|
function rawAsap(task) {
|
|
|
|
|
|
if (!queue.length) {
|
|
|
|
|
|
requestFlush();
|
|
|
|
|
|
flushing = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
// Equivalent to push, but avoids a function call.
|
|
|
|
|
|
queue[queue.length] = task;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var queue = [];
|
|
|
|
|
|
// Once a flush has been requested, no further calls to `requestFlush` are
|
|
|
|
|
|
// necessary until the next `flush` completes.
|
|
|
|
|
|
var flushing = false;
|
|
|
|
|
|
// `requestFlush` is an implementation-specific method that attempts to kick
|
|
|
|
|
|
// off a `flush` event as quickly as possible. `flush` will attempt to exhaust
|
|
|
|
|
|
// the event queue before yielding to the browser's own event loop.
|
|
|
|
|
|
var requestFlush;
|
|
|
|
|
|
// The position of the next task to execute in the task queue. This is
|
|
|
|
|
|
// preserved between calls to `flush` so that it can be resumed if
|
|
|
|
|
|
// a task throws an exception.
|
|
|
|
|
|
var index = 0;
|
|
|
|
|
|
// If a task schedules additional tasks recursively, the task queue can grow
|
|
|
|
|
|
// unbounded. To prevent memory exhaustion, the task queue will periodically
|
|
|
|
|
|
// truncate already-completed tasks.
|
|
|
|
|
|
var capacity = 1024;
|
|
|
|
|
|
|
|
|
|
|
|
// The flush function processes all tasks that have been scheduled with
|
|
|
|
|
|
// `rawAsap` unless and until one of those tasks throws an exception.
|
|
|
|
|
|
// If a task throws an exception, `flush` ensures that its state will remain
|
|
|
|
|
|
// consistent and will resume where it left off when called again.
|
|
|
|
|
|
// However, `flush` does not make any arrangements to be called again if an
|
|
|
|
|
|
// exception is thrown.
|
|
|
|
|
|
function flush() {
|
|
|
|
|
|
while (index < queue.length) {
|
|
|
|
|
|
var currentIndex = index;
|
|
|
|
|
|
// Advance the index before calling the task. This ensures that we will
|
|
|
|
|
|
// begin flushing on the next task the task throws an error.
|
|
|
|
|
|
index = index + 1;
|
|
|
|
|
|
queue[currentIndex].call();
|
|
|
|
|
|
// Prevent leaking memory for long chains of recursive calls to `asap`.
|
|
|
|
|
|
// If we call `asap` within tasks scheduled by `asap`, the queue will
|
|
|
|
|
|
// grow, but to avoid an O(n) walk for every task we execute, we don't
|
|
|
|
|
|
// shift tasks off the queue after they have been executed.
|
|
|
|
|
|
// Instead, we periodically shift 1024 tasks off the queue.
|
|
|
|
|
|
if (index > capacity) {
|
|
|
|
|
|
// Manually shift all values starting at the index back to the
|
|
|
|
|
|
// beginning of the queue.
|
|
|
|
|
|
for (var scan = 0, newLength = queue.length - index; scan < newLength; scan++) {
|
|
|
|
|
|
queue[scan] = queue[scan + index];
|
|
|
|
|
|
}
|
|
|
|
|
|
queue.length -= index;
|
|
|
|
|
|
index = 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
queue.length = 0;
|
|
|
|
|
|
index = 0;
|
|
|
|
|
|
flushing = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// `requestFlush` is implemented using a strategy based on data collected from
|
|
|
|
|
|
// every available SauceLabs Selenium web driver worker at time of writing.
|
|
|
|
|
|
// https://docs.google.com/spreadsheets/d/1mG-5UYGup5qxGdEMWkhP6BWCz053NUb2E1QoUTU16uA/edit#gid=783724593
|
|
|
|
|
|
|
|
|
|
|
|
// Safari 6 and 6.1 for desktop, iPad, and iPhone are the only browsers that
|
|
|
|
|
|
// have WebKitMutationObserver but not un-prefixed MutationObserver.
|
|
|
|
|
|
// Must use `global` instead of `window` to work in both frames and web
|
|
|
|
|
|
// workers. `global` is a provision of Browserify, Mr, Mrs, or Mop.
|
|
|
|
|
|
var BrowserMutationObserver = global.MutationObserver || global.WebKitMutationObserver;
|
|
|
|
|
|
|
|
|
|
|
|
// MutationObservers are desirable because they have high priority and work
|
|
|
|
|
|
// reliably everywhere they are implemented.
|
|
|
|
|
|
// They are implemented in all modern browsers.
|
|
|
|
|
|
//
|
|
|
|
|
|
// - Android 4-4.3
|
|
|
|
|
|
// - Chrome 26-34
|
|
|
|
|
|
// - Firefox 14-29
|
|
|
|
|
|
// - Internet Explorer 11
|
|
|
|
|
|
// - iPad Safari 6-7.1
|
|
|
|
|
|
// - iPhone Safari 7-7.1
|
|
|
|
|
|
// - Safari 6-7
|
|
|
|
|
|
if (typeof BrowserMutationObserver === "function") {
|
|
|
|
|
|
requestFlush = makeRequestCallFromMutationObserver(flush);
|
|
|
|
|
|
|
|
|
|
|
|
// MessageChannels are desirable because they give direct access to the HTML
|
|
|
|
|
|
// task queue, are implemented in Internet Explorer 10, Safari 5.0-1, and Opera
|
|
|
|
|
|
// 11-12, and in web workers in many engines.
|
|
|
|
|
|
// Although message channels yield to any queued rendering and IO tasks, they
|
|
|
|
|
|
// would be better than imposing the 4ms delay of timers.
|
|
|
|
|
|
// However, they do not work reliably in Internet Explorer or Safari.
|
|
|
|
|
|
|
|
|
|
|
|
// Internet Explorer 10 is the only browser that has setImmediate but does
|
|
|
|
|
|
// not have MutationObservers.
|
|
|
|
|
|
// Although setImmediate yields to the browser's renderer, it would be
|
|
|
|
|
|
// preferrable to falling back to setTimeout since it does not have
|
|
|
|
|
|
// the minimum 4ms penalty.
|
|
|
|
|
|
// Unfortunately there appears to be a bug in Internet Explorer 10 Mobile (and
|
|
|
|
|
|
// Desktop to a lesser extent) that renders both setImmediate and
|
|
|
|
|
|
// MessageChannel useless for the purposes of ASAP.
|
|
|
|
|
|
// https://github.com/kriskowal/q/issues/396
|
|
|
|
|
|
|
|
|
|
|
|
// Timers are implemented universally.
|
|
|
|
|
|
// We fall back to timers in workers in most engines, and in foreground
|
|
|
|
|
|
// contexts in the following browsers.
|
|
|
|
|
|
// However, note that even this simple case requires nuances to operate in a
|
|
|
|
|
|
// broad spectrum of browsers.
|
|
|
|
|
|
//
|
|
|
|
|
|
// - Firefox 3-13
|
|
|
|
|
|
// - Internet Explorer 6-9
|
|
|
|
|
|
// - iPad Safari 4.3
|
|
|
|
|
|
// - Lynx 2.8.7
|
|
|
|
|
|
} else {
|
|
|
|
|
|
requestFlush = makeRequestCallFromTimer(flush);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// `requestFlush` requests that the high priority event queue be flushed as
|
|
|
|
|
|
// soon as possible.
|
|
|
|
|
|
// This is useful to prevent an error thrown in a task from stalling the event
|
|
|
|
|
|
// queue if the exception handled by Node.js’s
|
|
|
|
|
|
// `process.on("uncaughtException")` or by a domain.
|
|
|
|
|
|
rawAsap.requestFlush = requestFlush;
|
|
|
|
|
|
|
|
|
|
|
|
// To request a high priority event, we induce a mutation observer by toggling
|
|
|
|
|
|
// the text of a text node between "1" and "-1".
|
|
|
|
|
|
function makeRequestCallFromMutationObserver(callback) {
|
|
|
|
|
|
var toggle = 1;
|
|
|
|
|
|
var observer = new BrowserMutationObserver(callback);
|
|
|
|
|
|
var node = document.createTextNode("");
|
|
|
|
|
|
observer.observe(node, {characterData: true});
|
|
|
|
|
|
return function requestCall() {
|
|
|
|
|
|
toggle = -toggle;
|
|
|
|
|
|
node.data = toggle;
|
|
|
|
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// The message channel technique was discovered by Malte Ubl and was the
|
|
|
|
|
|
// original foundation for this library.
|
|
|
|
|
|
// http://www.nonblocking.io/2011/06/windownexttick.html
|
|
|
|
|
|
|
|
|
|
|
|
// Safari 6.0.5 (at least) intermittently fails to create message ports on a
|
|
|
|
|
|
// page's first load. Thankfully, this version of Safari supports
|
|
|
|
|
|
// MutationObservers, so we don't need to fall back in that case.
|
|
|
|
|
|
|
|
|
|
|
|
// function makeRequestCallFromMessageChannel(callback) {
|
|
|
|
|
|
// var channel = new MessageChannel();
|
|
|
|
|
|
// channel.port1.onmessage = callback;
|
|
|
|
|
|
// return function requestCall() {
|
|
|
|
|
|
// channel.port2.postMessage(0);
|
|
|
|
|
|
// };
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
// For reasons explained above, we are also unable to use `setImmediate`
|
|
|
|
|
|
// under any circumstances.
|
|
|
|
|
|
// Even if we were, there is another bug in Internet Explorer 10.
|
|
|
|
|
|
// It is not sufficient to assign `setImmediate` to `requestFlush` because
|
|
|
|
|
|
// `setImmediate` must be called *by name* and therefore must be wrapped in a
|
|
|
|
|
|
// closure.
|
|
|
|
|
|
// Never forget.
|
|
|
|
|
|
|
|
|
|
|
|
// function makeRequestCallFromSetImmediate(callback) {
|
|
|
|
|
|
// return function requestCall() {
|
|
|
|
|
|
// setImmediate(callback);
|
|
|
|
|
|
// };
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
// Safari 6.0 has a problem where timers will get lost while the user is
|
|
|
|
|
|
// scrolling. This problem does not impact ASAP because Safari 6.0 supports
|
|
|
|
|
|
// mutation observers, so that implementation is used instead.
|
|
|
|
|
|
// However, if we ever elect to use timers in Safari, the prevalent work-around
|
|
|
|
|
|
// is to add a scroll event listener that calls for a flush.
|
|
|
|
|
|
|
|
|
|
|
|
// `setTimeout` does not call the passed callback if the delay is less than
|
|
|
|
|
|
// approximately 7 in web workers in Firefox 8 through 18, and sometimes not
|
|
|
|
|
|
// even then.
|
|
|
|
|
|
|
|
|
|
|
|
function makeRequestCallFromTimer(callback) {
|
|
|
|
|
|
return function requestCall() {
|
|
|
|
|
|
// We dispatch a timeout with a specified delay of 0 for engines that
|
|
|
|
|
|
// can reliably accommodate that request. This will usually be snapped
|
|
|
|
|
|
// to a 4 milisecond delay, but once we're flushing, there's no delay
|
|
|
|
|
|
// between events.
|
|
|
|
|
|
var timeoutHandle = setTimeout(handleTimer, 0);
|
|
|
|
|
|
// However, since this timer gets frequently dropped in Firefox
|
|
|
|
|
|
// workers, we enlist an interval handle that will try to fire
|
|
|
|
|
|
// an event 20 times per second until it succeeds.
|
|
|
|
|
|
var intervalHandle = setInterval(handleTimer, 50);
|
|
|
|
|
|
|
|
|
|
|
|
function handleTimer() {
|
|
|
|
|
|
// Whichever timer succeeds will cancel both timers and
|
|
|
|
|
|
// execute the callback.
|
|
|
|
|
|
clearTimeout(timeoutHandle);
|
|
|
|
|
|
clearInterval(intervalHandle);
|
|
|
|
|
|
callback();
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// This is for `asap.js` only.
|
|
|
|
|
|
// Its name will be periodically randomized to break any code that depends on
|
|
|
|
|
|
// its existence.
|
|
|
|
|
|
rawAsap.makeRequestCallFromTimer = makeRequestCallFromTimer;
|
|
|
|
|
|
|
|
|
|
|
|
// ASAP was originally a nextTick shim included in Q. This was factored out
|
|
|
|
|
|
// into this ASAP package. It was later adapted to RSVP which made further
|
|
|
|
|
|
// amendments. These decisions, particularly to marginalize MessageChannel and
|
|
|
|
|
|
// to capture the MutationObserver implementation in a closure, were integrated
|
|
|
|
|
|
// back into ASAP proper.
|
|
|
|
|
|
// https://github.com/tildeio/rsvp.js/blob/cddf7232546a9cf858524b75cde6f9edf72620a7/lib/rsvp/asap.js
|
|
|
|
|
|
|
|
|
|
|
|
/* WEBPACK VAR INJECTION */}.call(exports, (function() { return this; }())))
|
|
|
|
|
|
|
|
|
|
|
|
/***/ },
|
|
|
|
|
|
/* 31 */
|
|
|
|
|
|
/***/ function(module, exports) {
|
|
|
|
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
|
|
// A simple class system, more documentation to come
|
|
|
|
|
|
|
|
|
|
|
|
function extend(cls, name, props) {
|
|
|
|
|
|
// This does that same thing as Object.create, but with support for IE8
|
|
|
|
|
|
var F = function() {};
|
|
|
|
|
|
F.prototype = cls.prototype;
|
|
|
|
|
|
var prototype = new F();
|
|
|
|
|
|
|
|
|
|
|
|
// jshint undef: false
|
|
|
|
|
|
var fnTest = /xyz/.test(function(){ xyz; }) ? /\bparent\b/ : /.*/;
|
|
|
|
|
|
props = props || {};
|
|
|
|
|
|
|
|
|
|
|
|
for(var k in props) {
|
|
|
|
|
|
var src = props[k];
|
|
|
|
|
|
var parent = prototype[k];
|
|
|
|
|
|
|
|
|
|
|
|
if(typeof parent === 'function' &&
|
|
|
|
|
|
typeof src === 'function' &&
|
|
|
|
|
|
fnTest.test(src)) {
|
|
|
|
|
|
/*jshint -W083 */
|
|
|
|
|
|
prototype[k] = (function (src, parent) {
|
|
|
|
|
|
return function() {
|
|
|
|
|
|
// Save the current parent method
|
|
|
|
|
|
var tmp = this.parent;
|
|
|
|
|
|
|
|
|
|
|
|
// Set parent to the previous method, call, and restore
|
|
|
|
|
|
this.parent = parent;
|
|
|
|
|
|
var res = src.apply(this, arguments);
|
|
|
|
|
|
this.parent = tmp;
|
|
|
|
|
|
|
|
|
|
|
|
return res;
|
|
|
|
|
|
};
|
|
|
|
|
|
})(src, parent);
|
|
|
|
|
|
}
|
|
|
|
|
|
else {
|
|
|
|
|
|
prototype[k] = src;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
prototype.typename = name;
|
|
|
|
|
|
|
|
|
|
|
|
var new_cls = function() {
|
|
|
|
|
|
if(prototype.init) {
|
|
|
|
|
|
prototype.init.apply(this, arguments);
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
new_cls.prototype = prototype;
|
|
|
|
|
|
new_cls.prototype.constructor = new_cls;
|
|
|
|
|
|
|
|
|
|
|
|
new_cls.extend = function(name, props) {
|
|
|
|
|
|
if(typeof name === 'object') {
|
|
|
|
|
|
props = name;
|
|
|
|
|
|
name = 'anonymous';
|
|
|
|
|
|
}
|
|
|
|
|
|
return extend(new_cls, name, props);
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
return new_cls;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
module.exports = extend(Object, 'Object', {});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/***/ },
|
|
|
|
|
|
/* 32 */
|
|
|
|
|
|
/***/ function(module, exports) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/***/ },
|
|
|
|
|
|
/* 33 */
|
|
|
|
|
|
/***/ function(module, exports, __webpack_require__) {
|
|
|
|
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
|
|
var lib = __webpack_require__(27);
|
|
|
|
|
|
var r = __webpack_require__(34);
|
|
|
|
|
|
|
|
|
|
|
|
function normalize(value, defaultValue) {
|
|
|
|
|
|
if(value === null || value === undefined || value === false) {
|
|
|
|
|
|
return defaultValue;
|
|
|
|
|
|
}
|
|
|
|
|
|
return value;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var filters = {
|
|
|
|
|
|
abs: function(n) {
|
|
|
|
|
|
return Math.abs(n);
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
batch: function(arr, linecount, fill_with) {
|
|
|
|
|
|
var i;
|
|
|
|
|
|
var res = [];
|
|
|
|
|
|
var tmp = [];
|
|
|
|
|
|
|
|
|
|
|
|
for(i = 0; i < arr.length; i++) {
|
|
|
|
|
|
if(i % linecount === 0 && tmp.length) {
|
|
|
|
|
|
res.push(tmp);
|
|
|
|
|
|
tmp = [];
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
tmp.push(arr[i]);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if(tmp.length) {
|
|
|
|
|
|
if(fill_with) {
|
|
|
|
|
|
for(i = tmp.length; i < linecount; i++) {
|
|
|
|
|
|
tmp.push(fill_with);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
res.push(tmp);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return res;
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
capitalize: function(str) {
|
|
|
|
|
|
str = normalize(str, '');
|
|
|
|
|
|
var ret = str.toLowerCase();
|
|
|
|
|
|
return r.copySafeness(str, ret.charAt(0).toUpperCase() + ret.slice(1));
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
center: function(str, width) {
|
|
|
|
|
|
str = normalize(str, '');
|
|
|
|
|
|
width = width || 80;
|
|
|
|
|
|
|
|
|
|
|
|
if(str.length >= width) {
|
|
|
|
|
|
return str;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var spaces = width - str.length;
|
|
|
|
|
|
var pre = lib.repeat(' ', spaces/2 - spaces % 2);
|
|
|
|
|
|
var post = lib.repeat(' ', spaces/2);
|
|
|
|
|
|
return r.copySafeness(str, pre + str + post);
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
'default': function(val, def, bool) {
|
|
|
|
|
|
if(bool) {
|
|
|
|
|
|
return val ? val : def;
|
|
|
|
|
|
}
|
|
|
|
|
|
else {
|
|
|
|
|
|
return (val !== undefined) ? val : def;
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
dictsort: function(val, case_sensitive, by) {
|
|
|
|
|
|
if (!lib.isObject(val)) {
|
|
|
|
|
|
throw new lib.TemplateError('dictsort filter: val must be an object');
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var array = [];
|
|
|
|
|
|
for (var k in val) {
|
|
|
|
|
|
// deliberately include properties from the object's prototype
|
|
|
|
|
|
array.push([k,val[k]]);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var si;
|
|
|
|
|
|
if (by === undefined || by === 'key') {
|
|
|
|
|
|
si = 0;
|
|
|
|
|
|
} else if (by === 'value') {
|
|
|
|
|
|
si = 1;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
throw new lib.TemplateError(
|
|
|
|
|
|
'dictsort filter: You can only sort by either key or value');
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
array.sort(function(t1, t2) {
|
|
|
|
|
|
var a = t1[si];
|
|
|
|
|
|
var b = t2[si];
|
|
|
|
|
|
|
|
|
|
|
|
if (!case_sensitive) {
|
|
|
|
|
|
if (lib.isString(a)) {
|
|
|
|
|
|
a = a.toUpperCase();
|
|
|
|
|
|
}
|
|
|
|
|
|
if (lib.isString(b)) {
|
|
|
|
|
|
b = b.toUpperCase();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return a > b ? 1 : (a === b ? 0 : -1);
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
return array;
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
dump: function(obj) {
|
|
|
|
|
|
return JSON.stringify(obj);
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
escape: function(str) {
|
|
|
|
|
|
if(typeof str === 'string' ||
|
|
|
|
|
|
str instanceof r.SafeString) {
|
|
|
|
|
|
return lib.escape(str);
|
|
|
|
|
|
}
|
|
|
|
|
|
return str;
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
safe: function(str) {
|
|
|
|
|
|
return r.markSafe(str);
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
first: function(arr) {
|
|
|
|
|
|
return arr[0];
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
groupby: function(arr, attr) {
|
|
|
|
|
|
return lib.groupBy(arr, attr);
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
indent: function(str, width, indentfirst) {
|
|
|
|
|
|
str = normalize(str, '');
|
|
|
|
|
|
|
|
|
|
|
|
if (str === '') return '';
|
|
|
|
|
|
|
|
|
|
|
|
width = width || 4;
|
|
|
|
|
|
var res = '';
|
|
|
|
|
|
var lines = str.split('\n');
|
|
|
|
|
|
var sp = lib.repeat(' ', width);
|
|
|
|
|
|
|
|
|
|
|
|
for(var i=0; i<lines.length; i++) {
|
|
|
|
|
|
if(i === 0 && !indentfirst) {
|
|
|
|
|
|
res += lines[i] + '\n';
|
|
|
|
|
|
}
|
|
|
|
|
|
else {
|
|
|
|
|
|
res += sp + lines[i] + '\n';
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return r.copySafeness(str, res);
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
join: function(arr, del, attr) {
|
|
|
|
|
|
del = del || '';
|
|
|
|
|
|
|
|
|
|
|
|
if(attr) {
|
|
|
|
|
|
arr = lib.map(arr, function(v) {
|
|
|
|
|
|
return v[attr];
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return arr.join(del);
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
last: function(arr) {
|
|
|
|
|
|
return arr[arr.length-1];
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
length: function(val) {
|
|
|
|
|
|
var value = normalize(val, '');
|
|
|
|
|
|
|
|
|
|
|
|
return value !== undefined ? value.length : 0;
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
list: function(val) {
|
|
|
|
|
|
if(lib.isString(val)) {
|
|
|
|
|
|
return val.split('');
|
|
|
|
|
|
}
|
|
|
|
|
|
else if(lib.isObject(val)) {
|
|
|
|
|
|
var keys = [];
|
|
|
|
|
|
|
|
|
|
|
|
if(Object.keys) {
|
|
|
|
|
|
keys = Object.keys(val);
|
|
|
|
|
|
}
|
|
|
|
|
|
else {
|
|
|
|
|
|
for(var k in val) {
|
|
|
|
|
|
keys.push(k);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return lib.map(keys, function(k) {
|
|
|
|
|
|
return { key: k,
|
|
|
|
|
|
value: val[k] };
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
else if(lib.isArray(val)) {
|
|
|
|
|
|
return val;
|
|
|
|
|
|
}
|
|
|
|
|
|
else {
|
|
|
|
|
|
throw new lib.TemplateError('list filter: type not iterable');
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
lower: function(str) {
|
|
|
|
|
|
str = normalize(str, '');
|
|
|
|
|
|
return str.toLowerCase();
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
random: function(arr) {
|
|
|
|
|
|
return arr[Math.floor(Math.random() * arr.length)];
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
rejectattr: function(arr, attr) {
|
|
|
|
|
|
return arr.filter(function (item) {
|
|
|
|
|
|
return !item[attr];
|
|
|
|
|
|
});
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
selectattr: function(arr, attr) {
|
|
|
|
|
|
return arr.filter(function (item) {
|
|
|
|
|
|
return !!item[attr];
|
|
|
|
|
|
});
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
replace: function(str, old, new_, maxCount) {
|
|
|
|
|
|
var originalStr = str;
|
|
|
|
|
|
|
|
|
|
|
|
if (old instanceof RegExp) {
|
|
|
|
|
|
return str.replace(old, new_);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if(typeof maxCount === 'undefined'){
|
|
|
|
|
|
maxCount = -1;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var res = ''; // Output
|
|
|
|
|
|
|
|
|
|
|
|
// Cast Numbers in the search term to string
|
|
|
|
|
|
if(typeof old === 'number'){
|
|
|
|
|
|
old = old + '';
|
|
|
|
|
|
}
|
|
|
|
|
|
else if(typeof old !== 'string') {
|
|
|
|
|
|
// If it is something other than number or string,
|
|
|
|
|
|
// return the original string
|
|
|
|
|
|
return str;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Cast numbers in the replacement to string
|
|
|
|
|
|
if(typeof str === 'number'){
|
|
|
|
|
|
str = str + '';
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// If by now, we don't have a string, throw it back
|
|
|
|
|
|
if(typeof str !== 'string' && !(str instanceof r.SafeString)){
|
|
|
|
|
|
return str;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ShortCircuits
|
|
|
|
|
|
if(old === ''){
|
|
|
|
|
|
// Mimic the python behaviour: empty string is replaced
|
|
|
|
|
|
// by replacement e.g. "abc"|replace("", ".") -> .a.b.c.
|
|
|
|
|
|
res = new_ + str.split('').join(new_) + new_;
|
|
|
|
|
|
return r.copySafeness(str, res);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var nextIndex = str.indexOf(old);
|
|
|
|
|
|
// if # of replacements to perform is 0, or the string to does
|
|
|
|
|
|
// not contain the old value, return the string
|
|
|
|
|
|
if(maxCount === 0 || nextIndex === -1){
|
|
|
|
|
|
return str;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var pos = 0;
|
|
|
|
|
|
var count = 0; // # of replacements made
|
|
|
|
|
|
|
|
|
|
|
|
while(nextIndex > -1 && (maxCount === -1 || count < maxCount)){
|
|
|
|
|
|
// Grab the next chunk of src string and add it with the
|
|
|
|
|
|
// replacement, to the result
|
|
|
|
|
|
res += str.substring(pos, nextIndex) + new_;
|
|
|
|
|
|
// Increment our pointer in the src string
|
|
|
|
|
|
pos = nextIndex + old.length;
|
|
|
|
|
|
count++;
|
|
|
|
|
|
// See if there are any more replacements to be made
|
|
|
|
|
|
nextIndex = str.indexOf(old, pos);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// We've either reached the end, or done the max # of
|
|
|
|
|
|
// replacements, tack on any remaining string
|
|
|
|
|
|
if(pos < str.length) {
|
|
|
|
|
|
res += str.substring(pos);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return r.copySafeness(originalStr, res);
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
reverse: function(val) {
|
|
|
|
|
|
var arr;
|
|
|
|
|
|
if(lib.isString(val)) {
|
|
|
|
|
|
arr = filters.list(val);
|
|
|
|
|
|
}
|
|
|
|
|
|
else {
|
|
|
|
|
|
// Copy it
|
|
|
|
|
|
arr = lib.map(val, function(v) { return v; });
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
arr.reverse();
|
|
|
|
|
|
|
|
|
|
|
|
if(lib.isString(val)) {
|
|
|
|
|
|
return r.copySafeness(val, arr.join(''));
|
|
|
|
|
|
}
|
|
|
|
|
|
return arr;
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
round: function(val, precision, method) {
|
|
|
|
|
|
precision = precision || 0;
|
|
|
|
|
|
var factor = Math.pow(10, precision);
|
|
|
|
|
|
var rounder;
|
|
|
|
|
|
|
|
|
|
|
|
if(method === 'ceil') {
|
|
|
|
|
|
rounder = Math.ceil;
|
|
|
|
|
|
}
|
|
|
|
|
|
else if(method === 'floor') {
|
|
|
|
|
|
rounder = Math.floor;
|
|
|
|
|
|
}
|
|
|
|
|
|
else {
|
|
|
|
|
|
rounder = Math.round;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return rounder(val * factor) / factor;
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
slice: function(arr, slices, fillWith) {
|
|
|
|
|
|
var sliceLength = Math.floor(arr.length / slices);
|
|
|
|
|
|
var extra = arr.length % slices;
|
|
|
|
|
|
var offset = 0;
|
|
|
|
|
|
var res = [];
|
|
|
|
|
|
|
|
|
|
|
|
for(var i=0; i<slices; i++) {
|
|
|
|
|
|
var start = offset + i * sliceLength;
|
|
|
|
|
|
if(i < extra) {
|
|
|
|
|
|
offset++;
|
|
|
|
|
|
}
|
|
|
|
|
|
var end = offset + (i + 1) * sliceLength;
|
|
|
|
|
|
|
|
|
|
|
|
var slice = arr.slice(start, end);
|
|
|
|
|
|
if(fillWith && i >= extra) {
|
|
|
|
|
|
slice.push(fillWith);
|
|
|
|
|
|
}
|
|
|
|
|
|
res.push(slice);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return res;
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
sort: r.makeMacro(['value', 'reverse', 'case_sensitive', 'attribute'], [], function(arr, reverse, caseSens, attr) {
|
|
|
|
|
|
// Copy it
|
|
|
|
|
|
arr = lib.map(arr, function(v) { return v; });
|
|
|
|
|
|
|
|
|
|
|
|
arr.sort(function(a, b) {
|
|
|
|
|
|
var x, y;
|
|
|
|
|
|
|
|
|
|
|
|
if(attr) {
|
|
|
|
|
|
x = a[attr];
|
|
|
|
|
|
y = b[attr];
|
|
|
|
|
|
}
|
|
|
|
|
|
else {
|
|
|
|
|
|
x = a;
|
|
|
|
|
|
y = b;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if(!caseSens && lib.isString(x) && lib.isString(y)) {
|
|
|
|
|
|
x = x.toLowerCase();
|
|
|
|
|
|
y = y.toLowerCase();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if(x < y) {
|
|
|
|
|
|
return reverse ? 1 : -1;
|
|
|
|
|
|
}
|
|
|
|
|
|
else if(x > y) {
|
|
|
|
|
|
return reverse ? -1: 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
else {
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
return arr;
|
|
|
|
|
|
}),
|
|
|
|
|
|
|
|
|
|
|
|
string: function(obj) {
|
|
|
|
|
|
return r.copySafeness(obj, obj);
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
striptags: function(input, preserve_linebreaks) {
|
|
|
|
|
|
input = normalize(input, '');
|
|
|
|
|
|
preserve_linebreaks = preserve_linebreaks || false;
|
|
|
|
|
|
var tags = /<\/?([a-z][a-z0-9]*)\b[^>]*>|<!--[\s\S]*?-->/gi;
|
|
|
|
|
|
var trimmedInput = filters.trim(input.replace(tags, ''));
|
|
|
|
|
|
var res = '';
|
|
|
|
|
|
if (preserve_linebreaks) {
|
|
|
|
|
|
res = trimmedInput
|
|
|
|
|
|
.replace(/^ +| +$/gm, '') // remove leading and trailing spaces
|
|
|
|
|
|
.replace(/ +/g, ' ') // squash adjacent spaces
|
|
|
|
|
|
.replace(/(\r\n)/g, '\n') // normalize linebreaks (CRLF -> LF)
|
|
|
|
|
|
.replace(/\n\n\n+/g, '\n\n'); // squash abnormal adjacent linebreaks
|
|
|
|
|
|
} else {
|
|
|
|
|
|
res = trimmedInput.replace(/\s+/gi, ' ');
|
|
|
|
|
|
}
|
|
|
|
|
|
return r.copySafeness(input, res);
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
title: function(str) {
|
|
|
|
|
|
str = normalize(str, '');
|
|
|
|
|
|
var words = str.split(' ');
|
|
|
|
|
|
for(var i = 0; i < words.length; i++) {
|
|
|
|
|
|
words[i] = filters.capitalize(words[i]);
|
|
|
|
|
|
}
|
|
|
|
|
|
return r.copySafeness(str, words.join(' '));
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
trim: function(str) {
|
|
|
|
|
|
return r.copySafeness(str, str.replace(/^\s*|\s*$/g, ''));
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
truncate: function(input, length, killwords, end) {
|
|
|
|
|
|
var orig = input;
|
|
|
|
|
|
input = normalize(input, '');
|
|
|
|
|
|
length = length || 255;
|
|
|
|
|
|
|
|
|
|
|
|
if (input.length <= length)
|
|
|
|
|
|
return input;
|
|
|
|
|
|
|
|
|
|
|
|
if (killwords) {
|
|
|
|
|
|
input = input.substring(0, length);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
var idx = input.lastIndexOf(' ', length);
|
|
|
|
|
|
if(idx === -1) {
|
|
|
|
|
|
idx = length;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
input = input.substring(0, idx);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
input += (end !== undefined && end !== null) ? end : '...';
|
|
|
|
|
|
return r.copySafeness(orig, input);
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
upper: function(str) {
|
|
|
|
|
|
str = normalize(str, '');
|
|
|
|
|
|
return str.toUpperCase();
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
urlencode: function(obj) {
|
|
|
|
|
|
var enc = encodeURIComponent;
|
|
|
|
|
|
if (lib.isString(obj)) {
|
|
|
|
|
|
return enc(obj);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
var parts;
|
|
|
|
|
|
if (lib.isArray(obj)) {
|
|
|
|
|
|
parts = obj.map(function(item) {
|
|
|
|
|
|
return enc(item[0]) + '=' + enc(item[1]);
|
|
|
|
|
|
});
|
|
|
|
|
|
} else {
|
|
|
|
|
|
parts = [];
|
|
|
|
|
|
for (var k in obj) {
|
|
|
|
|
|
if (obj.hasOwnProperty(k)) {
|
|
|
|
|
|
parts.push(enc(k) + '=' + enc(obj[k]));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return parts.join('&');
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
urlize: function(str, length, nofollow) {
|
|
|
|
|
|
if (isNaN(length)) length = Infinity;
|
|
|
|
|
|
|
|
|
|
|
|
var noFollowAttr = (nofollow === true ? ' rel="nofollow"' : '');
|
|
|
|
|
|
|
|
|
|
|
|
// For the jinja regexp, see
|
|
|
|
|
|
// https://github.com/mitsuhiko/jinja2/blob/f15b814dcba6aa12bc74d1f7d0c881d55f7126be/jinja2/utils.py#L20-L23
|
|
|
|
|
|
var puncRE = /^(?:\(|<|<)?(.*?)(?:\.|,|\)|\n|>)?$/;
|
|
|
|
|
|
// from http://blog.gerv.net/2011/05/html5_email_address_regexp/
|
|
|
|
|
|
var emailRE = /^[\w.!#$%&'*+\-\/=?\^`{|}~]+@[a-z\d\-]+(\.[a-z\d\-]+)+$/i;
|
|
|
|
|
|
var httpHttpsRE = /^https?:\/\/.*$/;
|
|
|
|
|
|
var wwwRE = /^www\./;
|
|
|
|
|
|
var tldRE = /\.(?:org|net|com)(?:\:|\/|$)/;
|
|
|
|
|
|
|
|
|
|
|
|
var words = str.split(/\s+/).filter(function(word) {
|
|
|
|
|
|
// If the word has no length, bail. This can happen for str with
|
|
|
|
|
|
// trailing whitespace.
|
|
|
|
|
|
return word && word.length;
|
|
|
|
|
|
}).map(function(word) {
|
|
|
|
|
|
var matches = word.match(puncRE);
|
|
|
|
|
|
var possibleUrl = matches && matches[1] || word;
|
|
|
|
|
|
|
|
|
|
|
|
// url that starts with http or https
|
|
|
|
|
|
if (httpHttpsRE.test(possibleUrl))
|
|
|
|
|
|
return '<a href="' + possibleUrl + '"' + noFollowAttr + '>' + possibleUrl.substr(0, length) + '</a>';
|
|
|
|
|
|
|
|
|
|
|
|
// url that starts with www.
|
|
|
|
|
|
if (wwwRE.test(possibleUrl))
|
|
|
|
|
|
return '<a href="http://' + possibleUrl + '"' + noFollowAttr + '>' + possibleUrl.substr(0, length) + '</a>';
|
|
|
|
|
|
|
|
|
|
|
|
// an email address of the form username@domain.tld
|
|
|
|
|
|
if (emailRE.test(possibleUrl))
|
|
|
|
|
|
return '<a href="mailto:' + possibleUrl + '">' + possibleUrl + '</a>';
|
|
|
|
|
|
|
|
|
|
|
|
// url that ends in .com, .org or .net that is not an email address
|
|
|
|
|
|
if (tldRE.test(possibleUrl))
|
|
|
|
|
|
return '<a href="http://' + possibleUrl + '"' + noFollowAttr + '>' + possibleUrl.substr(0, length) + '</a>';
|
|
|
|
|
|
|
|
|
|
|
|
return word;
|
|
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
return words.join(' ');
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
wordcount: function(str) {
|
|
|
|
|
|
str = normalize(str, '');
|
|
|
|
|
|
var words = (str) ? str.match(/\w+/g) : null;
|
|
|
|
|
|
return (words) ? words.length : null;
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
'float': function(val, def) {
|
|
|
|
|
|
var res = parseFloat(val);
|
|
|
|
|
|
return isNaN(res) ? def : res;
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
'int': function(val, def) {
|
|
|
|
|
|
var res = parseInt(val, 10);
|
|
|
|
|
|
return isNaN(res) ? def : res;
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Aliases
|
|
|
|
|
|
filters.d = filters['default'];
|
|
|
|
|
|
filters.e = filters.escape;
|
|
|
|
|
|
|
|
|
|
|
|
module.exports = filters;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/***/ },
|
|
|
|
|
|
/* 34 */
|
|
|
|
|
|
/***/ function(module, exports, __webpack_require__) {
|
|
|
|
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
|
|
var lib = __webpack_require__(27);
|
|
|
|
|
|
var Obj = __webpack_require__(31);
|
|
|
|
|
|
|
|
|
|
|
|
// Frames keep track of scoping both at compile-time and run-time so
|
|
|
|
|
|
// we know how to access variables. Block tags can introduce special
|
|
|
|
|
|
// variables, for example.
|
|
|
|
|
|
var Frame = Obj.extend({
|
|
|
|
|
|
init: function(parent) {
|
|
|
|
|
|
this.variables = {};
|
|
|
|
|
|
this.parent = parent;
|
|
|
|
|
|
this.topLevel = false;
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
set: function(name, val, resolveUp) {
|
|
|
|
|
|
// Allow variables with dots by automatically creating the
|
|
|
|
|
|
// nested structure
|
|
|
|
|
|
var parts = name.split('.');
|
|
|
|
|
|
var obj = this.variables;
|
|
|
|
|
|
var frame = this;
|
|
|
|
|
|
|
|
|
|
|
|
if(resolveUp) {
|
|
|
|
|
|
if((frame = this.resolve(parts[0]))) {
|
|
|
|
|
|
frame.set(name, val);
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
frame = this;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
for(var i=0; i<parts.length - 1; i++) {
|
|
|
|
|
|
var id = parts[i];
|
|
|
|
|
|
|
|
|
|
|
|
if(!obj[id]) {
|
|
|
|
|
|
obj[id] = {};
|
|
|
|
|
|
}
|
|
|
|
|
|
obj = obj[id];
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
obj[parts[parts.length - 1]] = val;
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
get: function(name) {
|
|
|
|
|
|
var val = this.variables[name];
|
|
|
|
|
|
if(val !== undefined && val !== null) {
|
|
|
|
|
|
return val;
|
|
|
|
|
|
}
|
|
|
|
|
|
return null;
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
lookup: function(name) {
|
|
|
|
|
|
var p = this.parent;
|
|
|
|
|
|
var val = this.variables[name];
|
|
|
|
|
|
if(val !== undefined && val !== null) {
|
|
|
|
|
|
return val;
|
|
|
|
|
|
}
|
|
|
|
|
|
return p && p.lookup(name);
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
resolve: function(name) {
|
|
|
|
|
|
var p = this.parent;
|
|
|
|
|
|
var val = this.variables[name];
|
|
|
|
|
|
if(val !== undefined && val !== null) {
|
|
|
|
|
|
return this;
|
|
|
|
|
|
}
|
|
|
|
|
|
return p && p.resolve(name);
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
push: function() {
|
|
|
|
|
|
return new Frame(this);
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
pop: function() {
|
|
|
|
|
|
return this.parent;
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
function makeMacro(argNames, kwargNames, func) {
|
|
|
|
|
|
return function() {
|
|
|
|
|
|
var argCount = numArgs(arguments);
|
|
|
|
|
|
var args;
|
|
|
|
|
|
var kwargs = getKeywordArgs(arguments);
|
|
|
|
|
|
var i;
|
|
|
|
|
|
|
|
|
|
|
|
if(argCount > argNames.length) {
|
|
|
|
|
|
args = Array.prototype.slice.call(arguments, 0, argNames.length);
|
|
|
|
|
|
|
|
|
|
|
|
// Positional arguments that should be passed in as
|
|
|
|
|
|
// keyword arguments (essentially default values)
|
|
|
|
|
|
var vals = Array.prototype.slice.call(arguments, args.length, argCount);
|
|
|
|
|
|
for(i = 0; i < vals.length; i++) {
|
|
|
|
|
|
if(i < kwargNames.length) {
|
|
|
|
|
|
kwargs[kwargNames[i]] = vals[i];
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
args.push(kwargs);
|
|
|
|
|
|
}
|
|
|
|
|
|
else if(argCount < argNames.length) {
|
|
|
|
|
|
args = Array.prototype.slice.call(arguments, 0, argCount);
|
|
|
|
|
|
|
|
|
|
|
|
for(i = argCount; i < argNames.length; i++) {
|
|
|
|
|
|
var arg = argNames[i];
|
|
|
|
|
|
|
|
|
|
|
|
// Keyword arguments that should be passed as
|
|
|
|
|
|
// positional arguments, i.e. the caller explicitly
|
|
|
|
|
|
// used the name of a positional arg
|
|
|
|
|
|
args.push(kwargs[arg]);
|
|
|
|
|
|
delete kwargs[arg];
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
args.push(kwargs);
|
|
|
|
|
|
}
|
|
|
|
|
|
else {
|
|
|
|
|
|
args = arguments;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return func.apply(this, args);
|
|
|
|
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function makeKeywordArgs(obj) {
|
|
|
|
|
|
obj.__keywords = true;
|
|
|
|
|
|
return obj;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function getKeywordArgs(args) {
|
|
|
|
|
|
var len = args.length;
|
|
|
|
|
|
if(len) {
|
|
|
|
|
|
var lastArg = args[len - 1];
|
|
|
|
|
|
if(lastArg && lastArg.hasOwnProperty('__keywords')) {
|
|
|
|
|
|
return lastArg;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return {};
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function numArgs(args) {
|
|
|
|
|
|
var len = args.length;
|
|
|
|
|
|
if(len === 0) {
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var lastArg = args[len - 1];
|
|
|
|
|
|
if(lastArg && lastArg.hasOwnProperty('__keywords')) {
|
|
|
|
|
|
return len - 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
else {
|
|
|
|
|
|
return len;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// A SafeString object indicates that the string should not be
|
|
|
|
|
|
// autoescaped. This happens magically because autoescaping only
|
|
|
|
|
|
// occurs on primitive string objects.
|
|
|
|
|
|
function SafeString(val) {
|
|
|
|
|
|
if(typeof val !== 'string') {
|
|
|
|
|
|
return val;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
this.val = val;
|
|
|
|
|
|
this.length = val.length;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SafeString.prototype = Object.create(String.prototype, {
|
|
|
|
|
|
length: { writable: true, configurable: true, value: 0 }
|
|
|
|
|
|
});
|
|
|
|
|
|
SafeString.prototype.valueOf = function() {
|
|
|
|
|
|
return this.val;
|
|
|
|
|
|
};
|
|
|
|
|
|
SafeString.prototype.toString = function() {
|
|
|
|
|
|
return this.val;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
function copySafeness(dest, target) {
|
|
|
|
|
|
if(dest instanceof SafeString) {
|
|
|
|
|
|
return new SafeString(target);
|
|
|
|
|
|
}
|
|
|
|
|
|
return target.toString();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function markSafe(val) {
|
|
|
|
|
|
var type = typeof val;
|
|
|
|
|
|
|
|
|
|
|
|
if(type === 'string') {
|
|
|
|
|
|
return new SafeString(val);
|
|
|
|
|
|
}
|
|
|
|
|
|
else if(type !== 'function') {
|
|
|
|
|
|
return val;
|
|
|
|
|
|
}
|
|
|
|
|
|
else {
|
|
|
|
|
|
return function() {
|
|
|
|
|
|
var ret = val.apply(this, arguments);
|
|
|
|
|
|
|
|
|
|
|
|
if(typeof ret === 'string') {
|
|
|
|
|
|
return new SafeString(ret);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function suppressValue(val, autoescape) {
|
|
|
|
|
|
val = (val !== undefined && val !== null) ? val : '';
|
|
|
|
|
|
|
|
|
|
|
|
if(autoescape && typeof val === 'string') {
|
|
|
|
|
|
val = lib.escape(val);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return val;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function ensureDefined(val, lineno, colno) {
|
|
|
|
|
|
if(val === null || val === undefined) {
|
|
|
|
|
|
throw new lib.TemplateError(
|
|
|
|
|
|
'attempted to output null or undefined value',
|
|
|
|
|
|
lineno + 1,
|
|
|
|
|
|
colno + 1
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
return val;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function memberLookup(obj, val) {
|
|
|
|
|
|
obj = obj || {};
|
|
|
|
|
|
|
|
|
|
|
|
if(typeof obj[val] === 'function') {
|
|
|
|
|
|
return function() {
|
|
|
|
|
|
return obj[val].apply(obj, arguments);
|
|
|
|
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return obj[val];
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function callWrap(obj, name, context, args) {
|
|
|
|
|
|
if(!obj) {
|
|
|
|
|
|
throw new Error('Unable to call `' + name + '`, which is undefined or falsey');
|
|
|
|
|
|
}
|
|
|
|
|
|
else if(typeof obj !== 'function') {
|
|
|
|
|
|
throw new Error('Unable to call `' + name + '`, which is not a function');
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// jshint validthis: true
|
|
|
|
|
|
return obj.apply(context, args);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function contextOrFrameLookup(context, frame, name) {
|
|
|
|
|
|
var val = frame.lookup(name);
|
|
|
|
|
|
return (val !== undefined && val !== null) ?
|
|
|
|
|
|
val :
|
|
|
|
|
|
context.lookup(name);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function handleError(error, lineno, colno) {
|
|
|
|
|
|
if(error.lineno) {
|
|
|
|
|
|
return error;
|
|
|
|
|
|
}
|
|
|
|
|
|
else {
|
|
|
|
|
|
return new lib.TemplateError(error, lineno, colno);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function asyncEach(arr, dimen, iter, cb) {
|
|
|
|
|
|
if(lib.isArray(arr)) {
|
|
|
|
|
|
var len = arr.length;
|
|
|
|
|
|
|
|
|
|
|
|
lib.asyncIter(arr, function(item, i, next) {
|
|
|
|
|
|
switch(dimen) {
|
|
|
|
|
|
case 1: iter(item, i, len, next); break;
|
|
|
|
|
|
case 2: iter(item[0], item[1], i, len, next); break;
|
|
|
|
|
|
case 3: iter(item[0], item[1], item[2], i, len, next); break;
|
|
|
|
|
|
default:
|
|
|
|
|
|
item.push(i, next);
|
|
|
|
|
|
iter.apply(this, item);
|
|
|
|
|
|
}
|
|
|
|
|
|
}, cb);
|
|
|
|
|
|
}
|
|
|
|
|
|
else {
|
|
|
|
|
|
lib.asyncFor(arr, function(key, val, i, len, next) {
|
|
|
|
|
|
iter(key, val, i, len, next);
|
|
|
|
|
|
}, cb);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function asyncAll(arr, dimen, func, cb) {
|
|
|
|
|
|
var finished = 0;
|
|
|
|
|
|
var len, i;
|
|
|
|
|
|
var outputArr;
|
|
|
|
|
|
|
|
|
|
|
|
function done(i, output) {
|
|
|
|
|
|
finished++;
|
|
|
|
|
|
outputArr[i] = output;
|
|
|
|
|
|
|
|
|
|
|
|
if(finished === len) {
|
|
|
|
|
|
cb(null, outputArr.join(''));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if(lib.isArray(arr)) {
|
|
|
|
|
|
len = arr.length;
|
|
|
|
|
|
outputArr = new Array(len);
|
|
|
|
|
|
|
|
|
|
|
|
if(len === 0) {
|
|
|
|
|
|
cb(null, '');
|
|
|
|
|
|
}
|
|
|
|
|
|
else {
|
|
|
|
|
|
for(i = 0; i < arr.length; i++) {
|
|
|
|
|
|
var item = arr[i];
|
|
|
|
|
|
|
|
|
|
|
|
switch(dimen) {
|
|
|
|
|
|
case 1: func(item, i, len, done); break;
|
|
|
|
|
|
case 2: func(item[0], item[1], i, len, done); break;
|
|
|
|
|
|
case 3: func(item[0], item[1], item[2], i, len, done); break;
|
|
|
|
|
|
default:
|
|
|
|
|
|
item.push(i, done);
|
|
|
|
|
|
// jshint validthis: true
|
|
|
|
|
|
func.apply(this, item);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else {
|
|
|
|
|
|
var keys = lib.keys(arr);
|
|
|
|
|
|
len = keys.length;
|
|
|
|
|
|
outputArr = new Array(len);
|
|
|
|
|
|
|
|
|
|
|
|
if(len === 0) {
|
|
|
|
|
|
cb(null, '');
|
|
|
|
|
|
}
|
|
|
|
|
|
else {
|
|
|
|
|
|
for(i = 0; i < keys.length; i++) {
|
|
|
|
|
|
var k = keys[i];
|
|
|
|
|
|
func(k, arr[k], i, len, done);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
|
|
Frame: Frame,
|
|
|
|
|
|
makeMacro: makeMacro,
|
|
|
|
|
|
makeKeywordArgs: makeKeywordArgs,
|
|
|
|
|
|
numArgs: numArgs,
|
|
|
|
|
|
suppressValue: suppressValue,
|
|
|
|
|
|
ensureDefined: ensureDefined,
|
|
|
|
|
|
memberLookup: memberLookup,
|
|
|
|
|
|
contextOrFrameLookup: contextOrFrameLookup,
|
|
|
|
|
|
callWrap: callWrap,
|
|
|
|
|
|
handleError: handleError,
|
|
|
|
|
|
isArray: lib.isArray,
|
|
|
|
|
|
keys: lib.keys,
|
|
|
|
|
|
SafeString: SafeString,
|
|
|
|
|
|
copySafeness: copySafeness,
|
|
|
|
|
|
markSafe: markSafe,
|
|
|
|
|
|
asyncEach: asyncEach,
|
|
|
|
|
|
asyncAll: asyncAll
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/***/ },
|
|
|
|
|
|
/* 35 */
|
|
|
|
|
|
/***/ function(module, exports) {
|
|
|
|
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
|
|
function cycler(items) {
|
|
|
|
|
|
var index = -1;
|
|
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
|
current: null,
|
|
|
|
|
|
reset: function() {
|
|
|
|
|
|
index = -1;
|
|
|
|
|
|
this.current = null;
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
next: function() {
|
|
|
|
|
|
index++;
|
|
|
|
|
|
if(index >= items.length) {
|
|
|
|
|
|
index = 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
this.current = items[index];
|
|
|
|
|
|
return this.current;
|
|
|
|
|
|
},
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function joiner(sep) {
|
|
|
|
|
|
sep = sep || ',';
|
|
|
|
|
|
var first = true;
|
|
|
|
|
|
|
|
|
|
|
|
return function() {
|
|
|
|
|
|
var val = first ? '' : sep;
|
|
|
|
|
|
first = false;
|
|
|
|
|
|
return val;
|
|
|
|
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Making this a function instead so it returns a new object
|
|
|
|
|
|
// each time it's called. That way, if something like an environment
|
|
|
|
|
|
// uses it, they will each have their own copy.
|
|
|
|
|
|
function globals() {
|
|
|
|
|
|
return {
|
|
|
|
|
|
range: function(start, stop, step) {
|
|
|
|
|
|
if(!stop) {
|
|
|
|
|
|
stop = start;
|
|
|
|
|
|
start = 0;
|
|
|
|
|
|
step = 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
else if(!step) {
|
|
|
|
|
|
step = 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var arr = [];
|
|
|
|
|
|
var i;
|
|
|
|
|
|
if (step > 0) {
|
|
|
|
|
|
for (i=start; i<stop; i+=step) {
|
|
|
|
|
|
arr.push(i);
|
|
|
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
|
|
|
for (i=start; i>stop; i+=step) {
|
|
|
|
|
|
arr.push(i);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return arr;
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
// lipsum: function(n, html, min, max) {
|
|
|
|
|
|
// },
|
|
|
|
|
|
|
|
|
|
|
|
cycler: function() {
|
|
|
|
|
|
return cycler(Array.prototype.slice.call(arguments));
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
joiner: function(sep) {
|
|
|
|
|
|
return joiner(sep);
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
module.exports = globals;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/***/ },
|
|
|
|
|
|
/* 36 */
|
|
|
|
|
|
/***/ function(module, exports, __webpack_require__) {
|
|
|
|
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
|
|
var Loader = __webpack_require__(37);
|
|
|
|
|
|
|
|
|
|
|
|
var PrecompiledLoader = Loader.extend({
|
|
|
|
|
|
init: function(compiledTemplates) {
|
|
|
|
|
|
this.precompiled = compiledTemplates || {};
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
getSource: function(name) {
|
|
|
|
|
|
if (this.precompiled[name]) {
|
|
|
|
|
|
return {
|
|
|
|
|
|
src: { type: 'code',
|
|
|
|
|
|
obj: this.precompiled[name] },
|
|
|
|
|
|
path: name
|
|
|
|
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
module.exports = PrecompiledLoader;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/***/ },
|
|
|
|
|
|
/* 37 */
|
|
|
|
|
|
/***/ function(module, exports, __webpack_require__) {
|
|
|
|
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
|
|
var path = __webpack_require__(24);
|
|
|
|
|
|
var Obj = __webpack_require__(31);
|
|
|
|
|
|
var lib = __webpack_require__(27);
|
|
|
|
|
|
|
|
|
|
|
|
var Loader = Obj.extend({
|
|
|
|
|
|
on: function(name, func) {
|
|
|
|
|
|
this.listeners = this.listeners || {};
|
|
|
|
|
|
this.listeners[name] = this.listeners[name] || [];
|
|
|
|
|
|
this.listeners[name].push(func);
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
emit: function(name /*, arg1, arg2, ...*/) {
|
|
|
|
|
|
var args = Array.prototype.slice.call(arguments, 1);
|
|
|
|
|
|
|
|
|
|
|
|
if(this.listeners && this.listeners[name]) {
|
|
|
|
|
|
lib.each(this.listeners[name], function(listener) {
|
|
|
|
|
|
listener.apply(null, args);
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
resolve: function(from, to) {
|
|
|
|
|
|
return path.resolve(path.dirname(from), to);
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
isRelative: function(filename) {
|
|
|
|
|
|
return (filename.indexOf('./') === 0 || filename.indexOf('../') === 0);
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
module.exports = Loader;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/***/ },
|
|
|
|
|
|
/* 38 */
|
|
|
|
|
|
/***/ function(module, exports) {
|
|
|
|
|
|
|
|
|
|
|
|
function installCompat() {
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
|
|
// This must be called like `nunjucks.installCompat` so that `this`
|
|
|
|
|
|
// references the nunjucks instance
|
|
|
|
|
|
var runtime = this.runtime; // jshint ignore:line
|
|
|
|
|
|
var lib = this.lib; // jshint ignore:line
|
|
|
|
|
|
|
|
|
|
|
|
var orig_contextOrFrameLookup = runtime.contextOrFrameLookup;
|
|
|
|
|
|
runtime.contextOrFrameLookup = function(context, frame, key) {
|
|
|
|
|
|
var val = orig_contextOrFrameLookup.apply(this, arguments);
|
|
|
|
|
|
if (val === undefined) {
|
|
|
|
|
|
switch (key) {
|
|
|
|
|
|
case 'True':
|
|
|
|
|
|
return true;
|
|
|
|
|
|
case 'False':
|
|
|
|
|
|
return false;
|
|
|
|
|
|
case 'None':
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return val;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
var orig_memberLookup = runtime.memberLookup;
|
|
|
|
|
|
var ARRAY_MEMBERS = {
|
|
|
|
|
|
pop: function(index) {
|
|
|
|
|
|
if (index === undefined) {
|
|
|
|
|
|
return this.pop();
|
|
|
|
|
|
}
|
|
|
|
|
|
if (index >= this.length || index < 0) {
|
|
|
|
|
|
throw new Error('KeyError');
|
|
|
|
|
|
}
|
|
|
|
|
|
return this.splice(index, 1);
|
|
|
|
|
|
},
|
|
|
|
|
|
remove: function(element) {
|
|
|
|
|
|
for (var i = 0; i < this.length; i++) {
|
|
|
|
|
|
if (this[i] === element) {
|
|
|
|
|
|
return this.splice(i, 1);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
throw new Error('ValueError');
|
|
|
|
|
|
},
|
|
|
|
|
|
count: function(element) {
|
|
|
|
|
|
var count = 0;
|
|
|
|
|
|
for (var i = 0; i < this.length; i++) {
|
|
|
|
|
|
if (this[i] === element) {
|
|
|
|
|
|
count++;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return count;
|
|
|
|
|
|
},
|
|
|
|
|
|
index: function(element) {
|
|
|
|
|
|
var i;
|
|
|
|
|
|
if ((i = this.indexOf(element)) === -1) {
|
|
|
|
|
|
throw new Error('ValueError');
|
|
|
|
|
|
}
|
|
|
|
|
|
return i;
|
|
|
|
|
|
},
|
|
|
|
|
|
find: function(element) {
|
|
|
|
|
|
return this.indexOf(element);
|
|
|
|
|
|
},
|
|
|
|
|
|
insert: function(index, elem) {
|
|
|
|
|
|
return this.splice(index, 0, elem);
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
var OBJECT_MEMBERS = {
|
|
|
|
|
|
items: function() {
|
|
|
|
|
|
var ret = [];
|
|
|
|
|
|
for(var k in this) {
|
|
|
|
|
|
ret.push([k, this[k]]);
|
|
|
|
|
|
}
|
|
|
|
|
|
return ret;
|
|
|
|
|
|
},
|
|
|
|
|
|
values: function() {
|
|
|
|
|
|
var ret = [];
|
|
|
|
|
|
for(var k in this) {
|
|
|
|
|
|
ret.push(this[k]);
|
|
|
|
|
|
}
|
|
|
|
|
|
return ret;
|
|
|
|
|
|
},
|
|
|
|
|
|
keys: function() {
|
|
|
|
|
|
var ret = [];
|
|
|
|
|
|
for(var k in this) {
|
|
|
|
|
|
ret.push(k);
|
|
|
|
|
|
}
|
|
|
|
|
|
return ret;
|
|
|
|
|
|
},
|
|
|
|
|
|
get: function(key, def) {
|
|
|
|
|
|
var output = this[key];
|
|
|
|
|
|
if (output === undefined) {
|
|
|
|
|
|
output = def;
|
|
|
|
|
|
}
|
|
|
|
|
|
return output;
|
|
|
|
|
|
},
|
|
|
|
|
|
has_key: function(key) {
|
|
|
|
|
|
return this.hasOwnProperty(key);
|
|
|
|
|
|
},
|
|
|
|
|
|
pop: function(key, def) {
|
|
|
|
|
|
var output = this[key];
|
|
|
|
|
|
if (output === undefined && def !== undefined) {
|
|
|
|
|
|
output = def;
|
|
|
|
|
|
} else if (output === undefined) {
|
|
|
|
|
|
throw new Error('KeyError');
|
|
|
|
|
|
} else {
|
|
|
|
|
|
delete this[key];
|
|
|
|
|
|
}
|
|
|
|
|
|
return output;
|
|
|
|
|
|
},
|
|
|
|
|
|
popitem: function() {
|
|
|
|
|
|
for (var k in this) {
|
|
|
|
|
|
// Return the first object pair.
|
|
|
|
|
|
var val = this[k];
|
|
|
|
|
|
delete this[k];
|
|
|
|
|
|
return [k, val];
|
|
|
|
|
|
}
|
|
|
|
|
|
throw new Error('KeyError');
|
|
|
|
|
|
},
|
|
|
|
|
|
setdefault: function(key, def) {
|
|
|
|
|
|
if (key in this) {
|
|
|
|
|
|
return this[key];
|
|
|
|
|
|
}
|
|
|
|
|
|
if (def === undefined) {
|
|
|
|
|
|
def = null;
|
|
|
|
|
|
}
|
|
|
|
|
|
return this[key] = def;
|
|
|
|
|
|
},
|
|
|
|
|
|
update: function(kwargs) {
|
|
|
|
|
|
for (var k in kwargs) {
|
|
|
|
|
|
this[k] = kwargs[k];
|
|
|
|
|
|
}
|
|
|
|
|
|
return null; // Always returns None
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
OBJECT_MEMBERS.iteritems = OBJECT_MEMBERS.items;
|
|
|
|
|
|
OBJECT_MEMBERS.itervalues = OBJECT_MEMBERS.values;
|
|
|
|
|
|
OBJECT_MEMBERS.iterkeys = OBJECT_MEMBERS.keys;
|
|
|
|
|
|
runtime.memberLookup = function(obj, val, autoescape) { // jshint ignore:line
|
|
|
|
|
|
obj = obj || {};
|
|
|
|
|
|
|
|
|
|
|
|
// If the object is an object, return any of the methods that Python would
|
|
|
|
|
|
// otherwise provide.
|
|
|
|
|
|
if (lib.isArray(obj) && ARRAY_MEMBERS.hasOwnProperty(val)) {
|
|
|
|
|
|
return function() {return ARRAY_MEMBERS[val].apply(obj, arguments);};
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (lib.isObject(obj) && OBJECT_MEMBERS.hasOwnProperty(val)) {
|
|
|
|
|
|
return function() {return OBJECT_MEMBERS[val].apply(obj, arguments);};
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return orig_memberLookup.apply(this, arguments);
|
|
|
|
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
module.exports = installCompat;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/***/ },
|
|
|
|
|
|
/* 39 */
|
2015-08-08 00:11:35 +00:00
|
|
|
|
/***/ function(module, exports, __webpack_require__) {
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
*
|
|
|
|
|
|
* HtmlPrinter (html-printer.js)
|
|
|
|
|
|
* Author: rtfpessoa
|
|
|
|
|
|
*
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
2015-12-20 22:22:58 +00:00
|
|
|
|
(function() {
|
2015-08-08 00:11:35 +00:00
|
|
|
|
|
|
|
|
|
|
var diffParser = __webpack_require__(1).DiffParser;
|
2015-10-19 11:47:49 +00:00
|
|
|
|
var printerUtils = __webpack_require__(4).PrinterUtils;
|
2015-08-08 00:11:35 +00:00
|
|
|
|
var utils = __webpack_require__(2).Utils;
|
2015-12-19 21:09:31 +00:00
|
|
|
|
var Rematch = __webpack_require__(20).Rematch;
|
2015-08-08 00:11:35 +00:00
|
|
|
|
|
2016-02-07 14:19:23 +00:00
|
|
|
|
var matcher = Rematch.rematch(function(a, b) {
|
|
|
|
|
|
var amod = a.content.substr(1);
|
|
|
|
|
|
var bmod = b.content.substr(1);
|
|
|
|
|
|
|
|
|
|
|
|
return Rematch.distance(amod, bmod);
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
function SideBySidePrinter(config) {
|
|
|
|
|
|
this.config = config;
|
2015-08-08 00:11:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2016-02-07 14:19:23 +00:00
|
|
|
|
SideBySidePrinter.prototype.makeDiffHtml = function(file, diffs) {
|
|
|
|
|
|
return '<div id="' + printerUtils.getHtmlId(file) + '" class="d2h-file-wrapper" data-lang="' + file.language + '">\n' +
|
|
|
|
|
|
' <div class="d2h-file-header">\n' +
|
|
|
|
|
|
' <div class="d2h-file-stats">\n' +
|
|
|
|
|
|
' <span class="d2h-lines-added">' +
|
|
|
|
|
|
' <span>+' + file.addedLines + '</span>\n' +
|
|
|
|
|
|
' </span>\n' +
|
|
|
|
|
|
' <span class="d2h-lines-deleted">' +
|
|
|
|
|
|
' <span>-' + file.deletedLines + '</span>\n' +
|
|
|
|
|
|
' </span>\n' +
|
|
|
|
|
|
' </div>\n' +
|
|
|
|
|
|
' <div class="d2h-file-name">' + printerUtils.getDiffName(file) + '</div>\n' +
|
|
|
|
|
|
' </div>\n' +
|
|
|
|
|
|
' <div class="d2h-files-diff">\n' +
|
|
|
|
|
|
' <div class="d2h-file-side-diff">\n' +
|
|
|
|
|
|
' <div class="d2h-code-wrapper">\n' +
|
|
|
|
|
|
' <table class="d2h-diff-table">\n' +
|
|
|
|
|
|
' <tbody class="d2h-diff-tbody">\n' +
|
|
|
|
|
|
' ' + diffs.left +
|
|
|
|
|
|
' </tbody>\n' +
|
|
|
|
|
|
' </table>\n' +
|
|
|
|
|
|
' </div>\n' +
|
|
|
|
|
|
' </div>\n' +
|
|
|
|
|
|
' <div class="d2h-file-side-diff">\n' +
|
|
|
|
|
|
' <div class="d2h-code-wrapper">\n' +
|
|
|
|
|
|
' <table class="d2h-diff-table">\n' +
|
|
|
|
|
|
' <tbody class="d2h-diff-tbody">\n' +
|
|
|
|
|
|
' ' + diffs.right +
|
|
|
|
|
|
' </tbody>\n' +
|
|
|
|
|
|
' </table>\n' +
|
|
|
|
|
|
' </div>\n' +
|
|
|
|
|
|
' </div>\n' +
|
|
|
|
|
|
' </div>\n' +
|
|
|
|
|
|
' </div>\n';
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
SideBySidePrinter.prototype.generateSideBySideJsonHtml = function(diffFiles) {
|
|
|
|
|
|
var that = this;
|
2015-08-08 00:11:35 +00:00
|
|
|
|
return '<div class="d2h-wrapper">\n' +
|
|
|
|
|
|
diffFiles.map(function(file) {
|
|
|
|
|
|
|
|
|
|
|
|
var diffs;
|
|
|
|
|
|
if (file.blocks.length) {
|
2016-02-07 14:19:23 +00:00
|
|
|
|
diffs = that.generateSideBySideFileHtml(file);
|
2015-08-08 00:11:35 +00:00
|
|
|
|
} else {
|
2016-02-07 14:19:23 +00:00
|
|
|
|
diffs = that.generateEmptyDiff();
|
2015-08-08 00:11:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2016-02-07 14:19:23 +00:00
|
|
|
|
return that.makeDiffHtml(file, diffs);
|
2015-08-08 00:11:35 +00:00
|
|
|
|
}).join('\n') +
|
|
|
|
|
|
'</div>\n';
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2016-02-07 14:19:23 +00:00
|
|
|
|
SideBySidePrinter.prototype.makeSideHtml = function(blockHeader) {
|
|
|
|
|
|
return '<tr>\n' +
|
|
|
|
|
|
' <td class="d2h-code-side-linenumber ' + diffParser.LINE_TYPE.INFO + '"></td>\n' +
|
|
|
|
|
|
' <td class="' + diffParser.LINE_TYPE.INFO + '">\n' +
|
|
|
|
|
|
' <div class="d2h-code-side-line ' + diffParser.LINE_TYPE.INFO + '">' + blockHeader + '</div>\n' +
|
|
|
|
|
|
' </td>\n' +
|
|
|
|
|
|
'</tr>\n';
|
|
|
|
|
|
};
|
2015-12-19 21:09:31 +00:00
|
|
|
|
|
2016-02-07 14:19:23 +00:00
|
|
|
|
SideBySidePrinter.prototype.generateSideBySideFileHtml = function(file) {
|
|
|
|
|
|
var that = this;
|
2015-08-08 00:11:35 +00:00
|
|
|
|
var fileHtml = {};
|
|
|
|
|
|
fileHtml.left = '';
|
|
|
|
|
|
fileHtml.right = '';
|
|
|
|
|
|
|
|
|
|
|
|
file.blocks.forEach(function(block) {
|
|
|
|
|
|
|
2016-02-07 14:19:23 +00:00
|
|
|
|
fileHtml.left += that.makeSideHtml(utils.escape(block.header));
|
|
|
|
|
|
fileHtml.right += that.makeSideHtml('');
|
2015-08-08 00:11:35 +00:00
|
|
|
|
|
|
|
|
|
|
var oldLines = [];
|
|
|
|
|
|
var newLines = [];
|
2015-12-20 22:22:58 +00:00
|
|
|
|
|
2015-12-19 21:09:31 +00:00
|
|
|
|
function processChangeBlock() {
|
|
|
|
|
|
var matches;
|
|
|
|
|
|
var insertType;
|
|
|
|
|
|
var deleteType;
|
2016-02-07 14:19:23 +00:00
|
|
|
|
var doMatching = that.config.matching === 'lines' || that.config.matching === 'words';
|
2015-12-20 22:22:58 +00:00
|
|
|
|
|
2015-12-19 21:09:31 +00:00
|
|
|
|
if (doMatching) {
|
|
|
|
|
|
matches = matcher(oldLines, newLines);
|
|
|
|
|
|
insertType = diffParser.LINE_TYPE.INSERT_CHANGES;
|
|
|
|
|
|
deleteType = diffParser.LINE_TYPE.DELETE_CHANGES;
|
|
|
|
|
|
} else {
|
2015-12-20 22:22:58 +00:00
|
|
|
|
matches = [[oldLines, newLines]];
|
2015-12-19 21:09:31 +00:00
|
|
|
|
insertType = diffParser.LINE_TYPE.INSERTS;
|
|
|
|
|
|
deleteType = diffParser.LINE_TYPE.DELETES;
|
|
|
|
|
|
}
|
2015-12-20 22:22:58 +00:00
|
|
|
|
|
|
|
|
|
|
matches.forEach(function(match) {
|
|
|
|
|
|
oldLines = match[0];
|
|
|
|
|
|
newLines = match[1];
|
|
|
|
|
|
|
|
|
|
|
|
var common = Math.min(oldLines.length, newLines.length);
|
|
|
|
|
|
var max = Math.max(oldLines.length, newLines.length);
|
|
|
|
|
|
|
|
|
|
|
|
for (var j = 0; j < common; j++) {
|
|
|
|
|
|
var oldLine = oldLines[j];
|
|
|
|
|
|
var newLine = newLines[j];
|
2015-12-19 21:09:31 +00:00
|
|
|
|
|
2016-02-07 14:19:23 +00:00
|
|
|
|
that.config.isCombined = file.isCombined;
|
2015-12-19 21:09:31 +00:00
|
|
|
|
|
2016-02-07 14:19:23 +00:00
|
|
|
|
var diff = printerUtils.diffHighlight(oldLine.content, newLine.content, that.config);
|
2015-12-19 21:09:31 +00:00
|
|
|
|
|
|
|
|
|
|
fileHtml.left +=
|
2016-02-07 14:19:23 +00:00
|
|
|
|
that.generateSingleLineHtml(deleteType, oldLine.oldNumber,
|
2015-12-19 21:09:31 +00:00
|
|
|
|
diff.first.line, diff.first.prefix);
|
|
|
|
|
|
fileHtml.right +=
|
2016-02-07 14:19:23 +00:00
|
|
|
|
that.generateSingleLineHtml(insertType, newLine.newNumber,
|
2015-12-19 21:09:31 +00:00
|
|
|
|
diff.second.line, diff.second.prefix);
|
2015-12-20 22:22:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (max > common) {
|
|
|
|
|
|
var oldSlice = oldLines.slice(common);
|
|
|
|
|
|
var newSlice = newLines.slice(common);
|
|
|
|
|
|
|
2016-02-07 14:19:23 +00:00
|
|
|
|
var tmpHtml = that.processLines(oldSlice, newSlice);
|
2015-12-20 22:22:58 +00:00
|
|
|
|
fileHtml.left += tmpHtml.left;
|
|
|
|
|
|
fileHtml.right += tmpHtml.right;
|
|
|
|
|
|
}
|
2015-12-19 21:09:31 +00:00
|
|
|
|
});
|
2015-12-20 22:22:58 +00:00
|
|
|
|
|
2015-12-19 21:09:31 +00:00
|
|
|
|
oldLines = [];
|
|
|
|
|
|
newLines = [];
|
|
|
|
|
|
}
|
2015-12-20 22:22:58 +00:00
|
|
|
|
|
2015-08-08 00:11:35 +00:00
|
|
|
|
for (var i = 0; i < block.lines.length; i++) {
|
|
|
|
|
|
var line = block.lines[i];
|
2016-02-07 14:19:23 +00:00
|
|
|
|
var prefix = line.content[0];
|
2015-12-19 21:09:31 +00:00
|
|
|
|
var escapedLine = utils.escape(line.content.substr(1));
|
2015-08-08 00:11:35 +00:00
|
|
|
|
|
2015-12-20 22:22:58 +00:00
|
|
|
|
if (line.type !== diffParser.LINE_TYPE.INSERTS &&
|
|
|
|
|
|
(newLines.length > 0 || (line.type !== diffParser.LINE_TYPE.DELETES && oldLines.length > 0))) {
|
2015-12-19 21:09:31 +00:00
|
|
|
|
processChangeBlock();
|
|
|
|
|
|
}
|
2015-12-20 22:22:58 +00:00
|
|
|
|
|
|
|
|
|
|
if (line.type === diffParser.LINE_TYPE.CONTEXT) {
|
2016-02-07 14:19:23 +00:00
|
|
|
|
fileHtml.left += that.generateSingleLineHtml(line.type, line.oldNumber, escapedLine, prefix);
|
|
|
|
|
|
fileHtml.right += that.generateSingleLineHtml(line.type, line.newNumber, escapedLine, prefix);
|
2015-12-20 22:22:58 +00:00
|
|
|
|
} else if (line.type === diffParser.LINE_TYPE.INSERTS && !oldLines.length) {
|
2016-02-07 14:19:23 +00:00
|
|
|
|
fileHtml.left += that.generateSingleLineHtml(diffParser.LINE_TYPE.CONTEXT, '', '', '');
|
|
|
|
|
|
fileHtml.right += that.generateSingleLineHtml(line.type, line.newNumber, escapedLine, prefix);
|
2015-12-20 22:22:58 +00:00
|
|
|
|
} else if (line.type === diffParser.LINE_TYPE.DELETES) {
|
2015-08-08 00:11:35 +00:00
|
|
|
|
oldLines.push(line);
|
2015-12-20 22:22:58 +00:00
|
|
|
|
} else if (line.type === diffParser.LINE_TYPE.INSERTS && Boolean(oldLines.length)) {
|
2015-08-08 00:11:35 +00:00
|
|
|
|
newLines.push(line);
|
|
|
|
|
|
} else {
|
2015-12-19 21:09:31 +00:00
|
|
|
|
console.error('unknown state in html side-by-side generator');
|
|
|
|
|
|
processChangeBlock();
|
2015-08-08 00:11:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2015-12-19 21:09:31 +00:00
|
|
|
|
processChangeBlock();
|
2015-08-08 00:11:35 +00:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
return fileHtml;
|
2016-02-07 14:19:23 +00:00
|
|
|
|
};
|
2015-08-08 00:11:35 +00:00
|
|
|
|
|
2016-02-07 14:19:23 +00:00
|
|
|
|
SideBySidePrinter.prototype.processLines = function(oldLines, newLines) {
|
|
|
|
|
|
var that = this;
|
2015-08-08 00:11:35 +00:00
|
|
|
|
var fileHtml = {};
|
|
|
|
|
|
fileHtml.left = '';
|
|
|
|
|
|
fileHtml.right = '';
|
|
|
|
|
|
|
|
|
|
|
|
var maxLinesNumber = Math.max(oldLines.length, newLines.length);
|
2015-12-20 22:22:58 +00:00
|
|
|
|
for (var i = 0; i < maxLinesNumber; i++) {
|
|
|
|
|
|
var oldLine = oldLines[i];
|
|
|
|
|
|
var newLine = newLines[i];
|
2015-12-19 21:09:31 +00:00
|
|
|
|
var oldContent;
|
|
|
|
|
|
var newContent;
|
|
|
|
|
|
var oldPrefix;
|
|
|
|
|
|
var newPrefix;
|
2015-12-20 22:22:58 +00:00
|
|
|
|
|
2015-12-19 21:09:31 +00:00
|
|
|
|
if (oldLine) {
|
|
|
|
|
|
oldContent = utils.escape(oldLine.content.substr(1));
|
|
|
|
|
|
oldPrefix = oldLine.content[0];
|
|
|
|
|
|
}
|
2015-12-20 22:22:58 +00:00
|
|
|
|
|
2015-12-19 21:09:31 +00:00
|
|
|
|
if (newLine) {
|
|
|
|
|
|
newContent = utils.escape(newLine.content.substr(1));
|
|
|
|
|
|
newPrefix = newLine.content[0];
|
|
|
|
|
|
}
|
2015-12-20 22:22:58 +00:00
|
|
|
|
|
2015-08-08 00:11:35 +00:00
|
|
|
|
if (oldLine && newLine) {
|
2016-02-07 14:19:23 +00:00
|
|
|
|
fileHtml.left += that.generateSingleLineHtml(oldLine.type, oldLine.oldNumber, oldContent, oldPrefix);
|
|
|
|
|
|
fileHtml.right += that.generateSingleLineHtml(newLine.type, newLine.newNumber, newContent, newPrefix);
|
2015-08-08 00:11:35 +00:00
|
|
|
|
} else if (oldLine) {
|
2016-02-07 14:19:23 +00:00
|
|
|
|
fileHtml.left += that.generateSingleLineHtml(oldLine.type, oldLine.oldNumber, oldContent, oldPrefix);
|
|
|
|
|
|
fileHtml.right += that.generateSingleLineHtml(diffParser.LINE_TYPE.CONTEXT, '', '', '');
|
2015-08-08 00:11:35 +00:00
|
|
|
|
} else if (newLine) {
|
2016-02-07 14:19:23 +00:00
|
|
|
|
fileHtml.left += that.generateSingleLineHtml(diffParser.LINE_TYPE.CONTEXT, '', '', '');
|
|
|
|
|
|
fileHtml.right += that.generateSingleLineHtml(newLine.type, newLine.newNumber, newContent, newPrefix);
|
2015-08-08 00:11:35 +00:00
|
|
|
|
} else {
|
|
|
|
|
|
console.error('How did it get here?');
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return fileHtml;
|
2016-02-07 14:19:23 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
SideBySidePrinter.prototype.makeSingleLineHtml = function(type, number, htmlContent, htmlPrefix) {
|
|
|
|
|
|
return '<tr>\n' +
|
|
|
|
|
|
' <td class="d2h-code-side-linenumber ' + type + '">' + number + '</td>\n' +
|
|
|
|
|
|
' <td class="' + type + '">' +
|
|
|
|
|
|
' <div class="d2h-code-side-line ' + type + '">' + htmlPrefix + htmlContent + '</div>' +
|
|
|
|
|
|
' </td>\n' +
|
|
|
|
|
|
' </tr>\n';
|
|
|
|
|
|
};
|
2015-08-08 00:11:35 +00:00
|
|
|
|
|
2016-02-07 14:19:23 +00:00
|
|
|
|
SideBySidePrinter.prototype.generateSingleLineHtml = function(type, number, content, prefix) {
|
2015-08-08 00:11:35 +00:00
|
|
|
|
var htmlPrefix = '';
|
|
|
|
|
|
if (prefix) {
|
|
|
|
|
|
htmlPrefix = '<span class="d2h-code-line-prefix">' + prefix + '</span>';
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var htmlContent = '';
|
|
|
|
|
|
if (content) {
|
|
|
|
|
|
htmlContent = '<span class="d2h-code-line-ctn">' + content + '</span>';
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-02-07 14:19:23 +00:00
|
|
|
|
return this.makeSingleLineHtml(type, number, htmlContent, htmlPrefix);
|
|
|
|
|
|
};
|
2015-08-08 00:11:35 +00:00
|
|
|
|
|
2016-02-07 14:19:23 +00:00
|
|
|
|
SideBySidePrinter.prototype.generateEmptyDiff = function() {
|
2015-08-08 00:11:35 +00:00
|
|
|
|
var fileHtml = {};
|
|
|
|
|
|
fileHtml.right = '';
|
|
|
|
|
|
|
|
|
|
|
|
fileHtml.left = '<tr>\n' +
|
|
|
|
|
|
' <td class="' + diffParser.LINE_TYPE.INFO + '">' +
|
|
|
|
|
|
' <div class="d2h-code-side-line ' + diffParser.LINE_TYPE.INFO + '">' +
|
|
|
|
|
|
'File without changes' +
|
|
|
|
|
|
' </div>' +
|
|
|
|
|
|
' </td>\n' +
|
|
|
|
|
|
'</tr>\n';
|
|
|
|
|
|
|
|
|
|
|
|
return fileHtml;
|
2016-02-07 14:19:23 +00:00
|
|
|
|
};
|
2015-08-08 00:11:35 +00:00
|
|
|
|
|
2016-02-07 14:19:23 +00:00
|
|
|
|
module.exports.SideBySidePrinter = SideBySidePrinter;
|
2015-08-08 00:11:35 +00:00
|
|
|
|
|
2015-12-20 22:22:58 +00:00
|
|
|
|
})();
|
2015-08-08 00:11:35 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/***/ }
|
|
|
|
|
|
/******/ ]);
|