diff2html
Advanced tools
Comparing version 2.0.0-beta12 to 2.0.0-beta13
{ | ||
"name": "diff2html", | ||
"version": "2.0.0-beta12", | ||
"version": "2.0.0-beta13", | ||
"homepage": "http://rtfpessoa.github.io/diff2html/", | ||
@@ -41,5 +41,5 @@ "description": "Fast Diff to colorized HTML", | ||
"templates": "./scripts/hulk.js --wrapper node --variable 'browserTemplates' ./src/templates/*.mustache > ./src/templates/diff2html-templates.js", | ||
"test": "istanbul cover -x '**/templates/**' -x 'rematch.js' _mocha -- -u exports -R spec ./test/**/*", | ||
"test": "istanbul cover _mocha -- -u exports -R spec ./test/**/*", | ||
"style": "jscs src test", | ||
"codacy": "istanbul cover -x '**/templates/**' -x 'rematch.js' _mocha -- -u exports -R spec ./test/**/* && cat ./coverage/lcov.info | codacy-coverage" | ||
"codacy": "istanbul cover _mocha -- -u exports -R spec ./test/**/* && cat ./coverage/lcov.info | codacy-coverage" | ||
}, | ||
@@ -46,0 +46,0 @@ "main": "./src/diff2html.js", |
@@ -26,3 +26,5 @@ /* | ||
DiffParser.prototype.generateDiffJson = function(diffInput, config) { | ||
DiffParser.prototype.generateDiffJson = function(diffInput, configuration) { | ||
var config = configuration || {}; | ||
var files = []; | ||
@@ -32,2 +34,3 @@ var currentFile = null; | ||
var oldLine = null; | ||
var oldLine2 = null; // Used for combined diff | ||
var newLine = null; | ||
@@ -72,14 +75,32 @@ | ||
if (values = /^@@ -(\d+),\d+ \+(\d+),\d+ @@.*/.exec(line)) { | ||
/** | ||
* From Range: | ||
* -<start line>[,<number of lines>] | ||
* | ||
* To Range: | ||
* +<start line>[,<number of lines>] | ||
* | ||
* @@ from-file-range to-file-range @@ | ||
* | ||
* @@@ from-file-range from-file-range to-file-range @@@ | ||
* | ||
* number of lines is optional, if omited consider 0 | ||
*/ | ||
if (values = /^@@ -(\d+)(?:,\d+)? \+(\d+)(?:,\d+)? @@.*/.exec(line)) { | ||
currentFile.isCombined = false; | ||
} else if (values = /^@@@ -(\d+),\d+ -\d+,\d+ \+(\d+),\d+ @@@.*/.exec(line)) { | ||
oldLine = values[1]; | ||
newLine = values[2]; | ||
} else if (values = /^@@@ -(\d+)(?:,\d+)? -(\d+)(?:,\d+)? \+(\d+)(?:,\d+)? @@@.*/.exec(line)) { | ||
currentFile.isCombined = true; | ||
oldLine = values[1]; | ||
oldLine2 = values[2]; | ||
newLine = values[3]; | ||
} else { | ||
values = [0, 0]; | ||
console.error("Failed to parse lines, starting in 0!"); | ||
oldLine = 0; | ||
newLine = 0; | ||
currentFile.isCombined = false; | ||
} | ||
oldLine = values[1]; | ||
newLine = values[2]; | ||
/* Create block metadata */ | ||
@@ -89,2 +110,3 @@ currentBlock = {}; | ||
currentBlock.oldStartLine = oldLine; | ||
currentBlock.oldStartLine2 = oldLine2; | ||
currentBlock.newStartLine = newLine; | ||
@@ -91,0 +113,0 @@ currentBlock.header = line; |
@@ -15,3 +15,3 @@ /* | ||
var hoganTemplates; | ||
var hoganTemplates = require('./templates/diff2html-templates.js'); | ||
@@ -22,13 +22,9 @@ var templatesPath = path.resolve(__dirname, 'templates'); | ||
function HoganJsUtils() { | ||
try { | ||
hoganTemplates = require('./templates/diff2html-templates.js'); | ||
} catch (_ignore) { | ||
hoganTemplates = {}; | ||
} | ||
} | ||
HoganJsUtils.prototype.render = function(namespace, view, params) { | ||
HoganJsUtils.prototype.render = function(namespace, view, params, configuration) { | ||
var config = configuration || {}; | ||
var templateKey = this._templateKey(namespace, view); | ||
var template = this._getTemplate(templateKey); | ||
var template = this._getTemplate(templateKey, config); | ||
if (template) { | ||
@@ -41,5 +37,9 @@ return template.render(params); | ||
HoganJsUtils.prototype._getTemplate = function(templateKey) { | ||
var template = this._readFromCache(templateKey); | ||
HoganJsUtils.prototype._getTemplate = function(templateKey, config) { | ||
var template; | ||
if (!config.noCache) { | ||
template = this._readFromCache(templateKey); | ||
} | ||
if (!template) { | ||
@@ -54,7 +54,12 @@ template = this._loadTemplate(templateKey); | ||
var template; | ||
if (fs.readFileSync) { | ||
var templatePath = path.join(templatesPath, templateKey); | ||
var templateContent = fs.readFileSync(templatePath + '.mustache', 'utf8'); | ||
template = hogan.compile(templateContent); | ||
templatesCache[templateKey] = template; | ||
try { | ||
if (fs.readFileSync) { | ||
var templatePath = path.join(templatesPath, templateKey); | ||
var templateContent = fs.readFileSync(templatePath + '.mustache', 'utf8'); | ||
template = hogan.compile(templateContent); | ||
templatesCache[templateKey] = template; | ||
} | ||
} catch (e) { | ||
console.error('Failed to read (template: ' + templateKey + ') from fs: ' + e.message); | ||
} | ||
@@ -61,0 +66,0 @@ |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
316503
5816