Skip to content

Commit

Permalink
Restore 1.12 compatibility
Browse files Browse the repository at this point in the history
We now build the addon based on your Ember version, with builds prior to 1.13 maintaining the original initializer.
  • Loading branch information
Lindsey Smith committed Jun 24, 2015
1 parent 7ef067b commit 66a1b26
Show file tree
Hide file tree
Showing 10 changed files with 63 additions and 19 deletions.
6 changes: 0 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,6 @@ This addon should be installed inside of an ember-cli project.
ember install ember-islands
```

If you're using a version of Ember prior to 1.13, install the `0.5.1` version, like so:

```
ember install ember-islands@0.5.1
```

## Usage

```html
Expand Down
12 changes: 7 additions & 5 deletions addon/deactivate-routing.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import Ember from 'ember';
var noop = Ember.K;

export default function deactivateRouting(instance) {
if (instance.startRouting) {
instance.startRouting = noop;
export default function deactivateRouting(instance_or_application) {
if (instance_or_application.startRouting) {
instance_or_application.startRouting = noop;
} else if (instance_or_application.__deprecatedInstance__ && instance_or_application.__deprecatedInstance__.startRouting) {
instance_or_application.__deprecatedInstance__.startRouting = noop;
} else {
Ember.assert("ember-islands doesn't know how to cancel routing for this" +
"version of Ember. Please report this issue to https://github.com/mitchlloyd/ember-islands" +
`with the version of Ember you are using (Ember.VERSION)`);
"version of Ember. Please report this issue to https://github.com/mitchlloyd/ember-islands" +
`with the version of Ember you are using (${Ember.VERSION})`);
}
}
19 changes: 15 additions & 4 deletions addon/render-components.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,19 @@ var $ = Ember.$;

// Do a little dance with Ember to create a function that can render
// components for the given application.
export function getRenderComponentFor(instance) {
var container = instance.container;
export function getRenderComponentFor(instance_or_application) {

var container;
if (instance_or_application.container) {
container = instance_or_application.container;
} else if (instance_or_application.__container__) {
container = instance_or_application.__container__;
} else {
Ember.assert("ember-islands doesn't know how to render components for this" +
"version of Ember. Please report this issue to https://github.com/mitchlloyd/ember-islands" +
`with the version of Ember you are using (${Ember.VERSION})`);
}

var componentLookup = container.lookup('component-lookup:main');

return function renderComponent(name, attributes, element) {
Expand All @@ -32,8 +43,8 @@ function componentAttributes(element) {
return attrs;
}

export default function renderComponents(instance) {
var renderComponent = getRenderComponentFor(instance);
export default function renderComponents(instance_or_application) {
var renderComponent = getRenderComponentFor(instance_or_application);

$('[data-component]').each(function() {
var name = this.getAttribute('data-component');
Expand Down
File renamed without changes.
20 changes: 20 additions & 0 deletions app/prefastboot/initializers/boot-ember-islands.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import Ember from 'ember';
import deactivateRouting from 'ember-islands/deactivate-routing';
import renderComponents from 'ember-islands/render-components';
var get = Ember.get;

export function initialize(registry, application) {
if (get(application, 'EMBER_ISLANDS.bypass')) {
return;
}

deactivateRouting(application);
renderComponents(application);
};

export default {
name: 'boot-ember-islands',
after: 'registerComponentLookup',
initialize: initialize
};

1 change: 0 additions & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"ember": "1.13.2",
"ember-cli-shims": "ember-cli/ember-cli-shims#0.0.3",
"ember-cli-test-loader": "ember-cli-test-loader#0.1.3",
"ember-data": "1.0.0-beta.16.1",
"ember-load-initializers": "ember-cli/ember-load-initializers#0.1.4",
"ember-qunit": "0.3.1",
"ember-qunit-notifications": "0.0.7",
Expand Down
6 changes: 6 additions & 0 deletions config/ember-try.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
module.exports = {
scenarios: [
{
name: 'Ember 1.12',
dependencies: {
'ember': '1.12.1'
}
},
{
name: 'Ember 1.13',
dependencies: {
Expand Down
14 changes: 13 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
/* jshint node: true */
'use strict';

var path = require('path');
var VersionChecker = require('ember-cli-version-checker');

module.exports = {
name: 'ember-islands'
name: 'ember-islands',

treeForApp: function (tree) {
var checker = new VersionChecker(this);
var dep = checker.for('ember', 'bower');

var version = dep.satisfies('<= 1.12') ? 'prefastboot' : 'fastboot';

return this.treeGenerator(path.join(this.root, 'app', version));
}
};
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
"ember-cli-inject-live-reload": "^1.3.0",
"ember-cli-qunit": "0.3.10",
"ember-cli-uglify": "1.0.1",
"ember-data": "1.0.0-beta.16.1",
"ember-export-application-global": "^1.0.2",
"ember-disable-prototype-extensions": "^1.0.0",
"ember-try": "0.0.7"
Expand All @@ -39,7 +38,8 @@
"ujs"
],
"dependencies": {
"ember-cli-babel": "^5.0.0"
"ember-cli-babel": "^5.0.0",
"ember-cli-version-checker": "^1.1.3"
},
"ember-addon": {
"configPath": "tests/dummy/config"
Expand Down

0 comments on commit 66a1b26

Please sign in to comment.