Browse files

fixed the way prefixes are set to be more consistent, Closes GH-131

  • Loading branch information...
1 parent 1fa5f0a commit 8bcbd738f25be7bccfeb0ad51283570cec2554be @tbranyen committed Aug 15, 2012
Showing with 27 additions and 11 deletions.
  1. +8 −11 backbone.layoutmanager.js
  2. +19 −0 test/views.js
View
19 backbone.layoutmanager.js
@@ -30,9 +30,6 @@ var LayoutManager = Backbone.View.extend({
// Have Backbone set up the rest of this View.
Backbone.View.call(this, options);
-
- // Set the prefix.
- this.__manager__.prefix = this._options().paths.layout || "";
},
// Swap the current layout to new layout.
@@ -171,11 +168,6 @@ var LayoutManager = Backbone.View.extend({
return viewDeferred.promise();
};
- // Set the prefix for a layout.
- if (!view.__manager__.prefix && options.paths) {
- view.__manager__.prefix = options.paths.template || "";
- }
-
// Add reference to the parentView.
view.__manager__.parent = this;
// Add reference to the placement selector used.
@@ -521,6 +513,14 @@ var LayoutManager = Backbone.View.extend({
_removeView: LayoutManager._removeView
});
+ // Set the prefix for a layout.
+ if (view instanceof Backbone.Layout) {
+ view.__manager__.prefix = view._options().paths.layout || "";
+ // Set the prefix for a template.
+ } else {
+ view.__manager__.prefix = view._options().paths.template || "";
+ }
+
// Extend the options with the prototype and passed options.
options = view.options = _.defaults(options || {}, view.options,
proto.options);
@@ -603,9 +603,6 @@ var LayoutManager = Backbone.View.extend({
view.remove = proto.remove;
}
- // Default the prefix to an empty string.
- view.__manager__.prefix = "";
-
// Normalize views to exist on either instance or options, default to
// options.
views = options.views || view.views;
View
19 test/views.js
@@ -1031,3 +1031,22 @@ test("Ensure events are copied over properly", 1, function() {
ok(hit, "Events were bound and triggered correctly");
});
+
+// https://github.com/tbranyen/backbone.layoutmanager/issues/131
+test("Ensure global paths are adhered to", 1, function() {
+ Backbone.LayoutManager.configure({
+ paths: {
+ template: "test/"
+ }
+ });
+
+ var t = new Backbone.LayoutView({
+ template: "here"
+ });
+
+ equal(t.__manager__.prefix, "test/", "Prefix properly hooked up");
+
+ Backbone.LayoutManager.configure({
+ paths: {}
+ });
+});

0 comments on commit 8bcbd73

Please sign in to comment.