[Build] Add compatibility with text plugin

Allow templates to be loaded via the text plugin, which
in turn will allow these to be built into the final JS
artifact.
This commit is contained in:
Victor Woeltjen
2016-01-28 11:41:14 -08:00
parent 967f8c9151
commit e0fbaa83b0
6 changed files with 32 additions and 24 deletions

View File

@ -87,7 +87,7 @@ define(
* @returns {Function} a function which can be called with a template
* URL to switch templates, or `undefined` to remove.
*/
TemplateLinker.prototype.link = function (scope, element, templateUrl) {
TemplateLinker.prototype.link = function (scope, element, ext) {
var activeElement = element,
activeTemplateUrl,
comment = this.$compile('<!-- hidden mct element -->')(scope),
@ -124,12 +124,18 @@ define(
self.$compile(element.contents())(activeScope);
}
function badTemplate(templateUrl) {
function showTemplate(template) {
addElement();
populateElement(template);
activeTemplateUrl = undefined;
}
function badTemplateUrl(templateUrl) {
self.$log.warn("Couldn't load template at " + templateUrl);
removeElement();
}
function changeTemplate(templateUrl) {
function changeTemplateUrl(templateUrl) {
if (templateUrl) {
destroyScope();
addElement();
@ -139,7 +145,7 @@ define(
populateElement(template);
}
}, function () {
badTemplate(templateUrl);
badTemplateUrl(templateUrl);
});
} else {
removeElement();
@ -147,12 +153,19 @@ define(
activeTemplateUrl = templateUrl;
}
if (templateUrl) {
changeTemplate(templateUrl);
} else {
removeElement();
function changeTemplate(ext) {
ext = ext || {};
if (ext.templateUrl) {
changeTemplateUrl(self.getPath(ext));
} else if (ext.template) {
showTemplate(ext.template);
} else {
removeElement();
}
}
changeTemplate(ext);
return changeTemplate;
};