Skip to content

Commit

Permalink
Merge pull request #501 from Gaurav0/glimmer2
Browse files Browse the repository at this point in the history
Upgrade to Glimmer 2
  • Loading branch information
Gaurav0 authored Jan 10, 2017
2 parents a00e9af + d0ec148 commit 01e3206
Show file tree
Hide file tree
Showing 16 changed files with 204 additions and 86 deletions.
4 changes: 2 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 @@ -16,5 +16,5 @@
/connect.lock
/coverage/*
/libpeerconnection.log
npm-debug.log
npm-debug.log*
testem.log
26 changes: 23 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,25 +1,45 @@
language: node_js
node_js:
- '4'
- '6'
notifications:
email: false
sudo: false
dist: trusty
sudo: required

addons:
apt:
sources:
- google-chrome
packages:
- google-chrome-stable

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

before_install:
- npm config set spin false
- npm install -g bower
- bower --version
- npm install phantomjs-prebuilt
- phantomjs --version

install:
- npm install
- bower install

before_script:
- export DISPLAY=:99.0
- sh -e /etc/init.d/xvfb start
- sleep 3 # give xvfb some time to start

script:
- npm test

after_script:
- scripts/travis-deploy.sh

env:
global:
- secure: Dwthqo6GaXQt7erj89xMa/2GRua9PTzcSKXYmxjE0O46DMuBR80JjPges0hGCWwPcdMFqsaMshSaTVF5eHc49vhaziB2sqWwLZndkRFIAsNGnBZkBpeZc9MsTNMbPP5KyJh/pG03nJLXUSz6xzMoxDNU/QHWyBYBxTlfxVGewLE=
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# [ember-twiddle](http://ember-twiddle.com)
# [ember-twiddle](https://ember-twiddle.com)

[![Build Status][travis-badge]][travis-badge-url] [![Code Climate](https://codeclimate.com/github/ember-cli/ember-twiddle/badges/gpa.svg)](https://codeclimate.com/github/ember-cli/ember-twiddle)

Expand Down
4 changes: 4 additions & 0 deletions app/controllers/edit/revision.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import Ember from "ember";
import GistController from "../mixins/gist-controller";

export default Ember.Controller.extend(GistController, {});
53 changes: 2 additions & 51 deletions app/controllers/gist.js
Original file line number Diff line number Diff line change
@@ -1,53 +1,4 @@
import Ember from "ember";
import GistController from "../mixins/gist-controller";

const { inject, RSVP, run } = Ember;

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

queryParams: ['numColumns', 'fullScreen', 'route', 'openFiles', 'fileTreeShown'],
numColumns: 1,
fullScreen: false,
openFiles: "",
fileTreeShown: true,
route: undefined,
applicationUrl: undefined,
unsaved: true,

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

actions: {
transitionQueryParams(queryParams) {
return this.transitionToRoute({ queryParams: queryParams }).then(() => {
return RSVP.resolve(queryParams);
});
}
},

setupWindowUpdate: function() {
// TODO: this in a controller seems suspect, rather this should likely be
// part of some handshake, to ensure no races exist. This should likley not
// be something a controller would handle - (SP)
window.addEventListener('message', (m) => {
run(() => {
if(typeof m.data==='object' && 'setAppUrl' in m.data) {
if (!this.get('isDestroyed')) {
if (window.messagesWaiting > 0) {
window.messagesWaiting = 0;
}
const newRoute = m.data.setAppUrl || '/';
this.setProperties({
applicationUrl: newRoute,
route: newRoute === "/" ? undefined : newRoute
});
}
}
});
});
}
});
export default Ember.Controller.extend(GistController, {});
53 changes: 53 additions & 0 deletions app/mixins/gist-controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import Ember from "ember";

const { inject, RSVP, run } = Ember;

export default Ember.Mixin.create({
fastboot: inject.service(),

queryParams: ['numColumns', 'fullScreen', 'route', 'openFiles', 'fileTreeShown'],
numColumns: 1,
fullScreen: false,
openFiles: "",
fileTreeShown: true,
route: undefined,
applicationUrl: undefined,
unsaved: true,

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

actions: {
transitionQueryParams(queryParams) {
return this.transitionToRoute({ queryParams: queryParams }).then(() => {
return RSVP.resolve(queryParams);
});
}
},

setupWindowUpdate: function() {
// TODO: this in a controller seems suspect, rather this should likely be
// part of some handshake, to ensure no races exist. This should likley not
// be something a controller would handle - (SP)
window.addEventListener('message', (m) => {
run(() => {
if(typeof m.data==='object' && 'setAppUrl' in m.data) {
if (!this.get('isDestroyed')) {
if (window.messagesWaiting > 0) {
window.messagesWaiting = 0;
}
const newRoute = m.data.setAppUrl || '/';
this.setProperties({
applicationUrl: newRoute,
route: newRoute === "/" ? undefined : newRoute
});
}
}
});
});
}
});
7 changes: 4 additions & 3 deletions app/models/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ import _merge from 'lodash/object/merge';

const {
ObjectProxy,
get,
set
get
} = Ember;

export default ObjectProxy.extend({
Expand All @@ -18,8 +17,10 @@ export default ObjectProxy.extend({
const storageKey = get(this, 'storageKey');
const defaultSettings = get(this, 'defaultSettings');
const localSettings = get(this, 'isFastBoot') ? {} : JSON.parse(localStorage.getItem(storageKey)) || {};
const newSettings = _merge(defaultSettings, localSettings);

set(this, 'content', _merge(defaultSettings, localSettings));
this.content = Ember.Object.create(newSettings);
this.content.setProperties(this.content);

this._super(...arguments);
},
Expand Down
86 changes: 86 additions & 0 deletions app/plugins/hbs-plugin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
export default function(babel, _options) {
var options = _options || {};

function htmlbarsInlineCompilerPlugin(babel) {
var t = babel.types;

var replaceNodeWithPrecompiledTemplate = function(node, template) {
var compiledTemplateString = "Ember.HTMLBars.compile(`" + template + "`)";

// Prefer calling replaceWithSourceString if it is present.
// this prevents a deprecation warning in Babel 5.6.7+.
//
// TODO: delete the fallback once we only support babel >= 5.6.7.
if (node.replaceWithSourceString) {
node.replaceWithSourceString(compiledTemplateString);
} else {
return compiledTemplateString;
}
};


return new babel.Transformer('htmlbars-inline-precompile', {
ImportDeclaration: function(node, parent, scope, file) {
if (t.isLiteral(node.source, { value: "htmlbars-inline-precompile" })) {
var first = node.specifiers && node.specifiers[0];
if (t.isImportDefaultSpecifier(first)) {
file.importSpecifier = first.local.name;
} else {
var input = file.code;
var usedImportStatement = input.slice(node.start, node.end);
var msg = "Only `import hbs from 'htmlbars-inline-precompile'` is supported. You used: `" + usedImportStatement + "`";
throw file.errorWithNode(node, msg);
}

// Prefer calling dangerouslyRemove instead of remove (if present) to
// suppress a deprecation warning.
//
// TODO: delete the fallback once we only support babel >= 5.5.0.
if (typeof this.dangerouslyRemove === 'function') {
this.dangerouslyRemove();
} else {
this.remove();
}
}
},

CallExpression: function(node, parent, scope, file) {
if (t.isIdentifier(node.callee, { name: file.importSpecifier })) {
var argumentErrorMsg = "hbs should be invoked with a single argument: the template string";
if (node.arguments.length !== 1) {
throw file.errorWithNode(node, argumentErrorMsg);
}

var template = node.arguments[0].value;
if (typeof template !== "string") {
throw file.errorWithNode(node, argumentErrorMsg);
}

return replaceNodeWithPrecompiledTemplate(this, template);
}
},

TaggedTemplateExpression: function(node, parent, scope, file) {
if (t.isIdentifier(node.tag, { name: file.importSpecifier })) {
if (node.quasi.expressions.length) {
throw file.errorWithNode(node, "placeholders inside a tagged template string are not supported");
}

var template = node.quasi.quasis.map(function(quasi) {
return quasi.value.cooked;
}).join("");

return replaceNodeWithPrecompiledTemplate(this, template);
}
}
});
}

// used by broccoli-babel-transpiler to bust the cache when
// the template compiler being used changes
htmlbarsInlineCompilerPlugin.cacheKey = function() {
return options.cacheKey;
};

return htmlbarsInlineCompilerPlugin;
}
1 change: 0 additions & 1 deletion app/routes/gist/edit/revision.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import GistEditRoute from "../edit";

export default GistEditRoute.extend({

controllerName: 'gist',
templateName: 'gist',

model(params) {
Expand Down
5 changes: 2 additions & 3 deletions app/services/ember-cli.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
import Babel from "npm:babel-core";
import Path from 'npm:path';
import HtmlbarsInlinePrecompile from 'npm:babel-plugin-htmlbars-inline-precompile';
import HbsPlugin from '../plugins/hbs-plugin';
import blueprints from '../lib/blueprints';
import config from '../config/environment';
import Ember from 'ember';
import moment from 'moment';
import _template from "lodash/string/template";

const hbsPlugin = new HtmlbarsInlinePrecompile(Ember.HTMLBars.precompile);

const { computed, inject, RSVP, $ } = Ember;
const twiddleAppName = 'twiddle';
const oldTwiddleAppNames = ['demo-app', 'app'];
const hbsPlugin = new HbsPlugin(Babel);

// These files will be included if not present
const boilerPlateJs = [
Expand Down
2 changes: 1 addition & 1 deletion blueprints/twiddle.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "0.10.7",
"version": "0.11.0",
"EmberENV": {
"FEATURES": {}
},
Expand Down
4 changes: 2 additions & 2 deletions bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "ember-twiddle",
"version": "0.10.7",
"dependencies": {
"ember": "2.8.0",
"ember": "~2.10.2",
"ember-cli-shims": "0.1.3",
"jquery": "1.11.3",
"codemirror": "~5.19.0",
Expand All @@ -16,7 +16,7 @@
},
"resolutions": {
"codemirror": "~5.19.0",
"ember": "2.8.0",
"ember": "~2.10.2",
"FakeXMLHttpRequest": "^1.3.0",
"route-recognizer": "^0.2.3"
}
Expand Down
4 changes: 4 additions & 0 deletions config/environment.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ module.exports = function(environment) {
FEATURES: {
// Here you can enable experimental features on an ember canary build
// e.g. 'with-controller': true
},
EXTEND_PROTOTYPES: {
// Prevent Ember Data from overriding Date.parse
Date: false
}
},

Expand Down
Loading

0 comments on commit 01e3206

Please sign in to comment.