mirror of
https://github.com/discourse/discourse.git
synced 2024-11-22 08:57:10 -06:00
Enable newer version of Ember
This commit is contained in:
parent
712ff01f38
commit
2d3518f475
2
Gemfile
2
Gemfile
@ -48,7 +48,7 @@ gem 'onebox'
|
|||||||
gem 'http_accept_language', '~>2.0.5', require: false
|
gem 'http_accept_language', '~>2.0.5', require: false
|
||||||
|
|
||||||
gem 'ember-rails', '0.18.5'
|
gem 'ember-rails', '0.18.5'
|
||||||
gem 'ember-source', '1.12.2'
|
gem 'ember-source', '2.4.6'
|
||||||
gem 'barber'
|
gem 'barber'
|
||||||
gem 'babel-transpiler'
|
gem 'babel-transpiler'
|
||||||
|
|
||||||
|
14
Gemfile.lock
14
Gemfile.lock
@ -81,9 +81,9 @@ GEM
|
|||||||
domain_name (0.5.25)
|
domain_name (0.5.25)
|
||||||
unf (>= 0.0.5, < 1.0.0)
|
unf (>= 0.0.5, < 1.0.0)
|
||||||
email_reply_trimmer (0.1.6)
|
email_reply_trimmer (0.1.6)
|
||||||
ember-data-source (1.0.0.beta.16.1)
|
ember-data-source (2.2.1)
|
||||||
ember-source (~> 1.8)
|
ember-source (>= 1.8, < 3.0)
|
||||||
ember-handlebars-template (0.7.3)
|
ember-handlebars-template (0.7.4)
|
||||||
barber (>= 0.11.0)
|
barber (>= 0.11.0)
|
||||||
sprockets (>= 3.3, < 4)
|
sprockets (>= 3.3, < 4)
|
||||||
ember-rails (0.18.5)
|
ember-rails (0.18.5)
|
||||||
@ -93,7 +93,7 @@ GEM
|
|||||||
ember-source (>= 1.1.0)
|
ember-source (>= 1.1.0)
|
||||||
jquery-rails (>= 1.0.17)
|
jquery-rails (>= 1.0.17)
|
||||||
railties (>= 3.1)
|
railties (>= 3.1)
|
||||||
ember-source (1.12.2)
|
ember-source (2.4.6)
|
||||||
erubis (2.7.0)
|
erubis (2.7.0)
|
||||||
eventmachine (1.2.0.1)
|
eventmachine (1.2.0.1)
|
||||||
excon (0.53.0)
|
excon (0.53.0)
|
||||||
@ -137,8 +137,8 @@ GEM
|
|||||||
image_size (1.4.1)
|
image_size (1.4.1)
|
||||||
in_threads (1.3.1)
|
in_threads (1.3.1)
|
||||||
jmespath (1.3.1)
|
jmespath (1.3.1)
|
||||||
jquery-rails (4.0.5)
|
jquery-rails (4.2.1)
|
||||||
rails-dom-testing (~> 1.0)
|
rails-dom-testing (>= 1, < 3)
|
||||||
railties (>= 4.2.0)
|
railties (>= 4.2.0)
|
||||||
thor (>= 0.14, < 2.0)
|
thor (>= 0.14, < 2.0)
|
||||||
json (1.8.3)
|
json (1.8.3)
|
||||||
@ -413,7 +413,7 @@ DEPENDENCIES
|
|||||||
discourse_fastimage (= 2.0.3)
|
discourse_fastimage (= 2.0.3)
|
||||||
email_reply_trimmer (= 0.1.6)
|
email_reply_trimmer (= 0.1.6)
|
||||||
ember-rails (= 0.18.5)
|
ember-rails (= 0.18.5)
|
||||||
ember-source (= 1.12.2)
|
ember-source (= 2.4.6)
|
||||||
excon
|
excon
|
||||||
execjs
|
execjs
|
||||||
fabrication (= 2.9.8)
|
fabrication (= 2.9.8)
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import { registerHelper } from 'discourse-common/lib/helpers';
|
const { registerKeyword } = Ember.__loader.require("ember-htmlbars/keywords");
|
||||||
|
const { internal } = Ember.__loader.require('htmlbars-runtime');
|
||||||
import PreloadStore from 'preload-store';
|
import PreloadStore from 'preload-store';
|
||||||
|
|
||||||
let _customizations = {};
|
let _customizations = {};
|
||||||
@ -24,15 +25,35 @@ export function setCustomHTML(key, html) {
|
|||||||
_customizations[key] = html;
|
_customizations[key] = html;
|
||||||
}
|
}
|
||||||
|
|
||||||
registerHelper('custom-html', function([id, contextString], hash, options, env) {
|
registerKeyword('custom-html', {
|
||||||
const html = getCustomHTML(id);
|
setupState(state, env, scope, params) {
|
||||||
if (html) { return html; }
|
return { htmlKey: env.hooks.getValue(params[0]) };
|
||||||
|
},
|
||||||
|
|
||||||
if (env) {
|
render(renderNode, env, scope, params, hash, template, inverse, visitor) {
|
||||||
const target = (env || contextString);
|
let state = renderNode.getState();
|
||||||
const container = target.container || target.data.view.container;
|
if (!state.htmlKey) { return true; }
|
||||||
if (container.lookup('template:' + id)) {
|
|
||||||
return env.helpers.partial.helperFunction.apply(this, arguments);
|
const html = getCustomHTML(state.htmlKey);
|
||||||
|
if (html) {
|
||||||
|
const htmlHash = { html };
|
||||||
|
env.hooks.component(renderNode,
|
||||||
|
env,
|
||||||
|
scope,
|
||||||
|
'custom-html-container',
|
||||||
|
params,
|
||||||
|
htmlHash,
|
||||||
|
{ default: template, inverse },
|
||||||
|
visitor);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template = env.owner.lookup(`template:${state.htmlKey}`);
|
||||||
|
if (template) {
|
||||||
|
internal.hostBlock(renderNode, env, scope, template.raw, null, null, visitor, function(options) {
|
||||||
|
options.templates.template.yield();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -23,24 +23,15 @@
|
|||||||
|
|
||||||
Will insert <b>Hello World</b> at that point in the template.
|
Will insert <b>Hello World</b> at that point in the template.
|
||||||
|
|
||||||
Optionally you can also define a view class for the outlet as:
|
|
||||||
|
|
||||||
plugins/hello/assets/javascripts/discourse/views/connectors/evil-trout/hello.js.es6
|
|
||||||
|
|
||||||
And it will be wired up automatically.
|
|
||||||
|
|
||||||
## Disabling
|
## Disabling
|
||||||
|
|
||||||
If a plugin returns a disabled status, the outlets will not be wired up for it.
|
If a plugin returns a disabled status, the outlets will not be wired up for it.
|
||||||
The list of disabled plugins is returned via the `Site` singleton.
|
The list of disabled plugins is returned via the `Site` singleton.
|
||||||
|
|
||||||
**/
|
**/
|
||||||
import { registerHelper } from 'discourse-common/lib/helpers';
|
let _connectorCache, _rawCache, _templateCache;
|
||||||
|
|
||||||
let _connectorCache, _rawCache;
|
|
||||||
|
|
||||||
function findOutlets(collection, callback) {
|
function findOutlets(collection, callback) {
|
||||||
|
|
||||||
const disabledPlugins = Discourse.Site.currentProp('disabled_plugins') || [];
|
const disabledPlugins = Discourse.Site.currentProp('disabled_plugins') || [];
|
||||||
|
|
||||||
Object.keys(collection).forEach(function(res) {
|
Object.keys(collection).forEach(function(res) {
|
||||||
@ -62,6 +53,7 @@ function findOutlets(collection, callback) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function clearCache() {
|
export function clearCache() {
|
||||||
|
_templateCache = null;
|
||||||
_connectorCache = null;
|
_connectorCache = null;
|
||||||
_rawCache = null;
|
_rawCache = null;
|
||||||
}
|
}
|
||||||
@ -69,57 +61,32 @@ export function clearCache() {
|
|||||||
function buildConnectorCache() {
|
function buildConnectorCache() {
|
||||||
_connectorCache = {};
|
_connectorCache = {};
|
||||||
_rawCache = {};
|
_rawCache = {};
|
||||||
|
_templateCache = [];
|
||||||
const uniqueViews = {};
|
|
||||||
findOutlets(requirejs._eak_seen, function(outletName, resource, uniqueName) {
|
|
||||||
_connectorCache[outletName] = _connectorCache[outletName] || [];
|
|
||||||
|
|
||||||
const viewClass = require(resource, null, null, true).default;
|
|
||||||
uniqueViews[uniqueName] = viewClass;
|
|
||||||
_connectorCache[outletName].pushObject(viewClass);
|
|
||||||
});
|
|
||||||
|
|
||||||
findOutlets(Ember.TEMPLATES, function(outletName, resource, uniqueName) {
|
findOutlets(Ember.TEMPLATES, function(outletName, resource, uniqueName) {
|
||||||
const mixin = {templateName: resource.replace('javascripts/', '')};
|
if (/\.raw$/.test(uniqueName)) {
|
||||||
let viewClass = uniqueViews[uniqueName];
|
|
||||||
|
|
||||||
if (viewClass) {
|
|
||||||
// We are going to add it back with the proper template
|
|
||||||
_connectorCache[outletName] = _connectorCache[outletName] || [];
|
|
||||||
_connectorCache[outletName].removeObject(viewClass);
|
|
||||||
} else {
|
|
||||||
if (!/\.raw$/.test(uniqueName)) {
|
|
||||||
viewClass = Ember.View.extend({ classNames: [outletName + '-outlet', uniqueName] });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (viewClass) {
|
|
||||||
_connectorCache[outletName] = _connectorCache[outletName] || [];
|
|
||||||
_connectorCache[outletName].pushObject(viewClass.extend(mixin));
|
|
||||||
} else {
|
|
||||||
// we have a raw template
|
|
||||||
if (!_rawCache[outletName]) {
|
if (!_rawCache[outletName]) {
|
||||||
_rawCache[outletName] = [];
|
_rawCache[outletName] = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
_rawCache[outletName].push(Ember.TEMPLATES[resource]);
|
_rawCache[outletName].push(Ember.TEMPLATES[resource]);
|
||||||
|
} else {
|
||||||
|
_connectorCache[outletName] = _connectorCache[outletName] || [];
|
||||||
|
|
||||||
|
_connectorCache[outletName].push({
|
||||||
|
templateName: resource.replace('javascripts/', ''),
|
||||||
|
template: Ember.TEMPLATES[resource],
|
||||||
|
classNames: `${outletName}-outlet ${uniqueName}`
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
Object.keys(_connectorCache).forEach(outletName => {
|
||||||
|
const connector = _connectorCache[outletName];
|
||||||
var _viewInjections;
|
(connector || []).forEach(s => {
|
||||||
function viewInjections(container) {
|
_templateCache.push(s.template);
|
||||||
if (_viewInjections) { return _viewInjections; }
|
s.templateId = parseInt(_templateCache.length - 1);
|
||||||
|
});
|
||||||
const injections = container._registry.getTypeInjections('view');
|
|
||||||
|
|
||||||
_viewInjections = {};
|
|
||||||
injections.forEach(function(i) {
|
|
||||||
_viewInjections[i.property] = container.lookup(i.fullName);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return _viewInjections;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// unbound version of outlets, only has a template
|
// unbound version of outlets, only has a template
|
||||||
@ -136,41 +103,50 @@ Handlebars.registerHelper('plugin-outlet', function(name) {
|
|||||||
|
|
||||||
return new Handlebars.SafeString(output.join(""));
|
return new Handlebars.SafeString(output.join(""));
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
registerHelper('plugin-outlet', function([connectionName], hash, options, env) {
|
const { registerKeyword } = Ember.__loader.require("ember-htmlbars/keywords");
|
||||||
if (!_connectorCache) { buildConnectorCache(); }
|
const { internal } = Ember.__loader.require('htmlbars-runtime');
|
||||||
|
|
||||||
if (_connectorCache[connectionName]) {
|
registerKeyword('plugin-outlet', {
|
||||||
const childViews = _connectorCache[connectionName];
|
setupState(state, env, scope, params) {
|
||||||
|
if (!_connectorCache) { buildConnectorCache(); }
|
||||||
|
return { outletName: env.hooks.getValue(params[0]) };
|
||||||
|
},
|
||||||
|
|
||||||
// If there is more than one view, create a container. Otherwise
|
render(renderNode, env, scope, params, hash, template, inverse, visitor) {
|
||||||
// just shove it in.
|
let state = renderNode.getState();
|
||||||
const viewClass = (childViews.length > 1) ? Ember.ContainerView : childViews[0];
|
if (!state.outletName) { return true; }
|
||||||
|
const connector = _connectorCache[state.outletName];
|
||||||
|
if (!connector || connector.length === 0) { return true; }
|
||||||
|
|
||||||
// TODO: Figure out how to do this without a container view
|
const listTemplate = Ember.TEMPLATES['outlet-list'];
|
||||||
if (env) {
|
listTemplate.raw.locals = ['templateId', 'outletClasses', 'tagName'];
|
||||||
const newHash = $.extend({}, viewInjections(env.data.view.container));
|
|
||||||
if (hash.tagName) { newHash.tagName = hash.tagName; }
|
|
||||||
|
|
||||||
// we don't need the default template since we have a connector
|
internal.hostBlock(renderNode, env, scope, listTemplate.raw, null, null, visitor, function(options) {
|
||||||
delete options.fn;
|
connector.forEach(source => {
|
||||||
delete options.template;
|
const tid = source.templateId;
|
||||||
env.helpers.view.helperFunction.call(this, [viewClass], newHash, options, env);
|
options.templates.template.yieldItem(`d-outlet-${tid}`, [
|
||||||
|
tid,
|
||||||
const cvs = env.data.view._childViews;
|
source.classNames,
|
||||||
if (childViews.length > 1 && cvs && cvs.length) {
|
hash.tagName || 'div'
|
||||||
const inserted = cvs[cvs.length-1];
|
]);
|
||||||
if (inserted) {
|
});
|
||||||
childViews.forEach(function(cv) {
|
});
|
||||||
inserted.pushObject(cv.create());
|
return true;
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// No longer used
|
registerKeyword('connector', function(morph, env, scope, params, hash, template, inverse, visitor) {
|
||||||
export function rewire() { }
|
template = _templateCache[parseInt(env.hooks.getValue(hash.templateId))];
|
||||||
|
|
||||||
|
env.hooks.component(morph,
|
||||||
|
env,
|
||||||
|
scope,
|
||||||
|
'connector-container',
|
||||||
|
params,
|
||||||
|
hash,
|
||||||
|
{ default: template.raw, inverse },
|
||||||
|
visitor);
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
@ -0,0 +1 @@
|
|||||||
|
{{html}}
|
@ -0,0 +1 @@
|
|||||||
|
{{connector templateId=(unbound templateId) class=(unbound outletClasses) tagName=(unbound tagName)}}
|
17119
vendor/assets/javascripts/ember-template-compiler.js
vendored
17119
vendor/assets/javascripts/ember-template-compiler.js
vendored
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user