mirror of
https://github.com/codeninjasllc/discourse.git
synced 2025-03-14 00:50:14 -04:00
FEATURE: raw helper has access to parent and options view object
This commit is contained in:
parent
2aec93c13d
commit
8524a9d94b
1 changed files with 24 additions and 0 deletions
|
@ -1,10 +1,34 @@
|
|||
import registerUnbound from 'discourse/helpers/register-unbound';
|
||||
|
||||
var viewCache = {};
|
||||
|
||||
registerUnbound('raw', function(templateName, params) {
|
||||
var template = Discourse.__container__.lookup('template:' + templateName + '.raw');
|
||||
if (!template) {
|
||||
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));
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue