UNPKG

1.1 kBPlain TextView Raw
1import {ViewEngine} from 'aurelia-templating';
2import {_createDynamicElement} from './dynamic-element';
3
4export function getElementName(address) {
5 return /([^\/^\?]+)\.html/i.exec(address)[1].toLowerCase();
6}
7
8export function configure(config) {
9 const viewEngine = config.container.get(ViewEngine);
10 const loader = config.aurelia.loader;
11
12 viewEngine.addResourcePlugin('.html', {
13 'fetch': function(viewUrl) {
14 return loader.loadTemplate(viewUrl).then(registryEntry => {
15 let bindableNames = registryEntry.template.getAttribute('bindable');
16 const useShadowDOMmode: null | '' | 'open' | 'closed' = registryEntry.template.getAttribute('use-shadow-dom');
17 const name = getElementName(viewUrl);
18
19 if (bindableNames) {
20 bindableNames = bindableNames.split(',').map(x => x.trim());
21 registryEntry.template.removeAttribute('bindable');
22 } else {
23 bindableNames = [];
24 }
25
26 return { [name]: _createDynamicElement({name, viewUrl, bindableNames, useShadowDOMmode}) };
27 });
28 }
29 });
30}