mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-27 17:46:05 -05:00
Raw templates should resolve their views with the resolver
This commit is contained in:
parent
8627a1e507
commit
c02a31d8b4
7 changed files with 61 additions and 67 deletions
|
@ -1,6 +1,17 @@
|
|||
import registerUnbound from 'discourse/helpers/register-unbound';
|
||||
|
||||
var viewCache = {};
|
||||
export function renderRaw(template, templateName, params) {
|
||||
params.parent = params.parent || this;
|
||||
|
||||
if (!params.view) {
|
||||
var viewClass = Discourse.__container__.lookupFactory('view:' + templateName);
|
||||
if (viewClass) {
|
||||
params.view = viewClass.create(params);
|
||||
}
|
||||
}
|
||||
|
||||
return new Handlebars.SafeString(template(params));
|
||||
}
|
||||
|
||||
registerUnbound('raw', function(templateName, params) {
|
||||
var template = Discourse.__container__.lookup('template:' + templateName + '.raw');
|
||||
|
@ -8,27 +19,6 @@ registerUnbound('raw', function(templateName, params) {
|
|||
Ember.warn('Could not find raw template: ' + templateName);
|
||||
return;
|
||||
}
|
||||
if(!params.parent) {
|
||||
params.parent = this;
|
||||
}
|
||||
|
||||
if(!params.view) {
|
||||
var cached = viewCache[templateName];
|
||||
if(cached){
|
||||
params.view = cached === "X" ? undefined : cached.create(params);
|
||||
} else {
|
||||
var split = templateName.split("/");
|
||||
var last = split[split.length-1];
|
||||
var name = "discourse/views/" + last;
|
||||
|
||||
if(hasModule(name)){
|
||||
viewCache[templateName] = require(name).default;
|
||||
params.view = viewCache[templateName].create(params);
|
||||
} else {
|
||||
viewCache[templateName] = "X";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return new Handlebars.SafeString(template(params));
|
||||
return renderRaw.call(this, template, templateName, params);
|
||||
});
|
||||
|
|
|
@ -1,30 +1,34 @@
|
|||
var get = Discourse.EmberCompatHandlebars.get;
|
||||
|
||||
export function resolveParams(options) {
|
||||
var params = {},
|
||||
hash = options.hash;
|
||||
|
||||
if (hash) {
|
||||
var self = this;
|
||||
if (options.hashTypes) {
|
||||
Ember.keys(hash).forEach(function(k) {
|
||||
var type = options.hashTypes[k];
|
||||
if (type === "STRING") {
|
||||
params[k] = hash[k];
|
||||
} else if (type === "ID") {
|
||||
params[k] = get(self, hash[k], options);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
params = hash;
|
||||
}
|
||||
}
|
||||
return params;
|
||||
}
|
||||
|
||||
export default function registerUnbound(name, fn) {
|
||||
Handlebars.registerHelper(name, function(property, options) {
|
||||
|
||||
if (options.types && options.types[0] === "ID") {
|
||||
property = get(this, property, options);
|
||||
}
|
||||
|
||||
var params = {},
|
||||
hash = options.hash;
|
||||
|
||||
if (hash) {
|
||||
var self = this;
|
||||
if (options.hashTypes) {
|
||||
Ember.keys(hash).forEach(function(k) {
|
||||
var type = options.hashTypes[k];
|
||||
if (type === "STRING") {
|
||||
params[k] = hash[k];
|
||||
} else if (type === "ID") {
|
||||
params[k] = get(self, hash[k], options);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
params = hash;
|
||||
}
|
||||
}
|
||||
var params = resolveParams.call(this, options);
|
||||
|
||||
return fn.apply(this,[property, params]);
|
||||
});
|
||||
|
|
|
@ -1,24 +0,0 @@
|
|||
{{#if bulkSelectEnabled}}
|
||||
<th class='star'>
|
||||
<button class='btn bulk-select' title='{{i18n "topics.bulk.toggle"}}'><i class='fa fa-list'></i></button>
|
||||
</th>
|
||||
{{/if}}
|
||||
{{raw "components/topic-list-header-column" order='default' name='topic.title' showBulkToggle=toggleInTitle}}
|
||||
{{#unless hideCategory}}
|
||||
{{raw "components/topic-list-header-column" sortable=sortable order='category' name='category_title'}}
|
||||
{{/unless}}
|
||||
{{#if showPosters}}
|
||||
{{raw "components/topic-list-header-column" order='posters' name='users'}}
|
||||
{{/if}}
|
||||
{{raw "components/topic-list-header-column" sortable=sortable number='true' order='posts' name='posts'}}
|
||||
{{#if showParticipants}}
|
||||
{{raw "components/topic-list-header-column" order='participants' name='users'}}
|
||||
{{/if}}
|
||||
{{#if showLikes}}
|
||||
{{raw "components/topic-list-header-column" sortable=sortable number='true' order='likes' name='likes'}}
|
||||
{{/if}}
|
||||
{{#if showOpLikes}}
|
||||
{{raw "components/topic-list-header-column" sortable=sortable number='true' order='op_likes' name='likes'}}
|
||||
{{/if}}
|
||||
{{raw "components/topic-list-header-column" sortable=sortable number='true' order='views' name='views'}}
|
||||
{{raw "components/topic-list-header-column" sortable=sortable number='true' order='activity' name='activity'}}
|
|
@ -1,6 +1,6 @@
|
|||
{{#unless skipHeader}}
|
||||
<thead>
|
||||
{{raw "components/topic-list-header"
|
||||
{{raw "topic-list-header"
|
||||
currentUser=currentUser
|
||||
canBulkSelect=canBulkSelect
|
||||
toggleInTitle=toggleInTitle
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
{{#if bulkSelectEnabled}}
|
||||
<th class='star'>
|
||||
<button class='btn bulk-select' title='{{i18n "topics.bulk.toggle"}}'><i class='fa fa-list'></i></button>
|
||||
</th>
|
||||
{{/if}}
|
||||
{{raw "topic-list-header-column" order='default' name='topic.title' showBulkToggle=toggleInTitle}}
|
||||
{{#unless hideCategory}}
|
||||
{{raw "topic-list-header-column" sortable=sortable order='category' name='category_title'}}
|
||||
{{/unless}}
|
||||
{{#if showPosters}}
|
||||
{{raw "topic-list-header-column" order='posters' name='users'}}
|
||||
{{/if}}
|
||||
{{raw "topic-list-header-column" sortable=sortable number='true' order='posts' name='posts'}}
|
||||
{{#if showParticipants}}
|
||||
{{raw "topic-list-header-column" order='participants' name='users'}}
|
||||
{{/if}}
|
||||
{{#if showLikes}}
|
||||
{{raw "topic-list-header-column" sortable=sortable number='true' order='likes' name='likes'}}
|
||||
{{/if}}
|
||||
{{#if showOpLikes}}
|
||||
{{raw "topic-list-header-column" sortable=sortable number='true' order='op_likes' name='likes'}}
|
||||
{{/if}}
|
||||
{{raw "topic-list-header-column" sortable=sortable number='true' order='views' name='views'}}
|
||||
{{raw "topic-list-header-column" sortable=sortable number='true' order='activity' name='activity'}}
|
Loading…
Reference in a new issue