mirror of
https://github.com/discourse/discourse.git
synced 2025-03-26 03:15:41 +08:00
Support for Raw Handlebars and helpers in Ember 1.13
This commit is contained in:
parent
41f19641d1
commit
b601120b39
app/assets/javascripts
discourse-common
discourse
helpers
templates
views
lib/freedom_patches
@ -55,12 +55,6 @@ function resolveParams(ctx, options) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function registerUnbound(name, fn) {
|
export function registerUnbound(name, fn) {
|
||||||
if (Ember.Helper) {
|
|
||||||
_helpers[name] = Ember.Helper.helper(function() {
|
|
||||||
// TODO: Allow newer ember to use helpers
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const func = function(property, options) {
|
const func = function(property, options) {
|
||||||
if (options.types && (options.types[0] === "ID" || options.types[0] === "PathExpression")) {
|
if (options.types && (options.types[0] === "ID" || options.types[0] === "PathExpression")) {
|
||||||
@ -70,6 +64,14 @@ export function registerUnbound(name, fn) {
|
|||||||
return fn.call(this, property, resolveParams(this, options));
|
return fn.call(this, property, resolveParams(this, options));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (Ember.Helper) {
|
||||||
|
_helpers[name] = Ember.Helper.extend({
|
||||||
|
compute: (params, args) => fn(params[0], args)
|
||||||
|
});
|
||||||
|
Handlebars.registerHelper(name, func);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
Handlebars.registerHelper(name, func);
|
Handlebars.registerHelper(name, func);
|
||||||
Ember.Handlebars.registerHelper(name, func);
|
Ember.Handlebars.registerHelper(name, func);
|
||||||
}
|
}
|
||||||
|
@ -132,6 +132,12 @@ export function buildResolver(baseName) {
|
|||||||
},
|
},
|
||||||
|
|
||||||
resolveTemplate(parsedName) {
|
resolveTemplate(parsedName) {
|
||||||
|
let fullName = parsedName.fullNameWithoutType;
|
||||||
|
if (fullName.indexOf('.raw') !== -1) {
|
||||||
|
return Ember.TEMPLATES[fullName] ||
|
||||||
|
Ember.TEMPLATES[fullName.replace(/\.raw$/, '')];
|
||||||
|
}
|
||||||
|
|
||||||
return this.findPluginMobileTemplate(parsedName) ||
|
return this.findPluginMobileTemplate(parsedName) ||
|
||||||
this.findPluginTemplate(parsedName) ||
|
this.findPluginTemplate(parsedName) ||
|
||||||
this.findMobileTemplate(parsedName) ||
|
this.findMobileTemplate(parsedName) ||
|
||||||
|
@ -1,17 +1,27 @@
|
|||||||
import { registerUnbound } from 'discourse-common/lib/helpers';
|
import { registerUnbound } from 'discourse-common/lib/helpers';
|
||||||
|
|
||||||
// see: https://github.com/emberjs/ember.js/issues/12634
|
let _injections;
|
||||||
var missingViews = {};
|
|
||||||
|
|
||||||
function renderRaw(ctx, template, templateName, params) {
|
function renderRaw(ctx, container, template, templateName, params) {
|
||||||
params.parent = params.parent || ctx;
|
params.parent = params.parent || ctx;
|
||||||
|
|
||||||
if (!params.view && !missingViews[templateName]) {
|
if (!params.view) {
|
||||||
var viewClass = Discourse.__container__.lookupFactory('view:' + templateName);
|
if (!_injections) {
|
||||||
if (viewClass) {
|
_injections = {
|
||||||
params.view = viewClass.create(params);
|
siteSettings: container.lookup('site-settings:main'),
|
||||||
} else {
|
currentUser: container.lookup('currentUser:main'),
|
||||||
missingViews[templateName] = true;
|
site: container.lookup('site:main'),
|
||||||
|
session: container.lookup('session:main'),
|
||||||
|
topicTrackingState: container.lookup('topic-tracking-state:main')
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
const module = `discourse/views/${templateName}`;
|
||||||
|
if (requirejs.entries[module]) {
|
||||||
|
const viewClass = require(module, null, null, true);
|
||||||
|
if (viewClass && viewClass.default) {
|
||||||
|
params.view = viewClass.default.create(params, _injections);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -19,10 +29,13 @@ function renderRaw(ctx, template, templateName, params) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
registerUnbound('raw', function(templateName, params) {
|
registerUnbound('raw', function(templateName, params) {
|
||||||
var template = Discourse.__container__.lookup('template:' + templateName + '.raw');
|
templateName = templateName.replace('.', '/');
|
||||||
|
|
||||||
|
const container = Discourse.__container__;
|
||||||
|
var template = container.lookup('template:' + templateName + '.raw');
|
||||||
if (!template) {
|
if (!template) {
|
||||||
Ember.warn('Could not find raw template: ' + templateName);
|
Ember.warn('Could not find raw template: ' + templateName);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
return renderRaw(this, template, templateName, params);
|
return renderRaw(this, container, template, templateName, params);
|
||||||
});
|
});
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
{{site-header canSignUp=canSignUp
|
{{site-header canSignUp=canSignUp
|
||||||
showCreateAccount="showCreateAccount"
|
showCreateAccount="showCreateAccount"
|
||||||
showLogin="showLogin"
|
showLogin="showLogin"
|
||||||
|
@ -1 +1 @@
|
|||||||
<{{this.tagName}} class="{{class}} {{cold-age-class topic.createdAt startDate=topic.bumpedAt class=""}} activity" title="{{{topic.bumpedAtTitle}}}"><a href="{{topic.lastPostUrl}}">{{format-date topic.bumpedAt format="tiny" noTitle="true"}}</a></{{this.tagName}}>
|
<{{tagName}} class="{{class}} {{cold-age-class topic.createdAt startDate=topic.bumpedAt class=""}} activity" title="{{{topic.bumpedAtTitle}}}"><a href="{{topic.lastPostUrl}}">{{format-date topic.bumpedAt format="tiny" noTitle="true"}}</a></{{tagName}}>
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
export default Ember.Object.extend({
|
export default Ember.Object.extend({
|
||||||
|
|
||||||
localizedName: function(){
|
localizedName: function(){
|
||||||
if(this.forceName){
|
if(this.forceName){
|
||||||
return this.forceName;
|
return this.forceName;
|
||||||
|
@ -54,6 +54,18 @@ end
|
|||||||
class Ember::Handlebars::Template
|
class Ember::Handlebars::Template
|
||||||
include Discourse::Ember::Handlebars::Helper
|
include Discourse::Ember::Handlebars::Helper
|
||||||
|
|
||||||
|
def precompile_handlebars(string, input=nil)
|
||||||
|
"require('discourse-common/lib/raw-handlebars').template(#{Barber::Precompiler.compile(string)});"
|
||||||
|
end
|
||||||
|
|
||||||
|
def compile_handlebars(string, input=nil)
|
||||||
|
"require('discourse-common/lib/raw-handlebars').compile(#{indent(string).inspect});"
|
||||||
|
end
|
||||||
|
|
||||||
|
def global_template_target(namespace, module_name, config)
|
||||||
|
"#{namespace}[#{template_path(module_name, config).inspect}]"
|
||||||
|
end
|
||||||
|
|
||||||
# FIXME: Previously, ember-handlebars-templates uses the logical path which incorrectly
|
# FIXME: Previously, ember-handlebars-templates uses the logical path which incorrectly
|
||||||
# returned paths with the `.raw` extension and our code is depending on the `.raw`
|
# returned paths with the `.raw` extension and our code is depending on the `.raw`
|
||||||
# to find the right template to use.
|
# to find the right template to use.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user