-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
93479b8
commit 0dd69ec
Showing
2 changed files
with
51 additions
and
41 deletions.
There are no files selected for viewing
91 changes: 50 additions & 41 deletions
91
packages/@ember/-internals/views/lib/system/lookup_partial.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,65 +1,74 @@ | ||
import { assert, deprecate } from '@ember/debug'; | ||
import EmberError from '@ember/error'; | ||
import { PARTIALS } from '@ember/deprecated-features'; | ||
|
||
function parseUnderscoredName(templateName) { | ||
let nameParts = templateName.split('/'); | ||
let lastPart = nameParts[nameParts.length - 1]; | ||
if (PARTIALS) { | ||
let nameParts = templateName.split('/'); | ||
let lastPart = nameParts[nameParts.length - 1]; | ||
|
||
nameParts[nameParts.length - 1] = `_${lastPart}`; | ||
nameParts[nameParts.length - 1] = `_${lastPart}`; | ||
|
||
return nameParts.join('/'); | ||
return nameParts.join('/'); | ||
} | ||
} | ||
|
||
export default function lookupPartial(templateName, owner) { | ||
deprecate( | ||
`The use of \`{{partial}}\` is deprecated, please refactor the "${templateName}" partial to a component`, | ||
false, | ||
{ | ||
id: 'ember-views.partial', | ||
until: '4.0.0', | ||
url: 'https://deprecations.emberjs.com/v3.x#toc_ember-views-partial', | ||
} | ||
); | ||
if (PARTIALS) { | ||
deprecate( | ||
`The use of \`{{partial}}\` is deprecated, please refactor the "${templateName}" partial to a component`, | ||
false, | ||
{ | ||
id: 'ember-views.partial', | ||
until: '4.0.0', | ||
url: 'https://deprecations.emberjs.com/v3.x#toc_ember-views-partial', | ||
} | ||
); | ||
|
||
if (templateName == null) { | ||
return; | ||
} | ||
if (templateName == null) { | ||
return; | ||
} | ||
|
||
let template = templateFor(owner, parseUnderscoredName(templateName), templateName); | ||
let template = templateFor(owner, parseUnderscoredName(templateName), templateName); | ||
|
||
assert(`Unable to find partial with name "${templateName}"`, Boolean(template)); | ||
assert(`Unable to find partial with name "${templateName}"`, Boolean(template)); | ||
|
||
return template; | ||
return template; | ||
} | ||
} | ||
|
||
export function hasPartial(name, owner) { | ||
if (!owner) { | ||
throw new EmberError( | ||
'Container was not found when looking up a views template. ' + | ||
'This is most likely due to manually instantiating an Ember.View. ' + | ||
'See: http://git.io/EKPpnA' | ||
if (PARTIALS) { | ||
if (!owner) { | ||
throw new EmberError( | ||
'Container was not found when looking up a views template. ' + | ||
'This is most likely due to manually instantiating an Ember.View. ' + | ||
'See: http://git.io/EKPpnA' | ||
); | ||
} | ||
|
||
return ( | ||
owner.hasRegistration(`template:${parseUnderscoredName(name)}`) || | ||
owner.hasRegistration(`template:${name}`) | ||
); | ||
} | ||
|
||
return ( | ||
owner.hasRegistration(`template:${parseUnderscoredName(name)}`) || | ||
owner.hasRegistration(`template:${name}`) | ||
); | ||
} | ||
|
||
function templateFor(owner, underscored, name) { | ||
if (!name) { | ||
return; | ||
} | ||
assert(`templateNames are not allowed to contain periods: ${name}`, name.indexOf('.') === -1); | ||
if (PARTIALS) { | ||
if (!name) { | ||
return; | ||
} | ||
assert(`templateNames are not allowed to contain periods: ${name}`, name.indexOf('.') === -1); | ||
|
||
if (!owner) { | ||
throw new EmberError( | ||
'Container was not found when looking up a views template. ' + | ||
'This is most likely due to manually instantiating an Ember.View. ' + | ||
'See: http://git.io/EKPpnA' | ||
); | ||
} | ||
if (!owner) { | ||
throw new EmberError( | ||
'Container was not found when looking up a views template. ' + | ||
'This is most likely due to manually instantiating an Ember.View. ' + | ||
'See: http://git.io/EKPpnA' | ||
); | ||
} | ||
|
||
return owner.lookup(`template:${underscored}`) || owner.lookup(`template:${name}`); | ||
return owner.lookup(`template:${underscored}`) || owner.lookup(`template:${name}`); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters