aurelia-templating-resources
Version:
A standard set of behaviors, converters and other resources for use with the Aurelia templating library.
31 lines (25 loc) • 1.1 kB
text/typescript
import {ViewEngine} from 'aurelia-templating';
import {_createDynamicElement} from './dynamic-element';
export function getElementName(address) {
return /([^\/^\?]+)\.html/i.exec(address)[1].toLowerCase();
}
export function configure(config) {
const viewEngine = config.container.get(ViewEngine);
const loader = config.aurelia.loader;
viewEngine.addResourcePlugin('.html', {
'fetch': function(viewUrl) {
return loader.loadTemplate(viewUrl).then(registryEntry => {
let bindableNames = registryEntry.template.getAttribute('bindable');
const useShadowDOMmode: null | '' | 'open' | 'closed' = registryEntry.template.getAttribute('use-shadow-dom');
const name = getElementName(viewUrl);
if (bindableNames) {
bindableNames = bindableNames.split(',').map(x => x.trim());
registryEntry.template.removeAttribute('bindable');
} else {
bindableNames = [];
}
return { [name]: _createDynamicElement({name, viewUrl, bindableNames, useShadowDOMmode}) };
});
}
});
}