it('should pass the provided context to the view', function() { var NestedView = Chiropractor.View.extend({ template: '{{ text }}' }); var View = Chiropractor.View.extend({ context: { View: NestedView, data: [{text: 'a'}, {text: 'b'}, {text: 'c'}] }, template: '{{#each data}}{{ view ../View null .. context=this }}{{/each}}' }); this.view = new View(); expect(this.view.render().$el.html()) .to.equal('<div>a</div><div>b</div><div>c</div>'); });
it('should allow referencing views as variables.', function() { var VarView = Chiropractor.View.extend({ template: 'hello' }), View = Chiropractor.View.extend({ template: 'Test ' + '{{ view VarView }}', context: { VarView: VarView } }); this.view = new View(); expect(this.view.render().$el.html()) .to.equal('Test <div>hello</div>'); });
'the only content being rendered.', function() { var View = Chiropractor.View.extend({ template: '{{#view "specs/hbs/view-templates"}}Test{{/view}}' }); this.view = new View(); expect(this.view.render().$el.html()) .to.equal('<div>Test</div>'); });
it('should allow providing a template as a block', function() { var VarView = Chiropractor.View.extend({ context: {hello: 'hello!'} }), View = Chiropractor.View.extend({ template: 'Test ' + '{{#view VarView}}{{ hello }}{{ there }}{{/view}}', context: { there: 'there!', VarView: VarView } }); this.view = new View(); expect(this.view.render().$el.html()) .to.equal('Test <div>hello!</div>'); });
'tempalte', function() { var VarView = Chiropractor.View.extend({ context: {hello: 'hello!'} }), View = Chiropractor.View.extend({ template: '<div>Parent' + '{{#view VarView}}{{ hello }}{{/view}}' + 'Parent</div>', context: { VarView: VarView } }); this.view = new View(); expect(this.view.render().$el.html()) .to.equal('<div>Parent<div>hello!</div>Parent</div>'); });
'a module that returns an associative array', function() { var View = Chiropractor.View.extend({ template: 'Test ' + '{{ view "specs/hbs/view-templates|View" }}' }); this.view = new View(); expect(this.view.render().$el.html()) .to.equal('Test <div>two</div>'); });
'from a module', function() { var View = Chiropractor.View.extend({ template: 'Test ' + '{{ view "specs/hbs/view-templates" }}' }); this.view = new View(); expect(this.view.render().$el.html()) .to.equal('Test <div>one</div>'); });
it('should not leak the parent context to the child', function() { var View = Chiropractor.View.extend({ context: {one: 1, two: 2, sub: {three: 3}}, template: 'Test {{ one }} - {{ two }} ' + '{{ view "specs/hbs/view-templates|Leak" sub }}' }); this.view = new View(); expect(this.view.render().$el.html()) .to.equal('Test 1 - 2 <div> - - 3</div>'); });
it('should pass the provided context to the view', function() { var View = Chiropractor.View.extend({ context: {one: 1, two: 2, sub: {three: 3}}, template: 'Test {{ one }} - {{ two }} ' + '{{ view "specs/hbs/view-templates|Context" sub }}' }); this.view = new View(); expect(this.view.render().$el.html()) .to.equal('Test 1 - 2 <div>3</div>'); });
define(function (require) { 'use strict'; var $ = require('jquery'), _ = require("underscore"), Chiropractor = require("chiropractor"), template = require('hbs!../templates/base'), Base; // Base View Base = Chiropractor.View.extend({ template: template }); return Base; });