Provide Handlebars.noConflict implementation
Allows for users who are loading via a global pattern to avoid conflicting with other instances of the library. Fixes #887
This commit is contained in:
Vendored
+1
-1
@@ -5,7 +5,7 @@ var _ = require('underscore'),
|
||||
fs = require('fs'),
|
||||
vm = require('vm');
|
||||
|
||||
global.Handlebars = undefined;
|
||||
global.Handlebars = 'no-conflict';
|
||||
vm.runInThisContext(fs.readFileSync(__dirname + '/../../dist/handlebars.js'), 'dist/handlebars.js');
|
||||
|
||||
global.CompilerContext = {
|
||||
|
||||
Vendored
+3
-1
@@ -5,7 +5,7 @@ var _ = require('underscore'),
|
||||
fs = require('fs'),
|
||||
vm = require('vm');
|
||||
|
||||
global.Handlebars = undefined;
|
||||
global.Handlebars = 'no-conflict';
|
||||
vm.runInThisContext(fs.readFileSync(__dirname + '/../../dist/handlebars.runtime.js'), 'dist/handlebars.runtime.js');
|
||||
|
||||
var parse = require('../../dist/cjs/handlebars/compiler/base').parse;
|
||||
@@ -13,6 +13,8 @@ var compiler = require('../../dist/cjs/handlebars/compiler/compiler');
|
||||
var JavaScriptCompiler = require('../../dist/cjs/handlebars/compiler/javascript-compiler')['default'];
|
||||
|
||||
global.CompilerContext = {
|
||||
browser: true,
|
||||
|
||||
compile: function(template, options) {
|
||||
// Hack the compiler on to the environment for these specific tests
|
||||
handlebarsEnv.precompile = function(template, options) {
|
||||
|
||||
@@ -60,4 +60,22 @@ describe('runtime', function() {
|
||||
equal(template._child(1, undefined, [{bar: 'baz'}])(), 'baz');
|
||||
});
|
||||
});
|
||||
|
||||
describe('#noConflict', function() {
|
||||
if (!CompilerContext.browser) {
|
||||
return;
|
||||
}
|
||||
|
||||
it('should reset on no conflict', function() {
|
||||
var reset = Handlebars;
|
||||
Handlebars.noConflict();
|
||||
equal(Handlebars, 'no-conflict');
|
||||
|
||||
Handlebars = 'really, none';
|
||||
reset.noConflict();
|
||||
equal(Handlebars, 'really, none');
|
||||
|
||||
Handlebars = reset;
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user