Skip to content

Commit

Permalink
Ensure templates were compiled with the current compiler version.
Browse files Browse the repository at this point in the history
  • Loading branch information
rwjblue committed Feb 15, 2015
1 parent 081aa43 commit 6c3bc9c
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 3 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
"ember-cli": "0.1.15",
"ember-cli-yuidoc": "^0.4.0",
"ember-publisher": "0.0.7",
"emberjs-build": "0.0.30",
"emberjs-build": "0.0.31",
"express": "^4.5.0",
"github": "^0.2.3",
"glob": "~4.3.2",
"htmlbars": "0.11.0",
"htmlbars": "0.11.1",
"qunit-extras": "^1.3.0",
"qunitjs": "^1.16.0",
"route-recognizer": "0.1.5",
Expand Down
6 changes: 6 additions & 0 deletions packages/ember-htmlbars/lib/system/render-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ export default function renderView(view, buffer, template) {
}

function renderHTMLBarsTemplate(view, buffer, template) {
Ember.assert(
'The template being rendered by `' + view + '` was compiled with `' + template.revision +
'` which does not match `Ember@VERSION_STRING_PLACEHOLDER` (this revision).',
template.revision === 'Ember@VERSION_STRING_PLACEHOLDER'
);

var contextualElement = buffer.innerContextualElement();
var args = view._blockArguments;
var env = {
Expand Down
16 changes: 16 additions & 0 deletions packages/ember-htmlbars/tests/system/render_view_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ QUnit.test('default environment values are passed through', function() {
view = EmberView.create({
template: {
isHTMLBars: true,
revision: 'Ember@VERSION_STRING_PLACEHOLDER',
render: function(view, env, contextualElement, blockArguments) {
for (var i = 0, l = keyNames.length; i < l; i++) {
var keyName = keyNames[i];
Expand All @@ -29,3 +30,18 @@ QUnit.test('default environment values are passed through', function() {

runAppend(view);
});

QUnit.test('Provides a helpful assertion if revisions do not match.', function() {
view = EmberView.create({
template: {
isHTMLBars: true,
revision: 'Foo-Bar-Baz',
render: function() { }
}
});

expectAssertion(function() {
runAppend(view);
},
/was compiled with `Foo-Bar-Baz`/);
});
1 change: 1 addition & 0 deletions packages/ember-routing-htmlbars/lib/helpers/link-to.js
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,7 @@ function linkToHelper(params, hash, options, env) {

options.template = {
isHTMLBars: true,
revision: 'Ember@VERSION_STRING_PLACEHOLDER',
render: function(view, env) {
var value = read(linkTitle) || "";
if (parseTextAsHTML) {
Expand Down
3 changes: 2 additions & 1 deletion packages/ember-template-compiler/lib/compat/precompile.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
@module ember
@submodule ember-template-compiler
*/
import compileOptions from "ember-template-compiler/system/compile_options";

var compile, compileSpec;

Expand All @@ -20,5 +21,5 @@ export default function(string) {
var asObject = arguments[1] === undefined ? true : arguments[1];
var compileFunc = asObject ? compile : compileSpec;

return compileFunc(string);
return compileFunc(string, compileOptions());
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ export default function() {
}

return {
revision: 'Ember@VERSION_STRING_PLACEHOLDER',

disableComponentGeneration: disableComponentGeneration,

plugins: plugins
Expand Down
17 changes: 17 additions & 0 deletions packages/ember-template-compiler/tests/system/compile_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,22 @@ QUnit.test('calls template on the compiled function', function() {
ok(actual.isMethod === false, 'sets isMethod via template function');
});

QUnit.test('includes the current revision in the compiled template', function() {
var templateString = "{{foo}} -- {{some-bar blah='foo'}}";

var actual = compile(templateString);

equal(actual.revision, 'Ember@VERSION_STRING_PLACEHOLDER', 'revision is included in generated template');
});

QUnit.test('the template revision is different than the HTMLBars default revision', function() {
var templateString = "{{foo}} -- {{some-bar blah='foo'}}";

var actual = compile(templateString);
var expected = htmlbarsCompile(templateString);

ok(actual.revision !== expected.revision, 'revision differs from default');
});

// jscs:enable validateIndentation
}
1 change: 1 addition & 0 deletions packages/ember-views/lib/views/select.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ var defaultTemplate = htmlbarsTemplate;

var selectOptionDefaultTemplate = {
isHTMLBars: true,
revision: 'Ember@VERSION_STRING_PLACEHOLDER',
render: function(context, env, contextualElement) {
var lazyValue = context.getStream('view.label');

Expand Down

0 comments on commit 6c3bc9c

Please sign in to comment.