(function() {
  var module = angular.module('multi-transclude', []);

  var Ctrl = ['$scope', '$element', '$transclude', function($scope, $element, $transclude){
    // Ensure we're transcluding or nothing will work.
    if(!$transclude) {
      throw new Error(
        'Illegal use of ngMultiTransclude controller. No directive ' +
        'that requires a transclusion found.'
      );
    }

    var toTransclude;

    $scope.$on('$destroy', function() {
      if(toTransclude) {
        toTransclude.remove();
        toTransclude = null;
      }
    });

    // Transclude content that matches name into element.
    this.transclude = function(name, element) {
      for(var i = 0; i < toTransclude.length; ++i) {
        // Uses the argument as the `name` attribute directly, but we could
        // evaluate it or interpolate it or whatever.
        var el = angular.element(toTransclude[i]);
        if(el.attr('name') === name) {
          element.append(el);
          return;
        }
      }
    };

    // There's not a good way to ask Angular to give you the closest
    // controller from a list of controllers, we we get all multi-transclude
    // controllers and select the one that is the child of the other.
    this.$element = $element;
    this.isChildOf = function(otherCtrl){
      return otherCtrl.$element[0].contains(this.$element[0]);
    };

    // get content to transclude
    $transclude(function(clone) {
      toTransclude = clone;
    });
  }];

  module.directive('ngMultiTemplate', function() {
    return {
      transclude: true,
      templateUrl: function(element, attrs) {
        return attrs.ngMultiTemplate;
      },
      controller: Ctrl
    };
  });

  module.directive('ngMultiTranscludeController', function() {
    return {
      controller: Ctrl
    };
  });

  module.directive('ngMultiTransclude', function() {
    return {
      require: ['?^ngMultiTranscludeController', '?^ngMultiTemplate'],
      link: function(scope, element, attrs, ctrls) {
        // Find the deepest controller (closes to this element).
        var ctrl1 = ctrls[0];
        var ctrl2 = ctrls[1];
        var ctrl;
        if(ctrl1 && ctrl2){
          ctrl = ctrl1.isChildOf(ctrl2) ? ctrl1 : ctrl2
        }
        else {
          ctrl = ctrl1 || ctrl2;
        }

        // A multi-transclude parent directive must be present.
        if(!ctrl) {
          throw new Error('Illegal use of ngMultiTransclude. No wrapping controller.')
        }

        // Receive transcluded content.
        ctrl.transclude(attrs.ngMultiTransclude, element);
      }
    };
  });
})();

@@ -1,24 +1,23 @@
 (function()
- 
 %7B%0A  var modu
@@ -221,33 +221,32 @@
 if(!$transclude)
- 
 %7B%0A      throw ne
@@ -443,25 +443,24 @@
 , function()
- 
 %7B%0A      if(t
@@ -471,17 +471,16 @@
 nsclude)
- 
 %7B%0A      
@@ -653,17 +653,16 @@
 element)
- 
 %7B%0A      
@@ -705,17 +705,16 @@
 th; ++i)
- 
 %7B%0A      
@@ -924,17 +924,16 @@
 == name)
- 
 %7B%0A      
@@ -1118,19 +1118,16 @@
 ers, we 
-we 
 get all 
@@ -1420,17 +1420,16 @@
 n(clone)
- 
 %7B%0A      
@@ -1505,33 +1505,32 @@
 ate', function()
- 
 %7B%0A    return %7B%0A 
@@ -1595,17 +1595,16 @@
 , attrs)
- 
 %7B%0A      
@@ -1733,33 +1733,32 @@
 ler', function()
- 
 %7B%0A    return %7B%0A 
@@ -1843,17 +1843,16 @@
 nction()
- 
 %7B%0A    re
@@ -1979,17 +1979,16 @@
 , ctrls)
- 
 %7B%0A      
@@ -2207,16 +2207,17 @@
  : ctrl2
+;
 %0A       
@@ -2359,17 +2359,16 @@
 f(!ctrl)
- 
 %7B%0A      

Fix mismatching brace spacing style; fix comment typo.