Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass Referrer to Glimmer Resolver #196

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions mu-trees/addon/ember-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,16 @@ export default function generateConfig(name) {
adapter: { definitiveCollection: 'models' },
application: { definitiveCollection: 'main' },
controller: { definitiveCollection: 'routes' },
component: { definitiveCollection: 'components' },
component: {
definitiveCollection: 'components',
privateCollection: 'components'
},
'component-lookup': { definitiveCollection: 'main' },
event_dispatcher: { definitiveCollection: 'main' },
helper: { definitiveCollection: 'components' },
helper: {
definitiveCollection: 'components',
privateCollection: 'components'
},
initializer: { definitiveCollection: 'initializers' },
'instance-initializers': { definitiveCollection: 'instance-initializer' },
location: { definitiveCollection: 'main' },
Expand All @@ -31,6 +37,7 @@ export default function generateConfig(name) {
service: { definitiveCollection: 'services' },
template: {
definitiveCollection: 'routes',
privateCollection: 'components',
fallbackCollectionPrefixes: {
'components': 'components'
}
Expand Down
24 changes: 19 additions & 5 deletions mu-trees/addon/resolvers/glimmer-wrapper/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,35 @@ const Resolver = DefaultResolver.extend({

normalize: null,

resolve(lookupString) {
resolve(lookupString, referrer) {
/*
* Ember paritals are looked up as templates. Here we replace the template
* Ember partials are looked up as templates. Here we replace the template
* resolution with a partial resolute when appropriate. Try to keep this
* code as "pay-go" as possible.
*/

if (lookupString.indexOf('template:') === 0) {
lookupString = this._templateToPartial(lookupString);
}
return this._resolve(lookupString);
return this._resolve(lookupString, referrer);
},

_resolve(lookupString) {
return this._glimmerResolver.resolve(lookupString);
_resolve(lookupString, referrer) {
if (referrer) {
// make absolute
let appName = this.config.app.name;
let parts = referrer.split(':src/ui/');
referrer = `${parts[0]}:/${appName}/${parts[1]}`;
referrer = referrer.split('/template.hbs')[0];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An aside, but @dgeb thinks @wycats and @chancancode are perhaps working on adding the absolute specifier to the template meta a compilation time. One that work lands we could change Ember to pass that and this code goes away 👍


// glimmer resolver will throw and error if specifier has as collection
let match = lookupString.match(/^template:components\/(.*)/);
if (match) {
lookupString = `template:${match[1]}`;
}
}

return this._glimmerResolver.resolve(lookupString, referrer);
},

/*
Expand Down