-
-
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.
View helper learns about the container
```javascript // stays the same {{view App.FuView}} // uses the container {{view 'fu'}} ```
- Loading branch information
1 parent
96ae9fa
commit ae116fa
Showing
2 changed files
with
101 additions
and
1 deletion.
There are no files selected for viewing
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
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 |
---|---|---|
@@ -0,0 +1,87 @@ | ||
var view, originalLookup; | ||
|
||
var container = { | ||
lookupFactory: function(){ } | ||
}; | ||
|
||
function viewClass(options){ | ||
options.container = options.container || container; | ||
return Ember.View.extend(options); | ||
} | ||
|
||
module("Handlebars {{#view}} helper", { | ||
setup: function() { | ||
originalLookup = Ember.lookup; | ||
|
||
}, | ||
|
||
teardown: function() { | ||
Ember.lookup = originalLookup; | ||
Ember.run(view, 'destroy'); | ||
} | ||
}); | ||
|
||
|
||
test("View lookup - App.FuView", function(){ | ||
Ember.lookup = { | ||
App: { | ||
FuView: viewClass({ | ||
elementId: "fu", | ||
template: Ember.Handlebars.compile("bro") | ||
}) | ||
} | ||
}; | ||
|
||
view = viewClass({ | ||
template: Ember.Handlebars.compile("{{view App.FuView}}") | ||
}).create(); | ||
|
||
Ember.run(view, 'appendTo', '#qunit-fixture'); | ||
|
||
equal(Ember.$('#fu').text(), 'bro'); | ||
}); | ||
|
||
test("View lookup - 'App.FuView'", function(){ | ||
Ember.lookup = { | ||
App: { | ||
FuView: viewClass({ | ||
elementId: "fu", | ||
template: Ember.Handlebars.compile("bro") | ||
}) | ||
} | ||
}; | ||
|
||
view = viewClass({ | ||
template: Ember.Handlebars.compile("{{view 'App.FuView'}}") | ||
}).create(); | ||
|
||
Ember.run(view, 'appendTo', '#qunit-fixture'); | ||
|
||
equal(Ember.$('#fu').text(), 'bro'); | ||
}); | ||
|
||
test("View lookup - 'fu'", function(){ | ||
var FuView = viewClass({ | ||
elementId: "fu", | ||
template: Ember.Handlebars.compile("bro") | ||
}); | ||
|
||
var container = { | ||
lookupFactory: lookupFactory | ||
}; | ||
|
||
view = Ember.View.extend({ | ||
template: Ember.Handlebars.compile("{{view 'fu'}}"), | ||
container: container | ||
}).create(); | ||
|
||
Ember.run(view, 'appendTo', '#qunit-fixture'); | ||
|
||
equal(Ember.$('#fu').text(), 'bro'); | ||
|
||
function lookupFactory(fullName) { | ||
equal(fullName, 'view:fu'); | ||
|
||
return FuView; | ||
} | ||
}); |
How about moving it into
Ember.Handlebars.get
so other places using that getter function can benefit as well? This seems to work and passes all the current tests:I excluded the
view.
prefix check, but if it's important obviously keep it.