Skip to content

Commit

Permalink
adding raw template to decorator
Browse files Browse the repository at this point in the history
  • Loading branch information
Traksewt committed Dec 2, 2016
1 parent bb87620 commit 316f53e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/services/builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -277,8 +277,8 @@ angular.module('schemaForm').provider('sfBuilder', ['sfPathProvider', function(s
*/
build: function(form, decorator, slots, lookup) {
return build(form, decorator, function(form, field) {
if (form.type === 'template') {
return form.template;
if (field.type === 'template') {
return field.template;
}
return $templateCache.get(field.template);
}, slots, undefined, undefined, lookup);
Expand Down
24 changes: 24 additions & 0 deletions test/services/decorators-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,30 @@ describe('schemaFormDecorators', function() {
var templateWithWrap = angular.element('<div id="wrap"><foobar form="{ type: \'foo\'}"></foobar></div>');
var template = templateWithWrap.children().eq(0);

$compile(template)($rootScope);
$rootScope.$apply();
templateWithWrap.children().length.should.equal(1);
templateWithWrap.children().is('foobar').should.be.true;
templateWithWrap.children().eq(0).children().length.should.equal(1);
templateWithWrap.children().eq(0).children().is('div').should.be.true;
templateWithWrap.children().eq(0).children().hasClass('yes').should.be.true;
});
});
});
describe('#createDecoratorWithRawTemplate', function() {
it('should enable you to create new decorator directives',function(){
module(function(schemaFormDecoratorsProvider){
schemaFormDecoratorsProvider.defineDecorator('foobar',{
'foo': {template: '<div class="yes">YES</div>', replace: true, type: 'template'}
},[angular.noop]);
});

inject(function($rootScope,$compile){

//Since our directive does a replace we need a wrapper to actually check the content.
var templateWithWrap = angular.element('<div id="wrap"><foobar form="{ type: \'foo\'}"></foobar></div>');
var template = templateWithWrap.children().eq(0);

$compile(template)($rootScope);
$rootScope.$apply();
templateWithWrap.children().length.should.equal(1);
Expand Down

0 comments on commit 316f53e

Please sign in to comment.