Skip to content
This repository
Browse code

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

  • Loading branch information...
commit 8bcbd738f25be7bccfeb0ad51283570cec2554be 1 parent 1fa5f0a
Tim Branyen authored

Showing 2 changed files with 27 additions and 11 deletions. Show diff stats Hide diff stats

  1. +8 11 backbone.layoutmanager.js
  2. +19 0 test/views.js
19 backbone.layoutmanager.js
@@ -30,9 +30,6 @@ var LayoutManager = Backbone.View.extend({
30 30
31 31 // Have Backbone set up the rest of this View.
32 32 Backbone.View.call(this, options);
33   -
34   - // Set the prefix.
35   - this.__manager__.prefix = this._options().paths.layout || "";
36 33 },
37 34
38 35 // Swap the current layout to new layout.
@@ -171,11 +168,6 @@ var LayoutManager = Backbone.View.extend({
171 168 return viewDeferred.promise();
172 169 };
173 170
174   - // Set the prefix for a layout.
175   - if (!view.__manager__.prefix && options.paths) {
176   - view.__manager__.prefix = options.paths.template || "";
177   - }
178   -
179 171 // Add reference to the parentView.
180 172 view.__manager__.parent = this;
181 173 // Add reference to the placement selector used.
@@ -521,6 +513,14 @@ var LayoutManager = Backbone.View.extend({
521 513 _removeView: LayoutManager._removeView
522 514 });
523 515
  516 + // Set the prefix for a layout.
  517 + if (view instanceof Backbone.Layout) {
  518 + view.__manager__.prefix = view._options().paths.layout || "";
  519 + // Set the prefix for a template.
  520 + } else {
  521 + view.__manager__.prefix = view._options().paths.template || "";
  522 + }
  523 +
524 524 // Extend the options with the prototype and passed options.
525 525 options = view.options = _.defaults(options || {}, view.options,
526 526 proto.options);
@@ -603,9 +603,6 @@ var LayoutManager = Backbone.View.extend({
603 603 view.remove = proto.remove;
604 604 }
605 605
606   - // Default the prefix to an empty string.
607   - view.__manager__.prefix = "";
608   -
609 606 // Normalize views to exist on either instance or options, default to
610 607 // options.
611 608 views = options.views || view.views;
19 test/views.js
@@ -1031,3 +1031,22 @@ test("Ensure events are copied over properly", 1, function() {
1031 1031
1032 1032 ok(hit, "Events were bound and triggered correctly");
1033 1033 });
  1034 +
  1035 +// https://github.com/tbranyen/backbone.layoutmanager/issues/131
  1036 +test("Ensure global paths are adhered to", 1, function() {
  1037 + Backbone.LayoutManager.configure({
  1038 + paths: {
  1039 + template: "test/"
  1040 + }
  1041 + });
  1042 +
  1043 + var t = new Backbone.LayoutView({
  1044 + template: "here"
  1045 + });
  1046 +
  1047 + equal(t.__manager__.prefix, "test/", "Prefix properly hooked up");
  1048 +
  1049 + Backbone.LayoutManager.configure({
  1050 + paths: {}
  1051 + });
  1052 +});

0 comments on commit 8bcbd73

Please sign in to comment.
Something went wrong with that request. Please try again.