|
1 | 1 | import { assert, deprecate } from '@ember/debug'; |
2 | 2 | import EmberError from '@ember/error'; |
| 3 | +import { PARTIALS } from '@ember/deprecated-features'; |
3 | 4 |
|
4 | 5 | function parseUnderscoredName(templateName) { |
5 | | - let nameParts = templateName.split('/'); |
6 | | - let lastPart = nameParts[nameParts.length - 1]; |
| 6 | + if (PARTIALS) { |
| 7 | + let nameParts = templateName.split('/'); |
| 8 | + let lastPart = nameParts[nameParts.length - 1]; |
7 | 9 |
|
8 | | - nameParts[nameParts.length - 1] = `_${lastPart}`; |
| 10 | + nameParts[nameParts.length - 1] = `_${lastPart}`; |
9 | 11 |
|
10 | | - return nameParts.join('/'); |
| 12 | + return nameParts.join('/'); |
| 13 | + } |
11 | 14 | } |
12 | 15 |
|
13 | 16 | export default function lookupPartial(templateName, owner) { |
14 | | - deprecate( |
15 | | - `The use of \`{{partial}}\` is deprecated, please refactor the "${templateName}" partial to a component`, |
16 | | - false, |
17 | | - { |
18 | | - id: 'ember-views.partial', |
19 | | - until: '4.0.0', |
20 | | - url: 'https://deprecations.emberjs.com/v3.x#toc_ember-views-partial', |
21 | | - } |
22 | | - ); |
| 17 | + if (PARTIALS) { |
| 18 | + deprecate( |
| 19 | + `The use of \`{{partial}}\` is deprecated, please refactor the "${templateName}" partial to a component`, |
| 20 | + false, |
| 21 | + { |
| 22 | + id: 'ember-views.partial', |
| 23 | + until: '4.0.0', |
| 24 | + url: 'https://deprecations.emberjs.com/v3.x#toc_ember-views-partial', |
| 25 | + } |
| 26 | + ); |
23 | 27 |
|
24 | | - if (templateName == null) { |
25 | | - return; |
26 | | - } |
| 28 | + if (templateName == null) { |
| 29 | + return; |
| 30 | + } |
27 | 31 |
|
28 | | - let template = templateFor(owner, parseUnderscoredName(templateName), templateName); |
| 32 | + let template = templateFor(owner, parseUnderscoredName(templateName), templateName); |
29 | 33 |
|
30 | | - assert(`Unable to find partial with name "${templateName}"`, Boolean(template)); |
| 34 | + assert(`Unable to find partial with name "${templateName}"`, Boolean(template)); |
31 | 35 |
|
32 | | - return template; |
| 36 | + return template; |
| 37 | + } |
33 | 38 | } |
34 | 39 |
|
35 | 40 | export function hasPartial(name, owner) { |
36 | | - if (!owner) { |
37 | | - throw new EmberError( |
38 | | - 'Container was not found when looking up a views template. ' + |
39 | | - 'This is most likely due to manually instantiating an Ember.View. ' + |
40 | | - 'See: http://git.io/EKPpnA' |
| 41 | + if (PARTIALS) { |
| 42 | + if (!owner) { |
| 43 | + throw new EmberError( |
| 44 | + 'Container was not found when looking up a views template. ' + |
| 45 | + 'This is most likely due to manually instantiating an Ember.View. ' + |
| 46 | + 'See: http://git.io/EKPpnA' |
| 47 | + ); |
| 48 | + } |
| 49 | + |
| 50 | + return ( |
| 51 | + owner.hasRegistration(`template:${parseUnderscoredName(name)}`) || |
| 52 | + owner.hasRegistration(`template:${name}`) |
41 | 53 | ); |
42 | 54 | } |
43 | | - |
44 | | - return ( |
45 | | - owner.hasRegistration(`template:${parseUnderscoredName(name)}`) || |
46 | | - owner.hasRegistration(`template:${name}`) |
47 | | - ); |
48 | 55 | } |
49 | 56 |
|
50 | 57 | function templateFor(owner, underscored, name) { |
51 | | - if (!name) { |
52 | | - return; |
53 | | - } |
54 | | - assert(`templateNames are not allowed to contain periods: ${name}`, name.indexOf('.') === -1); |
| 58 | + if (PARTIALS) { |
| 59 | + if (!name) { |
| 60 | + return; |
| 61 | + } |
| 62 | + assert(`templateNames are not allowed to contain periods: ${name}`, name.indexOf('.') === -1); |
55 | 63 |
|
56 | | - if (!owner) { |
57 | | - throw new EmberError( |
58 | | - 'Container was not found when looking up a views template. ' + |
59 | | - 'This is most likely due to manually instantiating an Ember.View. ' + |
60 | | - 'See: http://git.io/EKPpnA' |
61 | | - ); |
62 | | - } |
| 64 | + if (!owner) { |
| 65 | + throw new EmberError( |
| 66 | + 'Container was not found when looking up a views template. ' + |
| 67 | + 'This is most likely due to manually instantiating an Ember.View. ' + |
| 68 | + 'See: http://git.io/EKPpnA' |
| 69 | + ); |
| 70 | + } |
63 | 71 |
|
64 | | - return owner.lookup(`template:${underscored}`) || owner.lookup(`template:${name}`); |
| 72 | + return owner.lookup(`template:${underscored}`) || owner.lookup(`template:${name}`); |
| 73 | + } |
65 | 74 | } |
0 commit comments