|
1 | 1 | import {ViewEngine} from 'aurelia-templating'; |
2 | 2 | import {_createDynamicElement} from './dynamic-element'; |
3 | 3 |
|
| 4 | +const VIEW_EXTENSIONS = ['html', 'jade', 'pug']; |
| 5 | +const VIEW_REGEXP = new RegExp('([^\\/^\\?]+)\\.(' + VIEW_EXTENSIONS.join('|') + ')', 'i'); |
| 6 | + |
4 | 7 | export function getElementName(address) { |
5 | | - return /([^\/^\?]+)\.html/i.exec(address)[1].toLowerCase(); |
| 8 | + return VIEW_REGEXP.exec(address)[1].toLowerCase(); |
6 | 9 | } |
7 | 10 |
|
8 | 11 | export function configure(config) { |
9 | 12 | const viewEngine = config.container.get(ViewEngine); |
10 | 13 | const loader = config.aurelia.loader; |
11 | 14 |
|
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 | + } |
18 | 27 |
|
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 | + }; |
25 | 31 |
|
26 | | - return { [name]: _createDynamicElement({name, viewUrl, bindableNames, useShadowDOMmode}) }; |
27 | | - }); |
28 | | - } |
29 | | - }); |
| 32 | + for (const ext of VIEW_EXTENSIONS) { |
| 33 | + viewEngine.addResourcePlugin('.' + ext, {fetch}); |
| 34 | + } |
30 | 35 | } |
0 commit comments