Skip to content

Commit

Permalink
Merge pull request #438 from Gaurav0/fastboot_test
Browse files Browse the repository at this point in the history
[WIP] Fastboot support
  • Loading branch information
Gaurav0 committed Jun 6, 2016
2 parents 9f2215b + 7d835bd commit c6bb54e
Show file tree
Hide file tree
Showing 12 changed files with 95 additions and 31 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
/dist
/tmp

#intermediate files
/vendor/polyfill.js

# dependencies
/node_modules
/bower_components
Expand Down
15 changes: 10 additions & 5 deletions app/adapters/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,26 @@ import DS from 'ember-data';
import Ember from 'ember';
import config from '../config/environment';

const { computed } = Ember;
const { computed, inject } = Ember;

export default DS.RESTAdapter.extend({
fastboot: inject.service(),

host: config.host,

headers: computed('session.token', function() {
let headers = {};

var token = this.get('session.token') || config.TMP_TORII_TOKEN;
if (token) {
return {
'Authorization': 'token ' + token
};
headers['Authorization'] = 'token ' + token;
}

if (this.get('fastboot.isFastBoot')) {
headers['user-agent'] = "fastboot";
}

return {};
return headers;
}),

shouldReloadAll() { return true; },
Expand Down
6 changes: 5 additions & 1 deletion app/components/main-gist.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,17 @@ export default Ember.Component.extend(AppBuilderMixin, ColumnsMixin, FilesMixin,
dependencyResolver: inject.service(),
notify: inject.service(),
store: inject.service(),
fastboot: inject.service(),

numColumns: 1,
fullScreen: false,
openFiles: "",

init(...args) {
this._super(...args);
this.set('settings', Settings.create({
isFastBoot: this.get('fastboot.isFastBoot')
}));
this.createColumns();
this.set('activeEditorCol', '1');
},
Expand Down Expand Up @@ -53,7 +57,7 @@ export default Ember.Component.extend(AppBuilderMixin, ColumnsMixin, FilesMixin,
*/
activeEditorCol: null,

settings: Settings.create(),
settings: null,

/**
* Errors during build
Expand Down
8 changes: 6 additions & 2 deletions app/gist/controller.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import Ember from "ember";

const { RSVP, run } = Ember;
const { inject, RSVP, run } = Ember;

export default Ember.Controller.extend({
fastboot: inject.service(),

queryParams: ['numColumns', 'fullScreen', 'route', 'openFiles', 'fileTreeShown'],
numColumns: 1,
fullScreen: false,
Expand All @@ -14,7 +16,9 @@ export default Ember.Controller.extend({

init(...args) {
this._super(...args);
this.setupWindowUpdate();
if (!this.get('fastboot.isFastBoot')) {
this.setupWindowUpdate();
}
},

actions: {
Expand Down
4 changes: 3 additions & 1 deletion app/gist/edit/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ export default GistRoute.extend({
if (error && error.errors && error.errors.length > 0) {
let error1 = error.errors[0];
if (error1.status === "404") {
alert('The gist is missing or secret.');
if (alert) {
alert('The gist is missing or secret.');
}
return this.transitionTo('gist.new');
}
}
Expand Down
12 changes: 10 additions & 2 deletions app/gist/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const CONFIRM_MSG = "Unsaved changes will be lost.";
export default Ember.Route.extend({
notify: inject.service('notify'),
app: inject.service(),
fastboot: inject.service(),

titleToken: Ember.computed.readOnly('controller.model.description'),

Expand All @@ -17,6 +18,9 @@ export default Ember.Route.extend({
},

activate() {
if (this.get('fastboot.isFastBoot')) {
return;
}
this.set('boundConfirmUnload', this.confirmUnload.bind(this));
$(window).on('beforeunload', this.get('boundConfirmUnload'));
},
Expand All @@ -26,7 +30,9 @@ export default Ember.Route.extend({
if (gist.get('isNew')) {
this.get('store').unloadRecord(gist);
}
$(window).off('beforeunload', this.get('boundConfirmUnload'));
if (!this.get('fastboot.isFastBoot')) {
$(window).off('beforeunload', this.get('boundConfirmUnload'));
}
},

confirmUnload(event) {
Expand Down Expand Up @@ -93,7 +99,9 @@ export default Ember.Route.extend({

signInViaGithub () {
this.session.open('github-oauth2').catch(function(error) {
alert('Could not sign you in: ' + error.message);
if (alert) {
alert('Could not sign you in: ' + error.message);
}
throw error;
});
},
Expand Down
8 changes: 3 additions & 5 deletions app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,12 @@
{{content-for 'head-footer'}}
</head>
<body>
{{content-for 'body'}}

<div class="ember-load-indicator">Loading...</div>

<div id="main-app">
{{content-for 'body'}}
</div>

<div class="ember-load-indicator">Loading...</div>

<script src="assets/vendor.js"></script>
<script src="assets/ember-twiddle.js"></script>

Expand All @@ -38,7 +37,6 @@

ga('create', 'UA-1862979-11', 'auto');
ga('send', 'pageview');

</script>
</body>
</html>
6 changes: 4 additions & 2 deletions app/models/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default ObjectProxy.extend({
init() {
const storageKey = get(this, 'storageKey');
const defaultSettings = get(this, 'defaultSettings');
const localSettings = JSON.parse(localStorage.getItem(storageKey)) || {};
const localSettings = get(this, 'isFastBoot') ? {} : JSON.parse(localStorage.getItem(storageKey)) || {};

set(this, 'content', _merge(defaultSettings, localSettings));

Expand All @@ -28,6 +28,8 @@ export default ObjectProxy.extend({
const storageKey = get(this, 'storageKey');
const newSettings = JSON.stringify(get(this, 'content'));

localStorage.setItem(storageKey, newSettings);
if (!get(this, 'isFastBoot')) {
localStorage.setItem(storageKey, newSettings);
}
}
});
7 changes: 5 additions & 2 deletions app/services/resizeable-columns.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import Ember from "ember";

const { $, run } = Ember;
const { $, inject, run } = Ember;

export default Ember.Service.extend({
fastboot: inject.service(),

init() {
this._super(...arguments);
this.setupMouseEventsFromIframe();
if (!this.get('fastboot.isFastBoot')) {
this.setupMouseEventsFromIframe();
}
},

setupMouseEventsFromIframe() {
Expand Down
23 changes: 18 additions & 5 deletions app/torii-adapters/application.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import config from '../config/environment';
import Ember from 'ember';

const { inject } = Ember;
const { inject, isBlank, RSVP } = Ember;

export default Ember.Object.extend({ /**
* Resolve the user over the Github API using the token
Expand All @@ -11,12 +11,15 @@ export default Ember.Object.extend({ /**

store: inject.service(),
ajax: inject.service(),
fastboot: inject.service(),

resolveUser (token) {
config.TMP_TORII_TOKEN = token;
return this.get('store').find('user', 'current').then((user) => {
config.TMP_TORII_TOKEN = null;
localStorage.setItem('fiddle_gh_session', token);
if (!this.get('fastboot.isFastBoot')) {
localStorage.setItem('fiddle_gh_session', token);
}
return { currentUser: user, token: token };
});
},
Expand All @@ -26,9 +29,15 @@ export default Ember.Object.extend({ /**
* @return Promise
*/
fetch () {
if (this.get('fastboot.isFastBoot')) {
return RSVP.reject();
}

var token = localStorage.getItem('fiddle_gh_session');

if(Ember.isBlank(token)) { return Ember.RSVP.reject(); }
if (isBlank(token)) {
return RSVP.reject();
}

return this.resolveUser(token);
},
Expand All @@ -47,7 +56,11 @@ export default Ember.Object.extend({ /**
* @return Promise
*/
close () {
localStorage.removeItem('fiddle_gh_session');
return Ember.RSVP.resolve();
if (this.get('fastboot.isFastBoot')) {
return Ember.RSVP.reject();
} else {
localStorage.removeItem('fiddle_gh_session');
return Ember.RSVP.resolve();
}
}
});
25 changes: 22 additions & 3 deletions ember-cli-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@ module.exports = function(defaults) {
var concat = require('broccoli-concat');
var mergeTrees = require('broccoli-merge-trees');
var babelTranspiler = require('broccoli-babel-transpiler');
var browserify = require('browserify');
var path = require('path');
var fs = require('fs');

var env = EmberApp.env();
var isProductionLikeBuild = ['production', 'staging'].indexOf(env) > -1;
var isFastboot = process.env.EMBER_CLI_FASTBOOT;
var prepend = null;

if(isProductionLikeBuild) {
Expand All @@ -34,7 +37,12 @@ module.exports = function(defaults) {
'ember-cli-bootstrap-sassy': {
'js': ['dropdown', 'collapse']
},
fileCreator: [{filename: '/lib/blueprints.js', content: blueprintsCode}],
fileCreator: [
{
filename: '/lib/blueprints.js',
content: blueprintsCode
}
],
sourcemaps: {
enabled: !isProductionLikeBuild
},
Expand All @@ -51,7 +59,7 @@ module.exports = function(defaults) {
}
},
babel: {
includePolyfill: true
includePolyfill: !isFastboot
},

tests: true,
Expand All @@ -64,11 +72,22 @@ module.exports = function(defaults) {
}
});

if (isFastboot) {
var b = browserify();
b.add(require.resolve('babel/polyfill'));
b.bundle(function(err, buf) {
fs.writeFileSync('vendor/polyfill.js', buf);
});
app.import('vendor/polyfill.js', { prepend: true });
}

app.import('bower_components/ember/ember-template-compiler.js');

if (!isFastboot) {
app.import('vendor/drags.js');
}
app.import('vendor/bootstrap-dropdown-submenu-fix.css');
app.import('vendor/hint.css');
app.import('vendor/drags.js');

var loaderTree = funnel(path.dirname(require.resolve('loader.js')), {
files: ['loader.js'],
Expand Down
9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@
"author": "",
"license": "MIT",
"devDependencies": {
"babel": "^5.8.38",
"broccoli-asset-rev": "^2.4.2",
"broccoli-babel-transpiler": "~5.5.0",
"broccoli-concat": "2.2.0",
"broccoli-funnel": "^1.0.1",
"broccoli-merge-trees": "^1.1.1",
"browserify": "^13.0.1",
"dc-tabs": "0.1.0",
"dedent": "~0.6.0",
"ember-ajax": "~2.4.1",
Expand All @@ -33,20 +35,21 @@
"ember-cli": "2.6.0-beta.3",
"ember-cli-app-version": "1.0.0",
"ember-cli-babel": "^5.1.6",
"ember-cli-bootstrap-sassy": "0.5.3",
"ember-cli-bootstrap-sassy": "lifegadget/ember-cli-bootstrap-sassy#fa01943776a219905ee4a12bb9cd3981bba5c75a",
"ember-cli-build-notifications": "0.2.0",
"ember-cli-code-coverage": "~0.1.1",
"ember-cli-dependency-checker": "1.2.0",
"ember-cli-deploy": "~0.6.0",
"ember-cli-deploy-s3-pack": "~0.1.5",
"ember-cli-deploy-slack": "0.1.0",
"ember-cli-document-title": "0.3.1",
"ember-cli-fastboot": "1.0.0-beta.2",
"ember-cli-file-creator": "^0.2.0",
"ember-cli-htmlbars": "~1.0.3",
"ember-cli-htmlbars-inline-precompile": "^0.3.1",
"ember-cli-inject-live-reload": "^1.4.0",
"ember-cli-jshint": "~1.0.0",
"ember-cli-jstree": "1.0.2",
"ember-cli-jstree": "ritesh83/ember-cli-jstree#cda17d9e88911c5bbd245a498ba633571305347f",
"ember-cli-legacy-blueprints": "^0.1.0",
"ember-cli-mirage": "0.2.0",
"ember-cli-moment-shim": "~1.3.0",
Expand All @@ -61,7 +64,7 @@
"ember-notify": "~5.0.3",
"ember-responsive": "freshbooks/ember-responsive#0a92414cff75b23158742ef417fee6d755707b45",
"ember-route-action-helper": "0.3.1",
"ivy-codemirror": "1.4.0",
"ivy-codemirror": "2.0.2",
"moment": "~2.13.0",
"moment-timezone": "~0.5.4",
"torii": "0.8.0"
Expand Down

0 comments on commit c6bb54e

Please sign in to comment.