dist/ember-template-compiler.js in ember-source-1.5.1.1 vs dist/ember-template-compiler.js in ember-source-1.6.0.beta.1

- old
+ new

@@ -1,31 +1,40 @@ -(function() { -var Ember = { assert: function() {}, FEATURES: { isEnabled: function() {} } }; /*! * @overview Ember - JavaScript Application Framework * @copyright Copyright 2011-2014 Tilde Inc. and contributors * Portions Copyright 2006-2011 Strobe Inc. * Portions Copyright 2008-2011 Apple Inc. All rights reserved. * @license Licensed under MIT license * See https://raw.github.com/emberjs/ember.js/master/LICENSE - * @version 1.5.1 + * @version 1.6.0-beta.1 */ (function() { +var Ember = { assert: function() {}, FEATURES: { isEnabled: function() {} } }; /** @module ember @submodule ember-handlebars-compiler */ -// Eliminate dependency on any Ember to simplify precompilation workflow + + +// ES6Todo: you'll need to import debugger once debugger is es6'd. +if (typeof Ember.assert === 'undefined') { Ember.assert = function(){}; }; +if (typeof Ember.FEATURES === 'undefined') { Ember.FEATURES = { isEnabled: function(){} }; }; + var objectCreate = Object.create || function(parent) { function F() {} F.prototype = parent; return new F(); }; +// set up for circular references later +var View, Component; + +// ES6Todo: when ember-debug is es6'ed import this. +// var emberAssert = Ember.assert; var Handlebars = (Ember.imports && Ember.imports.Handlebars) || (this && this.Handlebars); if (!Handlebars && typeof require === 'function') { Handlebars = require('handlebars'); } @@ -50,11 +59,11 @@ This will return a function that can be used by `Ember.View` for rendering. @class Handlebars @namespace Ember */ -Ember.Handlebars = objectCreate(Handlebars); +var EmberHandlebars = Ember.Handlebars = objectCreate(Handlebars); /** Register a bound helper or custom view helper. ## Simple bound helper example @@ -105,17 +114,20 @@ @for Ember.Handlebars @param {String} name @param {Function|Ember.View} function or view class constructor @param {String} dependentKeys* */ -Ember.Handlebars.helper = function(name, value) { - Ember.assert("You tried to register a component named '" + name + "', but component names must include a '-'", !Ember.Component.detect(value) || name.match(/-/)); +EmberHandlebars.helper = function(name, value) { + if (!View) { View = requireModule('ember-views/views/view')['View']; } // ES6TODO: stupid circular dep + if (!Component) { Component = requireModule('ember-views/views/component')['default']; } // ES6TODO: stupid circular dep - if (Ember.View.detect(value)) { - Ember.Handlebars.registerHelper(name, Ember.Handlebars.makeViewHelper(value)); + Ember.assert("You tried to register a component named '" + name + "', but component names must include a '-'", !Component.detect(value) || name.match(/-/)); + + if (View.detect(value)) { + EmberHandlebars.registerHelper(name, EmberHandlebars.makeViewHelper(value)); } else { - Ember.Handlebars.registerBoundHelper.apply(null, arguments); + EmberHandlebars.registerBoundHelper.apply(null, arguments); } }; /** Returns a helper function that renders the provided ViewClass. @@ -126,58 +138,58 @@ @private @method makeViewHelper @for Ember.Handlebars @param {Function} ViewClass view class constructor */ -Ember.Handlebars.makeViewHelper = function(ViewClass) { +EmberHandlebars.makeViewHelper = function(ViewClass) { return function(options) { Ember.assert("You can only pass attributes (such as name=value) not bare values to a helper for a View found in '" + ViewClass.toString() + "'", arguments.length < 2); - return Ember.Handlebars.helpers.view.call(this, ViewClass, options); + return EmberHandlebars.helpers.view.call(this, ViewClass, options); }; }; /** @class helpers @namespace Ember.Handlebars */ -Ember.Handlebars.helpers = objectCreate(Handlebars.helpers); +EmberHandlebars.helpers = objectCreate(Handlebars.helpers); /** Override the the opcode compiler and JavaScript compiler for Handlebars. @class Compiler @namespace Ember.Handlebars @private @constructor */ -Ember.Handlebars.Compiler = function() {}; +EmberHandlebars.Compiler = function() {}; // Handlebars.Compiler doesn't exist in runtime-only if (Handlebars.Compiler) { - Ember.Handlebars.Compiler.prototype = objectCreate(Handlebars.Compiler.prototype); + EmberHandlebars.Compiler.prototype = objectCreate(Handlebars.Compiler.prototype); } -Ember.Handlebars.Compiler.prototype.compiler = Ember.Handlebars.Compiler; +EmberHandlebars.Compiler.prototype.compiler = EmberHandlebars.Compiler; /** @class JavaScriptCompiler @namespace Ember.Handlebars @private @constructor */ -Ember.Handlebars.JavaScriptCompiler = function() {}; +EmberHandlebars.JavaScriptCompiler = function() {}; // Handlebars.JavaScriptCompiler doesn't exist in runtime-only if (Handlebars.JavaScriptCompiler) { - Ember.Handlebars.JavaScriptCompiler.prototype = objectCreate(Handlebars.JavaScriptCompiler.prototype); - Ember.Handlebars.JavaScriptCompiler.prototype.compiler = Ember.Handlebars.JavaScriptCompiler; + EmberHandlebars.JavaScriptCompiler.prototype = objectCreate(Handlebars.JavaScriptCompiler.prototype); + EmberHandlebars.JavaScriptCompiler.prototype.compiler = EmberHandlebars.JavaScriptCompiler; } -Ember.Handlebars.JavaScriptCompiler.prototype.namespace = "Ember.Handlebars"; +EmberHandlebars.JavaScriptCompiler.prototype.namespace = "Ember.Handlebars"; -Ember.Handlebars.JavaScriptCompiler.prototype.initializeBuffer = function() { +EmberHandlebars.JavaScriptCompiler.prototype.initializeBuffer = function() { return "''"; }; /** Override the default buffer for Ember Handlebars. By default, Handlebars @@ -186,11 +198,11 @@ @private @method appendToBuffer @param string {String} */ -Ember.Handlebars.JavaScriptCompiler.prototype.appendToBuffer = function(string) { +EmberHandlebars.JavaScriptCompiler.prototype.appendToBuffer = function(string) { return "data.buffer.push("+string+");"; }; // Hacks ahead: // Handlebars presently has a bug where the `blockHelperMissing` hook @@ -206,27 +218,28 @@ var DOT_LOOKUP_REGEX = /helpers\.(.*?)\)/, BRACKET_STRING_LOOKUP_REGEX = /helpers\['(.*?)'/, INVOCATION_SPLITTING_REGEX = /(.*blockHelperMissing\.call\(.*)(stack[0-9]+)(,.*)/; -Ember.Handlebars.JavaScriptCompiler.stringifyLastBlockHelperMissingInvocation = function(source) { +EmberHandlebars.JavaScriptCompiler.stringifyLastBlockHelperMissingInvocation = function(source) { var helperInvocation = source[source.length - 1], helperName = (DOT_LOOKUP_REGEX.exec(helperInvocation) || BRACKET_STRING_LOOKUP_REGEX.exec(helperInvocation))[1], matches = INVOCATION_SPLITTING_REGEX.exec(helperInvocation); source[source.length - 1] = matches[1] + "'" + helperName + "'" + matches[3]; }; -var stringifyBlockHelperMissing = Ember.Handlebars.JavaScriptCompiler.stringifyLastBlockHelperMissingInvocation; -var originalBlockValue = Ember.Handlebars.JavaScriptCompiler.prototype.blockValue; -Ember.Handlebars.JavaScriptCompiler.prototype.blockValue = function() { +var stringifyBlockHelperMissing = EmberHandlebars.JavaScriptCompiler.stringifyLastBlockHelperMissingInvocation; + +var originalBlockValue = EmberHandlebars.JavaScriptCompiler.prototype.blockValue; +EmberHandlebars.JavaScriptCompiler.prototype.blockValue = function() { originalBlockValue.apply(this, arguments); stringifyBlockHelperMissing(this.source); }; -var originalAmbiguousBlockValue = Ember.Handlebars.JavaScriptCompiler.prototype.ambiguousBlockValue; -Ember.Handlebars.JavaScriptCompiler.prototype.ambiguousBlockValue = function() { +var originalAmbiguousBlockValue = EmberHandlebars.JavaScriptCompiler.prototype.ambiguousBlockValue; +EmberHandlebars.JavaScriptCompiler.prototype.ambiguousBlockValue = function() { originalAmbiguousBlockValue.apply(this, arguments); stringifyBlockHelperMissing(this.source); }; /** @@ -237,11 +250,11 @@ @private @method mustache @for Ember.Handlebars.Compiler @param mustache */ -Ember.Handlebars.Compiler.prototype.mustache = function(mustache) { +EmberHandlebars.Compiler.prototype.mustache = function(mustache) { if (!(mustache.params.length || mustache.hash)) { var id = new Handlebars.AST.IdNode([{ part: '_triageMustache' }]); // Update the mustache node to include a hash value indicating whether the original node // was escaped. This will allow us to properly escape values when the underlying value @@ -262,12 +275,14 @@ @method precompile @for Ember.Handlebars @static @param {String} string The template to precompile + @param {Boolean} asObject optional parameter, defaulting to true, of whether or not the + compiled template should be returned as an Object or a String */ -Ember.Handlebars.precompile = function(string) { +EmberHandlebars.precompile = function(string, asObject) { var ast = Handlebars.parse(string); var options = { knownHelpers: { action: true, @@ -279,12 +294,14 @@ }, data: true, stringParams: true }; - var environment = new Ember.Handlebars.Compiler().compile(ast, options); - return new Ember.Handlebars.JavaScriptCompiler().compile(environment, options, undefined, true); + asObject = asObject === undefined ? true : asObject; + + var environment = new EmberHandlebars.Compiler().compile(ast, options); + return new EmberHandlebars.JavaScriptCompiler().compile(environment, options, undefined, asObject); }; // We don't support this for Handlebars runtime-only if (Handlebars.compile) { /** @@ -296,25 +313,23 @@ @for Ember.Handlebars @static @param {String} string The template to compile @return {Function} */ - Ember.Handlebars.compile = function(string) { + EmberHandlebars.compile = function(string) { var ast = Handlebars.parse(string); var options = { data: true, stringParams: true }; - var environment = new Ember.Handlebars.Compiler().compile(ast, options); - var templateSpec = new Ember.Handlebars.JavaScriptCompiler().compile(environment, options, undefined, true); + var environment = new EmberHandlebars.Compiler().compile(ast, options); + var templateSpec = new EmberHandlebars.JavaScriptCompiler().compile(environment, options, undefined, true); - var template = Ember.Handlebars.template(templateSpec); + var template = EmberHandlebars.template(templateSpec); template.isMethod = false; //Make sure we don't wrap templates with ._super return template; }; } -})(); - -exports.precompile = Ember.Handlebars.precompile; -exports.EmberHandlebars = Ember.Handlebars; +exports.precompile = EmberHandlebars.precompile; +exports.EmberHandlebars = EmberHandlebars; })(); \ No newline at end of file