Add support for more ES6 features

This commit is contained in:
Robin Ward 2015-02-06 13:25:48 -05:00
parent 853e6d6cb7
commit a65e0a80ba
10 changed files with 33 additions and 20 deletions

View File

@ -107,6 +107,7 @@ gem 'ember-rails'
gem 'ember-source', '1.9.0.beta.4'
gem 'handlebars-source', '2.0.0'
gem 'barber'
gem '6to5'
gem 'message_bus'
gem 'rails_multisite', path: 'vendor/gems/rails_multisite'

View File

@ -6,6 +6,10 @@ PATH
GEM
remote: https://rubygems.org/
specs:
6to5 (0.5.0)
6to5-source (>= 1.14, < 4)
execjs (~> 2.0)
6to5-source (3.3.7)
CFPropertyList (2.2.8)
actionmailer (4.1.8)
actionpack (= 4.1.8)
@ -456,6 +460,7 @@ PLATFORMS
ruby
DEPENDENCIES
6to5
actionpack-action_caching
active_model_serializers (~> 0.8.0)
annotate

View File

@ -1,11 +1,3 @@
/**
The controls for toggling the summarized view on/off
@class ToggleSummaryComponent
@extends Ember.Component
@namespace Discourse
@module Discourse
**/
export default Ember.Component.extend({
layoutName: 'components/toggle-summary',
tagName: 'section',
@ -13,7 +5,7 @@ export default Ember.Component.extend({
postStream: Em.computed.alias('topic.postStream'),
actions: {
toggleSummary: function() {
toggleSummary() {
this.get('postStream').toggleSummary();
}
}

View File

@ -1,6 +1,6 @@
import registerUnbound from 'discourse/helpers/register-unbound';
export function daysSinceEpoch(dt) {
function daysSinceEpoch(dt) {
// 1000 * 60 * 60 * 24 = days since epoch
return dt.getTime() / 86400000;
}
@ -22,3 +22,5 @@ registerUnbound('cold-age-class', function(dt, params) {
return className;
});
export { daysSinceEpoch };

View File

@ -1,12 +1,12 @@
import registerUnbound from 'discourse/helpers/register-unbound';
export function iconClasses(icon, modifier) {
function iconClasses(icon, modifier) {
var classes = "fa fa-" + icon;
if (modifier) { classes += " fa-" + modifier; }
return classes;
}
export function iconHTML(icon, label, modifier) {
function iconHTML(icon, label, modifier) {
var html = "<i class='" + iconClasses(icon, modifier) + "'";
if (label) { html += " aria-hidden='true'"; }
html += "></i>";
@ -20,3 +20,5 @@ export function iconHTML(icon, label, modifier) {
registerUnbound('fa-icon', function(icon, params) {
return new Handlebars.SafeString(iconHTML(icon, params.label, params.modifier));
});
export { iconClasses, iconHTML };

View File

@ -1,6 +1,6 @@
import registerUnbound from 'discourse/helpers/register-unbound';
export function renderRaw(template, templateName, params) {
function renderRaw(template, templateName, params) {
params.parent = params.parent || this;
if (!params.view) {
@ -22,3 +22,5 @@ registerUnbound('raw', function(templateName, params) {
return renderRaw.call(this, template, templateName, params);
});
export { renderRaw };

View File

@ -1,6 +1,6 @@
import registerUnbound from 'discourse/helpers/register-unbound';
export function renderAvatar(user, options) {
function renderAvatar(user, options) {
options = options || {};
if (user) {
@ -44,3 +44,5 @@ export function renderAvatar(user, options) {
registerUnbound('avatar', function(user, params) {
return new Handlebars.SafeString(renderAvatar.call(this, user, params));
});
export { renderAvatar };

View File

@ -1,7 +1,7 @@
import { queryParams } from 'discourse/controllers/discovery-sortable';
// A helper to build a topic route for a filter
export function filterQueryParams(params, defaultParams) {
function filterQueryParams(params, defaultParams) {
var findOpts = defaultParams || {};
if (params) {
Ember.keys(queryParams).forEach(function(opt) {
@ -74,3 +74,4 @@ export default function(filter, extras) {
}, extras);
}
export { filterQueryParams };

View File

@ -1,4 +1,5 @@
require 'execjs'
require '6to5'
module Tilt
class ES6ModuleTranspilerTemplate < Tilt::Template
@ -14,6 +15,7 @@ module Tilt
def self.create_new_context
ctx = V8::Context.new(timeout: 5000)
ctx.eval("var self = this; #{File.read(ES6to5::Source.path)}")
ctx.eval("module = {}; exports = {};");
ctx.load("#{Rails.root}/lib/es6_module_transpiler/support/es6-module-transpiler.js")
ctx
@ -107,7 +109,9 @@ module Tilt
private
def generate_source(scope)
"new module.exports.Compiler(#{::JSON.generate(data, quirks_mode: true)}, '#{module_name(scope.root_path, scope.logical_path)}', #{compiler_options}).#{compiler_method}()"
js_source = ::JSON.generate(data, quirks_mode: true)
js_source = "to5.transform(#{js_source}, {ast: false, blacklist: ['es6.modules', 'useStrict']})['code']"
"new module.exports.Compiler(#{js_source}, '#{module_name(scope.root_path, scope.logical_path)}', #{compiler_options}).#{compiler_method}()"
end
def module_name(root_path, logical_path)

View File

@ -2,7 +2,7 @@
import siteFixtures from 'fixtures/site_fixtures';
export function integration(name, options) {
function integration(name, options) {
module("Integration: " + name, {
setup: function() {
Ember.run(Discourse, Discourse.advanceReadiness);
@ -39,13 +39,13 @@ export function integration(name, options) {
});
}
export function controllerFor(controller, model) {
function controllerFor(controller, model) {
controller = Discourse.__container__.lookup('controller:' + controller);
if (model) { controller.set('model', model ); }
return controller;
}
export function asyncTestDiscourse(text, func) {
function asyncTestDiscourse(text, func) {
asyncTest(text, function () {
var self = this;
Ember.run(function () {
@ -54,9 +54,11 @@ export function asyncTestDiscourse(text, func) {
});
}
export function fixture(selector) {
function fixture(selector) {
if (selector) {
return $("#qunit-fixture").find(selector);
}
return $("#qunit-fixture");
}
export { integration, controllerFor, asyncTestDiscourse, fixture };