Skip to content

Commit

Permalink
Upgrade & Implement Fastboot support (#12)
Browse files Browse the repository at this point in the history
* bumping ember

* running codemods

* making this work in fastboot

* updating package.json

* stopping double build on travis

* trying to fix travis

* fixing travis

* fixing bug with ember-try

* fixing tests

* fixing tests
  • Loading branch information
mansona committed May 3, 2018
1 parent 5dcc605 commit 1df34bb
Show file tree
Hide file tree
Showing 38 changed files with 11,386 additions and 341 deletions.
4 changes: 0 additions & 4 deletions .bowerrc

This file was deleted.

14 changes: 0 additions & 14 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,8 @@ insert_final_newline = true
indent_style = space
indent_size = 2

[*.js]
indent_style = space
indent_size = 2

[*.hbs]
insert_final_newline = false
indent_style = space
indent_size = 2

[*.css]
indent_style = space
indent_size = 2

[*.html]
indent_style = space
indent_size = 2

[*.{diff,md}]
trim_trailing_whitespace = false
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/blueprints/*/files/**/*.js
50 changes: 50 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
module.exports = {
root: true,
parserOptions: {
ecmaVersion: 2017,
sourceType: 'module'
},
plugins: [
'ember'
],
extends: [
'eslint:recommended',
'plugin:ember/recommended'
],
env: {
browser: true
},
rules: {
},
overrides: [
// node files
{
files: [
'ember-cli-build.js',
'index.js',
'testem.js',
'blueprints/*/index.js',
'config/**/*.js',
'tests/dummy/config/**/*.js'
],
excludedFiles: [
'addon/**',
'addon-test-support/**',
'app/**',
'tests/dummy/app/**'
],
parserOptions: {
sourceType: 'script',
ecmaVersion: 2015
},
env: {
browser: false,
node: true
},
plugins: ['node'],
rules: Object.assign({}, require('eslint-plugin-node').configs.recommended.rules, {
// add your custom rules and overrides for node files here
})
}
]
};
10 changes: 8 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# See http://help.github.com/ignore-files/ for more about ignoring files.
# See https://help.github.com/ignore-files/ for more about ignoring files.

# compiled output
/dist
Expand All @@ -13,5 +13,11 @@
/connect.lock
/coverage/*
/libpeerconnection.log
npm-debug.log
npm-debug.log*
yarn-error.log
testem.log

# ember-try
.node_modules.ember-try/
bower.json.ember-try
package.json.ember-try
32 changes: 0 additions & 32 deletions .jshintrc

This file was deleted.

11 changes: 9 additions & 2 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,17 @@ dist/
.bowerrc
.editorconfig
.ember-cli
.eslintrc.js
.gitignore
.watchmanconfig
.travis.yml
.npmignore
**/.gitkeep
bower.json
ember-cli-build.js
Brocfile.js
testem.json
testem.js

# ember-try
.node_modules.ember-try/
bower.json.ember-try
package.json.ember-try
54 changes: 37 additions & 17 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,29 +1,49 @@
language: node_js
node_js:
- '0.12'
# we recommend testing addons with the same minimum supported node version as Ember CLI
# so that your addon works for all apps
- "6"

sudo: false
dist: trusty

addons:
chrome: stable

branches:
only:
master

cache:
directories:
- node_modules
- $HOME/.npm

env:
- EMBER_TRY_SCENARIO=default
- EMBER_TRY_SCENARIO=ember-release
- EMBER_TRY_SCENARIO=ember-beta
- EMBER_TRY_SCENARIO=ember-canary
global:
# See https://git.io/vdao3 for details.
- JOBS=1
matrix:
# we recommend new addons test the current and previous LTS
# as well as latest stable release (bonus points to beta/canary)
- EMBER_TRY_SCENARIO=ember-lts-2.12
- EMBER_TRY_SCENARIO=ember-lts-2.16
- EMBER_TRY_SCENARIO=ember-lts-2.18
# - EMBER_TRY_SCENARIO=ember-release TODO: bug with ember-try
- EMBER_TRY_SCENARIO=ember-beta
- EMBER_TRY_SCENARIO=ember-canary
- EMBER_TRY_SCENARIO=ember-default

matrix:
fast_finish: true
allow_failures:
- env: EMBER_TRY_SCENARIO=ember-canary
before_install:
- export PATH=/usr/local/phantomjs-2.0.0/bin:$PATH
- npm config set spin false
- npm install -g npm@^2
install:
- npm install -g bower
- npm install
- bower install
- npm config set spin false
- npm install -g npm@4
- npm --version

script:
- ember try $EMBER_TRY_SCENARIO test
notifications:
slack:
secure: fRapTakBKLVJMxSYQ8vFcMkAqqHagFxqyF3DijxVSUH7IMsZ+ixK7FHRQ45FiQajX6PQwc3GQosP228zXlZpQvCQlEfhoGqKRk222MXKRyhiU5ZzwNQlzPzKrNMzrjLWp0NK7MZAINXcQXRWsAaOKhHSDXIYjUCopXzczVEUimUNi1DDnijRx/KXUuSqt1qABH8DHOlNJ1twHDolHE81hjtNsP3mBs7Veg+WCTkYSXCvh5sUguFkS2WJyN6DtJdhoery9TtntUXkERlyopuevd9675vKugqRpfxtLdtsRdD1G6bYvK+nr5x3fww+hmjMzzlWs4W4z9X8Usq0DDFrhvo0g4JLzkP4bfxslp9K/dN71RBau0mBlMZLhdjj8di1hWWsEYX7CPIC898hYpBXOLR23NPz+nkoRtyxarink6YhPS0KIfu9UgmTgG25OJzfu8zzlns0UcqlY+D/cF0jmm6EvINsJ/mtGj4ZweZ09uCz8hER6gZ8i9sOuc0XZ3/WJ/lkqjZCHs9l4ONfoIeJdaVjO6+bKci0RAY32Ek2I5XMNvXHNyrULYa7zFZt8k/20YOZ/t1jS+olB3TGfPWSeCTIAB4BdbZ5LWtwuWgQO6k2C78iUkdpRlnVoYxPWc3w1AaluqMNoxJszCZOT0moMfmoOkKpiwSP9JybQJTUU5Y=
- npm run lint:js
# Usually, it's ok to finish the test scenario without reverting
# to the addon's original dependency state, skipping "cleanup".
- node_modules/.bin/ember try:one $EMBER_TRY_SCENARIO --skip-cleanup
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2015
Copyright (c) 2018

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

Expand Down
4 changes: 0 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
# ember-body-class

Easily add CSS classes on the `<body>`, including route names as well as loading and error states.

## Installation

`ember install ember-body-class`

## Usage
Expand Down Expand Up @@ -62,4 +59,3 @@ Permission is hereby granted, free of charge, to any person obtaining a copy of
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

33 changes: 18 additions & 15 deletions addon/instance-initializers/body-class.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import Ember from 'ember';
import { on } from '@ember/object/evented';
import Route from '@ember/routing/route';

export function initialize(instance) {
if (!Ember.$) { // No jquery in fastboot
return;
}
import { addClass, removeClass } from '../util/bodyClass';

export function initialize(instance) {
var config;

if (instance.resolveRegistration) {
// Ember 2.1+
// http://emberjs.com/blog/2015/08/16/ember-2-1-beta-released.html#toc_registry-and-container-reform
Expand All @@ -20,9 +20,9 @@ export function initialize(instance) {
_includeRouteName = false;
}

Ember.Route.reopen({
Route.reopen({
classNames: [],
bodyClasses: [], // Backwards compatibility
bodyClasses: Object.freeze([]),

_getRouteDepthClasses() {
let routeParts = this.get('routeName').split('.');
Expand All @@ -38,32 +38,35 @@ export function initialize(instance) {
return routeDepthClasses;
},

addClasses: Ember.on('activate', function() {
const $body = Ember.$('body');
addClasses: on('activate', function() {
const document = instance.lookup('service:-document');
const body = document.body;
['bodyClasses', 'classNames'].forEach((classes) => {
this.get(classes).forEach(function(klass) {
$body.addClass(klass);
addClass(body, klass);
});
});

if (_includeRouteName) {
this._getRouteDepthClasses().forEach((depthClass)=> {
$body.addClass(depthClass);
addClass(body, depthClass);
});
}
}),

removeClasses: Ember.on('deactivate', function() {
const $body = Ember.$('body');
removeClasses: on('deactivate', function() {
const document = instance.lookup('service:-document');
const body = document.body;

['bodyClasses', 'classNames'].forEach((classes) => {
this.get(classes).forEach(function(klass) {
$body.removeClass(klass);
removeClass(body, klass)
});
});

if (_includeRouteName) {
this._getRouteDepthClasses().forEach((depthClass)=> {
$body.removeClass(depthClass);
removeClass(body, depthClass)
});
}
}),
Expand Down
24 changes: 12 additions & 12 deletions addon/mixins/body-class.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
import Ember from 'ember';
import Mixin from '@ember/object/mixin';

export default Ember.Mixin.create({
import { addClass, removeClass } from '../util/bodyClass';

export default Mixin.create({
actions: {
loading(/* transition, route */) {
if (!Ember.$) { // No jquery in fastboot
return true;
}
const document = this.owner.lookup('service:-document');
const body = document.body;

Ember.$('body').addClass("loading");
addClass(body, 'loading');

this.router.on('didTransition', function() {
Ember.$('body').removeClass("loading");
removeClass(body, 'loading');
});

return true;
},

error: function(/* error, transition */) {
if (!Ember.$) { // No jquery in fastboot
return true;
}
const document = this.owner.lookup('service:-document');
const body = document.body;

Ember.$('body').addClass("error");
addClass(body, 'error');

this.router.on('didTransition', function() {
Ember.$('body').removeClass("error");
removeClass(body, 'error');
});

return true;
Expand Down
17 changes: 17 additions & 0 deletions addon/util/bodyClass.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
export function addClass(element, klass) {
if(typeof FastBoot === 'undefined') {
element.classList.add(klass);
} else {
let existingClass = element.getAttribute('class')
element.setAttribute('class', `${existingClass} ${klass}`);
}
}

export function removeClass(element, klass) {
if(typeof FastBoot === 'undefined') {
element.classList.remove(klass);
} else {
let existingClass = element.getAttribute('class')
element.setAttribute('class', existingClass.replace(klass, ''));
}
}
9 changes: 0 additions & 9 deletions bower.json

This file was deleted.

Loading

0 comments on commit 1df34bb

Please sign in to comment.