Beispiel #1
0
 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>');
 });
Beispiel #2
0
      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>');
      });
Beispiel #3
0
               '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>');
 });
Beispiel #4
0
      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>');
      });
Beispiel #5
0
               '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>');
      });
Beispiel #6
0
          '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>');
 });
Beispiel #7
0
          '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>');
 });
Beispiel #8
0
 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>');
 });
Beispiel #9
0
 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>');
 });
Beispiel #10
0
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;
});