Allow uncompiled templates
This commit is contained in:
parent
2aaae31cc2
commit
f3cadb9667
3 changed files with 33 additions and 1 deletions
|
|
@ -98,6 +98,9 @@ The HTML output accepts a Javascript object with configuration. Possible options
|
||||||
- `synchronisedScroll`: scroll both panes in side-by-side mode: `true` or `false`, default is `false`
|
- `synchronisedScroll`: scroll both panes in side-by-side mode: `true` or `false`, default is `false`
|
||||||
- `matchWordsThreshold`: similarity threshold for word matching, default is 0.25
|
- `matchWordsThreshold`: similarity threshold for word matching, default is 0.25
|
||||||
- `matchingMaxComparisons`: perform at most this much comparisons for line matching a block of changes, default is `2500`
|
- `matchingMaxComparisons`: perform at most this much comparisons for line matching a block of changes, default is `2500`
|
||||||
|
- `templates`: object with previously compiled templates to replace parts of the html
|
||||||
|
- `rawTemplates`: object with raw not compiled templates to replace parts of the html
|
||||||
|
> For more information regarding the possible templates look into [src/templates](https://github.com/rtfpessoa/diff2html/tree/master/src/templates)
|
||||||
|
|
||||||
## Diff2HtmlUI Helper
|
## Diff2HtmlUI Helper
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,13 @@
|
||||||
function HoganJsUtils(configuration) {
|
function HoganJsUtils(configuration) {
|
||||||
this.config = configuration || {};
|
this.config = configuration || {};
|
||||||
extraTemplates = this.config.templates || {};
|
extraTemplates = this.config.templates || {};
|
||||||
|
|
||||||
|
var rawTemplates = this.config.rawTemplates || {};
|
||||||
|
for (var templateName in rawTemplates) {
|
||||||
|
if (rawTemplates.hasOwnProperty(templateName)) {
|
||||||
|
if (!extraTemplates[templateName]) extraTemplates[templateName] = this.compile(rawTemplates[templateName]);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
HoganJsUtils.prototype.render = function(namespace, view, params) {
|
HoganJsUtils.prototype.render = function(namespace, view, params) {
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,7 @@ describe('HoganJsUtils', function() {
|
||||||
assert.equal(null, result);
|
assert.equal(null, result);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should allow templates to be overridden', function() {
|
it('should allow templates to be overridden with compiled templates', function() {
|
||||||
var emptyDiffTemplate = HoganJsUtils.compile('<p>{{myName}}</p>');
|
var emptyDiffTemplate = HoganJsUtils.compile('<p>{{myName}}</p>');
|
||||||
|
|
||||||
var config = {templates: {'generic-empty-diff': emptyDiffTemplate}};
|
var config = {templates: {'generic-empty-diff': emptyDiffTemplate}};
|
||||||
|
|
@ -44,5 +44,27 @@ describe('HoganJsUtils', function() {
|
||||||
var result = hoganUtils.render('generic', 'empty-diff', {myName: 'Rodrigo Fernandes'});
|
var result = hoganUtils.render('generic', 'empty-diff', {myName: 'Rodrigo Fernandes'});
|
||||||
assert.equal('<p>Rodrigo Fernandes</p>', result);
|
assert.equal('<p>Rodrigo Fernandes</p>', result);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should allow templates to be overridden with uncompiled templates', function() {
|
||||||
|
var emptyDiffTemplate = '<p>{{myName}}</p>';
|
||||||
|
|
||||||
|
var config = {rawTemplates: {'generic-empty-diff': emptyDiffTemplate}};
|
||||||
|
var hoganUtils = new (require('../src/hoganjs-utils.js').HoganJsUtils)(config);
|
||||||
|
var result = hoganUtils.render('generic', 'empty-diff', {myName: 'Rodrigo Fernandes'});
|
||||||
|
assert.equal('<p>Rodrigo Fernandes</p>', result);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should allow templates to be overridden giving priority to compiled templates', function() {
|
||||||
|
var emptyDiffTemplate = HoganJsUtils.compile('<p>{{myName}}</p>');
|
||||||
|
var emptyDiffTemplateUncompiled = '<p>Not used!</p>';
|
||||||
|
|
||||||
|
var config = {
|
||||||
|
templates: {'generic-empty-diff': emptyDiffTemplate},
|
||||||
|
rawTemplates: {'generic-empty-diff': emptyDiffTemplateUncompiled}
|
||||||
|
};
|
||||||
|
var hoganUtils = new (require('../src/hoganjs-utils.js').HoganJsUtils)(config);
|
||||||
|
var result = hoganUtils.render('generic', 'empty-diff', {myName: 'Rodrigo Fernandes'});
|
||||||
|
assert.equal('<p>Rodrigo Fernandes</p>', result);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue