mirror of
https://github.com/discourse/discourse.git
synced 2025-03-20 05:05:36 +08:00
Add support for more ES6 features
This commit is contained in:
parent
853e6d6cb7
commit
a65e0a80ba
1
Gemfile
1
Gemfile
@ -107,6 +107,7 @@ gem 'ember-rails'
|
|||||||
gem 'ember-source', '1.9.0.beta.4'
|
gem 'ember-source', '1.9.0.beta.4'
|
||||||
gem 'handlebars-source', '2.0.0'
|
gem 'handlebars-source', '2.0.0'
|
||||||
gem 'barber'
|
gem 'barber'
|
||||||
|
gem '6to5'
|
||||||
|
|
||||||
gem 'message_bus'
|
gem 'message_bus'
|
||||||
gem 'rails_multisite', path: 'vendor/gems/rails_multisite'
|
gem 'rails_multisite', path: 'vendor/gems/rails_multisite'
|
||||||
|
@ -6,6 +6,10 @@ PATH
|
|||||||
GEM
|
GEM
|
||||||
remote: https://rubygems.org/
|
remote: https://rubygems.org/
|
||||||
specs:
|
specs:
|
||||||
|
6to5 (0.5.0)
|
||||||
|
6to5-source (>= 1.14, < 4)
|
||||||
|
execjs (~> 2.0)
|
||||||
|
6to5-source (3.3.7)
|
||||||
CFPropertyList (2.2.8)
|
CFPropertyList (2.2.8)
|
||||||
actionmailer (4.1.8)
|
actionmailer (4.1.8)
|
||||||
actionpack (= 4.1.8)
|
actionpack (= 4.1.8)
|
||||||
@ -456,6 +460,7 @@ PLATFORMS
|
|||||||
ruby
|
ruby
|
||||||
|
|
||||||
DEPENDENCIES
|
DEPENDENCIES
|
||||||
|
6to5
|
||||||
actionpack-action_caching
|
actionpack-action_caching
|
||||||
active_model_serializers (~> 0.8.0)
|
active_model_serializers (~> 0.8.0)
|
||||||
annotate
|
annotate
|
||||||
|
@ -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({
|
export default Ember.Component.extend({
|
||||||
layoutName: 'components/toggle-summary',
|
layoutName: 'components/toggle-summary',
|
||||||
tagName: 'section',
|
tagName: 'section',
|
||||||
@ -13,7 +5,7 @@ export default Ember.Component.extend({
|
|||||||
postStream: Em.computed.alias('topic.postStream'),
|
postStream: Em.computed.alias('topic.postStream'),
|
||||||
|
|
||||||
actions: {
|
actions: {
|
||||||
toggleSummary: function() {
|
toggleSummary() {
|
||||||
this.get('postStream').toggleSummary();
|
this.get('postStream').toggleSummary();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import registerUnbound from 'discourse/helpers/register-unbound';
|
import registerUnbound from 'discourse/helpers/register-unbound';
|
||||||
|
|
||||||
export function daysSinceEpoch(dt) {
|
function daysSinceEpoch(dt) {
|
||||||
// 1000 * 60 * 60 * 24 = days since epoch
|
// 1000 * 60 * 60 * 24 = days since epoch
|
||||||
return dt.getTime() / 86400000;
|
return dt.getTime() / 86400000;
|
||||||
}
|
}
|
||||||
@ -22,3 +22,5 @@ registerUnbound('cold-age-class', function(dt, params) {
|
|||||||
|
|
||||||
return className;
|
return className;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
export { daysSinceEpoch };
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
import registerUnbound from 'discourse/helpers/register-unbound';
|
import registerUnbound from 'discourse/helpers/register-unbound';
|
||||||
|
|
||||||
export function iconClasses(icon, modifier) {
|
function iconClasses(icon, modifier) {
|
||||||
var classes = "fa fa-" + icon;
|
var classes = "fa fa-" + icon;
|
||||||
if (modifier) { classes += " fa-" + modifier; }
|
if (modifier) { classes += " fa-" + modifier; }
|
||||||
return classes;
|
return classes;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function iconHTML(icon, label, modifier) {
|
function iconHTML(icon, label, modifier) {
|
||||||
var html = "<i class='" + iconClasses(icon, modifier) + "'";
|
var html = "<i class='" + iconClasses(icon, modifier) + "'";
|
||||||
if (label) { html += " aria-hidden='true'"; }
|
if (label) { html += " aria-hidden='true'"; }
|
||||||
html += "></i>";
|
html += "></i>";
|
||||||
@ -20,3 +20,5 @@ export function iconHTML(icon, label, modifier) {
|
|||||||
registerUnbound('fa-icon', function(icon, params) {
|
registerUnbound('fa-icon', function(icon, params) {
|
||||||
return new Handlebars.SafeString(iconHTML(icon, params.label, params.modifier));
|
return new Handlebars.SafeString(iconHTML(icon, params.label, params.modifier));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
export { iconClasses, iconHTML };
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import registerUnbound from 'discourse/helpers/register-unbound';
|
import registerUnbound from 'discourse/helpers/register-unbound';
|
||||||
|
|
||||||
export function renderRaw(template, templateName, params) {
|
function renderRaw(template, templateName, params) {
|
||||||
params.parent = params.parent || this;
|
params.parent = params.parent || this;
|
||||||
|
|
||||||
if (!params.view) {
|
if (!params.view) {
|
||||||
@ -22,3 +22,5 @@ registerUnbound('raw', function(templateName, params) {
|
|||||||
|
|
||||||
return renderRaw.call(this, template, templateName, params);
|
return renderRaw.call(this, template, templateName, params);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
export { renderRaw };
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import registerUnbound from 'discourse/helpers/register-unbound';
|
import registerUnbound from 'discourse/helpers/register-unbound';
|
||||||
|
|
||||||
export function renderAvatar(user, options) {
|
function renderAvatar(user, options) {
|
||||||
options = options || {};
|
options = options || {};
|
||||||
|
|
||||||
if (user) {
|
if (user) {
|
||||||
@ -44,3 +44,5 @@ export function renderAvatar(user, options) {
|
|||||||
registerUnbound('avatar', function(user, params) {
|
registerUnbound('avatar', function(user, params) {
|
||||||
return new Handlebars.SafeString(renderAvatar.call(this, user, params));
|
return new Handlebars.SafeString(renderAvatar.call(this, user, params));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
export { renderAvatar };
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { queryParams } from 'discourse/controllers/discovery-sortable';
|
import { queryParams } from 'discourse/controllers/discovery-sortable';
|
||||||
|
|
||||||
// A helper to build a topic route for a filter
|
// A helper to build a topic route for a filter
|
||||||
export function filterQueryParams(params, defaultParams) {
|
function filterQueryParams(params, defaultParams) {
|
||||||
var findOpts = defaultParams || {};
|
var findOpts = defaultParams || {};
|
||||||
if (params) {
|
if (params) {
|
||||||
Ember.keys(queryParams).forEach(function(opt) {
|
Ember.keys(queryParams).forEach(function(opt) {
|
||||||
@ -74,3 +74,4 @@ export default function(filter, extras) {
|
|||||||
}, extras);
|
}, extras);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export { filterQueryParams };
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
require 'execjs'
|
require 'execjs'
|
||||||
|
require '6to5'
|
||||||
|
|
||||||
module Tilt
|
module Tilt
|
||||||
class ES6ModuleTranspilerTemplate < Tilt::Template
|
class ES6ModuleTranspilerTemplate < Tilt::Template
|
||||||
@ -14,6 +15,7 @@ module Tilt
|
|||||||
|
|
||||||
def self.create_new_context
|
def self.create_new_context
|
||||||
ctx = V8::Context.new(timeout: 5000)
|
ctx = V8::Context.new(timeout: 5000)
|
||||||
|
ctx.eval("var self = this; #{File.read(ES6to5::Source.path)}")
|
||||||
ctx.eval("module = {}; exports = {};");
|
ctx.eval("module = {}; exports = {};");
|
||||||
ctx.load("#{Rails.root}/lib/es6_module_transpiler/support/es6-module-transpiler.js")
|
ctx.load("#{Rails.root}/lib/es6_module_transpiler/support/es6-module-transpiler.js")
|
||||||
ctx
|
ctx
|
||||||
@ -107,7 +109,9 @@ module Tilt
|
|||||||
private
|
private
|
||||||
|
|
||||||
def generate_source(scope)
|
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
|
end
|
||||||
|
|
||||||
def module_name(root_path, logical_path)
|
def module_name(root_path, logical_path)
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
import siteFixtures from 'fixtures/site_fixtures';
|
import siteFixtures from 'fixtures/site_fixtures';
|
||||||
|
|
||||||
export function integration(name, options) {
|
function integration(name, options) {
|
||||||
module("Integration: " + name, {
|
module("Integration: " + name, {
|
||||||
setup: function() {
|
setup: function() {
|
||||||
Ember.run(Discourse, Discourse.advanceReadiness);
|
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);
|
controller = Discourse.__container__.lookup('controller:' + controller);
|
||||||
if (model) { controller.set('model', model ); }
|
if (model) { controller.set('model', model ); }
|
||||||
return controller;
|
return controller;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function asyncTestDiscourse(text, func) {
|
function asyncTestDiscourse(text, func) {
|
||||||
asyncTest(text, function () {
|
asyncTest(text, function () {
|
||||||
var self = this;
|
var self = this;
|
||||||
Ember.run(function () {
|
Ember.run(function () {
|
||||||
@ -54,9 +54,11 @@ export function asyncTestDiscourse(text, func) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export function fixture(selector) {
|
function fixture(selector) {
|
||||||
if (selector) {
|
if (selector) {
|
||||||
return $("#qunit-fixture").find(selector);
|
return $("#qunit-fixture").find(selector);
|
||||||
}
|
}
|
||||||
return $("#qunit-fixture");
|
return $("#qunit-fixture");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export { integration, controllerFor, asyncTestDiscourse, fixture };
|
||||||
|
Loading…
x
Reference in New Issue
Block a user