Skip to content

Commit 1ce651d

Browse files
committed
Allow pug file extensions in html-resource-plugin
1 parent 750f519 commit 1ce651d

File tree

1 file changed

+22
-17
lines changed

1 file changed

+22
-17
lines changed

src/html-resource-plugin.ts

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,35 @@
11
import {ViewEngine} from 'aurelia-templating';
22
import {_createDynamicElement} from './dynamic-element';
33

4+
const VIEW_EXTENSIONS = ['html', 'jade', 'pug'];
5+
const VIEW_REGEXP = new RegExp('([^\\/^\\?]+)\\.(' + VIEW_EXTENSIONS.join('|') + ')', 'i');
6+
47
export function getElementName(address) {
5-
return /([^\/^\?]+)\.html/i.exec(address)[1].toLowerCase();
8+
return VIEW_REGEXP.exec(address)[1].toLowerCase();
69
}
710

811
export function configure(config) {
912
const viewEngine = config.container.get(ViewEngine);
1013
const loader = config.aurelia.loader;
1114

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);
15+
const fetch = function(viewUrl) {
16+
return loader.loadTemplate(viewUrl).then(registryEntry => {
17+
let bindableNames = registryEntry.template.getAttribute('bindable');
18+
const useShadowDOMmode: null | '' | 'open' | 'closed' = registryEntry.template.getAttribute('use-shadow-dom');
19+
const name = getElementName(viewUrl);
20+
21+
if (bindableNames) {
22+
bindableNames = bindableNames.split(',').map(x => x.trim());
23+
registryEntry.template.removeAttribute('bindable');
24+
} else {
25+
bindableNames = [];
26+
}
1827

19-
if (bindableNames) {
20-
bindableNames = bindableNames.split(',').map(x => x.trim());
21-
registryEntry.template.removeAttribute('bindable');
22-
} else {
23-
bindableNames = [];
24-
}
28+
return { [name]: _createDynamicElement({name, viewUrl, bindableNames, useShadowDOMmode}) };
29+
});
30+
};
2531

26-
return { [name]: _createDynamicElement({name, viewUrl, bindableNames, useShadowDOMmode}) };
27-
});
28-
}
29-
});
32+
for (const ext of VIEW_EXTENSIONS) {
33+
viewEngine.addResourcePlugin('.' + ext, {fetch});
34+
}
3035
}

0 commit comments

Comments
 (0)