[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

@ -30,7 +30,7 @@ requirejs.config({
"moment": "bower_components/moment/moment",
"moment-duration-format": "bower_components/moment-duration-format/lib/moment-duration-format",
"screenfull": "bower_components/screenfull/dist/screenfull.min",
"text": "bower_components/text/text.js",
"text": "bower_components/text/text",
"uuid": "bower_components/node-uuid/uuid"
},
"shim": {

View File

@ -22,11 +22,13 @@
/*global define*/
define([
"text!./res/templates/about-dialog.html",
"./src/LogoController",
"./src/AboutController",
"./src/LicenseController",
'legacyRegistry'
], function (
aboutDialogTemplate,
LogoController,
AboutController,
LicenseController,
@ -50,7 +52,7 @@ define([
},
{
"key": "about-dialog",
"templateUrl": "templates/about-dialog.html"
"template": aboutDialogTemplate
},
{
"key": "overlay-about",

View File

@ -74,7 +74,7 @@ define(
var key = template.key;
// First found should win (priority ordering)
templateMap[key] =
templateMap[key] || templateLinker.getPath(template);
templateMap[key] || template;
});
return {

View File

@ -69,11 +69,6 @@ define(
representationMap[representation.key].push(representation);
});
// Get a path to a representation
function getPath(representation) {
return templateLinker.getPath(representation);
}
// Look up a matching representation for this domain object
function lookup(key, domainObject) {
var candidates = representationMap[key] || [],
@ -175,9 +170,8 @@ define(
function refresh() {
var domainObject = $scope.domainObject,
representation = lookup($scope.key, domainObject),
path = representation && getPath(representation),
uses = ((representation || {}).uses || []),
canRepresent = !!(path && domainObject),
canRepresent = !!(representation && domainObject),
canEdit = !!(domainObject && domainObject.hasCapability('editor')),
idPath = getIdPath(domainObject),
key = $scope.key;
@ -192,7 +186,7 @@ define(
// Change templates (passing in undefined to clear
// if we don't have enough info to show a template.)
changeTemplate(canRepresent ? path : undefined);
changeTemplate(canRepresent ? representation : undefined);
// Any existing representers are no longer valid; release them.
destroyRepresenters();

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;
};

View File

@ -38,11 +38,10 @@ define(
.reduce(function (a, b) {
return a.concat(b);
}, [])
.map(function (ext) {
return templateLinker.getPath(ext);
})
.forEach(function (path) {
templateLinker.load(path);
.forEach(function (ext) {
if (ext.templateUrl) {
templateLinker.load(templateLinker.getPath(ext));
}
});
}