Comparing version 0.10.24 to 0.10.25
@@ -238,3 +238,3 @@ /* | ||
// dependencies from doing this without warning | ||
if (isDependency && currentView && !serializedViews) { | ||
if (isDependency && currentView && !currentView.fromSerialized) { | ||
throw new Error('Dependencies cannot override existing views. Already registered "' + viewName + '"'); | ||
@@ -241,0 +241,0 @@ } |
{ | ||
"name": "derby", | ||
"description": "MVC framework making it easy to write realtime, collaborative applications that run in both Node.js and browsers.", | ||
"version": "0.10.24", | ||
"version": "0.10.25", | ||
"homepage": "http://derbyjs.com/", | ||
@@ -17,3 +17,3 @@ "repository": { | ||
"derby-parsing": "^0.7.6", | ||
"derby-templates": "^0.7.3", | ||
"derby-templates": "^0.7.4", | ||
"html-util": "^0.2.1", | ||
@@ -20,0 +20,0 @@ "qs": "^6.0.2", |
@@ -68,3 +68,3 @@ var qs = require('qs'); | ||
/** | ||
* Stubs out view names with empty views. | ||
* Stubs out view names with empty view or the provided source. | ||
* | ||
@@ -74,9 +74,18 @@ * A view name is a colon-separated string of segments, as used in `<view is="...">`. | ||
* @example | ||
* var harness = new ComponentHarness('<view is="dialog"/>', Dialog) | ||
* .stub('icons:open-icon', 'icons:close-icon'); | ||
* var harness = new ComponentHarness('<view is="dialog"/>', Dialog).stub( | ||
* 'icons:open-icon', | ||
* 'icons:close-icon', | ||
* {is: 'dialog:buttons', source: '<button>OK</button>'} | ||
* ); | ||
*/ | ||
ComponentHarness.prototype.stub = function() { | ||
for (var i = 0; i < arguments.length; i++) { | ||
var name = arguments[i]; | ||
this.app.views.register(name, ''); | ||
var arg = arguments[i]; | ||
if (typeof arg === 'string') { | ||
this.app.views.register(arg, ''); | ||
} else if (arg && arg.is) { | ||
this.app.views.register(arg.is, arg.source || ''); | ||
} else { | ||
throw new Error('each argument must be the name of a view or an object with an `is` property'); | ||
} | ||
} | ||
@@ -83,0 +92,0 @@ return this; |
var expect = require('chai').expect; | ||
var ComponentHarness = require('../../test-utils').ComponentHarness; | ||
var derbyTemplates = require('../../templates'); | ||
@@ -219,2 +220,42 @@ describe('ComponentHarness', function() { | ||
it('supports view serializing', function() { | ||
function Clown() {} | ||
Clown.view = { | ||
is: 'clown', | ||
source: | ||
'<index:>' + | ||
'<div class="{{getClass()}}"></div>' | ||
}; | ||
Clown.prototype.getClass = function() { | ||
return 'clown'; | ||
}; | ||
function Box() {} | ||
Box.view = { | ||
is: 'box', | ||
source: | ||
'<index:>' + | ||
'<div class="{{getClass()}}">' + | ||
'<view is="clown" />' + | ||
'</div>', | ||
dependencies: [Clown] | ||
}; | ||
Box.prototype.getClass = function() { | ||
return 'box'; | ||
}; | ||
var harness = new ComponentHarness('<view is="box" />', Box); | ||
// Serialize returns JavaScript source code that is written to and | ||
// required from a file. We simulate that by evaling the source | ||
var serializedSource = harness.app.views.serialize(); | ||
var serialized = (new Function('return ' + serializedSource))(); | ||
// This is similar to what would happen in the browser. Derby would inject | ||
// the serialized views, then the application code would execute and | ||
// associate the views with component controllers | ||
var harness2 = new ComponentHarness(); | ||
serialized(derbyTemplates, harness2.app.views); | ||
harness2.app.component(Box); | ||
var html = harness2.renderHtml().html; | ||
expect(html).equal('<div class="box"><div class="clown"></div></div>'); | ||
}); | ||
it('gets overridden without error', function() { | ||
@@ -356,2 +397,30 @@ function ConflictingClown() {} | ||
it('defines source of view when provided', function() { | ||
function Box() {} | ||
Box.view = { | ||
is: 'box', | ||
source: | ||
'<index:>' + | ||
'<div class="box">' + | ||
'<view is="clown" />' + | ||
'<view is="ball" />' + | ||
'<view is="puppy" />' + | ||
'</div>' | ||
}; | ||
var html = new ComponentHarness('<view is="box" />', Box) | ||
.stub( | ||
'clown', | ||
{is: 'ball', source: '<span class="ball"></span>'}, | ||
'puppy' | ||
).renderHtml().html; | ||
expect(html).equal('<div class="box"><span class="ball"></span></div>'); | ||
}); | ||
it('throws error if no view name is provided', function() { | ||
var harness = new ComponentHarness(''); | ||
expect(function() { | ||
harness.stub({source: '<div></div>'}); | ||
}).to.throw(Error); | ||
}); | ||
it('overrides a component dependency with an empty view', function() { | ||
@@ -358,0 +427,0 @@ function Clown() {} |
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
217030
5644
2
Updatedderby-templates@^0.7.4