diff --git a/package.json b/package.json index 1e32a77a78d..e9d065d6998 100644 --- a/package.json +++ b/package.json @@ -23,6 +23,7 @@ "htmlbars": "0.8.1", "qunit-extras": "^1.3.0", "qunitjs": "^1.16.0", - "rsvp": "~3.0.6" + "rsvp": "~3.0.6", + "simple-dom": "^0.1.1" } } diff --git a/packages/ember-views/lib/main.js b/packages/ember-views/lib/main.js index ab2fe583dda..3ab0b02b944 100644 --- a/packages/ember-views/lib/main.js +++ b/packages/ember-views/lib/main.js @@ -16,6 +16,8 @@ import { getViewBoundingClientRect } from "ember-views/system/utils"; import RenderBuffer from "ember-views/system/render_buffer"; +import Renderer from "ember-views/system/renderer"; +import { DOMHelper } from "morph"; import "ember-views/system/ext"; // for the side effect of extending Ember.run.queues import { cloneStates, @@ -68,6 +70,8 @@ Ember.CoreView = CoreView; Ember.View = View; Ember.View.states = states; Ember.View.cloneStates = cloneStates; +Ember.View.DOMHelper = DOMHelper; +Ember.View._Renderer = Renderer; Ember.Checkbox = Checkbox; Ember.TextField = TextField; Ember.TextArea = TextArea; diff --git a/packages/ember-views/lib/system/render_buffer.js b/packages/ember-views/lib/system/render_buffer.js index 3d77efb8f8f..b22e3494605 100644 --- a/packages/ember-views/lib/system/render_buffer.js +++ b/packages/ember-views/lib/system/render_buffer.js @@ -520,7 +520,7 @@ RenderBuffer.prototype = { this.dom.detectNamespace(contextualElement); if (!this._element) { - this._element = document.createDocumentFragment(); + this._element = this.dom.createDocumentFragment(); } if (content.nodeType) { diff --git a/packages/ember-views/lib/views/view.js b/packages/ember-views/lib/views/view.js index ac9c6943103..48e2abca6af 100644 --- a/packages/ember-views/lib/views/view.js +++ b/packages/ember-views/lib/views/view.js @@ -1878,9 +1878,11 @@ var View = CoreView.extend({ var attrs = _attrs || {}; var view; attrs._parentView = this; + attrs.renderer = this.renderer; if (CoreView.detect(maybeViewClass)) { attrs.container = this.container; + view = maybeViewClass.create(attrs); // don't set the property on a virtual view, as they are invisible to diff --git a/tests/node/app-boot-test.js b/tests/node/app-boot-test.js index 41affaf5528..95146a74d58 100644 --- a/tests/node/app-boot-test.js +++ b/tests/node/app-boot-test.js @@ -3,19 +3,116 @@ var path = require('path'); var distPath = path.join(__dirname, '../../dist'); +/*jshint -W079 */ +var Ember = require(path.join(distPath, 'ember.debug.cjs')); +Ember.testing = true; +var DOMHelper = Ember.View.DOMHelper; +var SimpleDOM = require('simple-dom'); + QUnit.module("App boot"); QUnit.test("App is created without throwing an exception", function() { - var Ember = require(path.join(distPath, 'ember.debug.cjs')); + var App; + + Ember.run(function() { + App = Ember.Application.create(); - var App = Ember.Application.create({ + App.Router = Ember.Router.extend({ + location: 'none' + }); + + App.advanceReadiness(); }); - App.Router = Ember.Router.extend({ - location: 'none' + QUnit.ok(App); +}); + +QUnit.test("It is possible to render a view in Node", function() { + var View = Ember.View.extend({ + renderer: new Ember.View._Renderer(new DOMHelper(new SimpleDOM.Document())), + template: Ember.Handlebars.compile("

Hello

") }); - App.advanceReadiness(); + var morph = { + contextualElement: {}, + setContent: function(element) { + this.element = element; + } + }; - QUnit.ok(App); + var view = View.create({ + _domHelper: new DOMHelper(new SimpleDOM.Document()), + _morph: morph + }); + + var renderer = view.renderer; + + Ember.run(function() { + renderer.renderTree(view); + }); + + var serializer = new SimpleDOM.HTMLSerializer(SimpleDOM.voidMap); + ok(serializer.serialize(morph.element).match(/

Hello<\/h1>/)); +}); + +QUnit.test("It is possible to render a view with curlies in Node", function() { + var View = Ember.Component.extend({ + renderer: new Ember.View._Renderer(new DOMHelper(new SimpleDOM.Document())), + layout: Ember.Handlebars.compile("

Hello {{location}}

"), + location: "World" + }); + + var morph = { + contextualElement: {}, + setContent: function(element) { + this.element = element; + } + }; + + var view = View.create({ + _domHelper: new DOMHelper(new SimpleDOM.Document()), + _morph: morph + }); + + var renderer = view.renderer; + + Ember.run(function() { + renderer.renderTree(view); + }); + + var serializer = new SimpleDOM.HTMLSerializer(SimpleDOM.voidMap); + ok(serializer.serialize(morph.element).match(/

Hello World<\/h1>/)); +}); + +QUnit.test("It is possible to render a view with a nested {{view}} helper in Node", function() { + var View = Ember.Component.extend({ + renderer: new Ember.View._Renderer(new DOMHelper(new SimpleDOM.Document())), + layout: Ember.Handlebars.compile("

Hello {{#if hasExistence}}{{location}}{{/if}}

{{view bar}}
"), + location: "World", + hasExistence: true, + bar: Ember.View.extend({ + template: Ember.Handlebars.compile("

The files are *inside* the computer?!

") + }) + }); + + var morph = { + contextualElement: {}, + setContent: function(element) { + this.element = element; + } + }; + + var view = View.create({ + _domHelper: new DOMHelper(new SimpleDOM.Document()), + _morph: morph + }); + + var renderer = view.renderer; + + Ember.run(function() { + renderer.renderTree(view); + }); + + var serializer = new SimpleDOM.HTMLSerializer(SimpleDOM.voidMap); + ok(serializer.serialize(morph.element).match(/

Hello World<\/h1>

The files are \*inside\* the computer\?\!<\/p><\/div><\/div>/)); });