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 Jan 24, 2017
1 parent 1af2292 commit daecafe
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
26 changes: 26 additions & 0 deletions src/services/schema-form-decorators.provider.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,30 @@ describe('schemaFormDecorators', function() {
});
});
});

describe('#legacy #defineDecoratorWithRawTemplate', 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);
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;
});
});
});

});
4 changes: 2 additions & 2 deletions src/services/sf-builder.provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -326,8 +326,8 @@ export default function(sfPathProvider) {
*/
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

0 comments on commit daecafe

Please sign in to comment.