Skip to content
This repository has been archived by the owner on May 20, 2022. It is now read-only.

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
akatov committed Nov 11, 2013
0 parents commit 4623f9c
Show file tree
Hide file tree
Showing 6 changed files with 106 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .bowerrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"directory": "bower_components"
}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
bower_components
22 changes: 22 additions & 0 deletions bower.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "ng-layout",
"main": "ng-layout.js",
"version": "0.0.0",
"authors": [
"Dmitri Akatov <akatov@gmail.com>"
],
"description": "simple reusable layouts",
"keywords": [
"layout"
],
"license": "MIT",
"ignore": [
"**/.*",
"node_modules",
"bower_components",
"test"
],
"devDependencies": {
"angular": "~1.2.0"
}
}
43 changes: 43 additions & 0 deletions ng-layout.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
'use strict';

angular.module('ngLayout', [])
.directive('ngLayout', [
'$compile', '$timeout', '$templateCache', '$http',
function ($compile, $timeout, $templateCache, $http) {
var CONTENT_FOR = 'CONTENT_FOR'
var YIELD = 'YIELD'
return {
restrict: 'E',
scope: { src: '=' },
transclude: true,
compile: function(elmt, attr, transclude) {
var element = elmt
return function(scope, element, attrs) {
$http.get(attr.src, {cache: $templateCache}).success(function(html) {
var dom = $compile(html)(scope.$parent)
element.append(dom)
transclude(scope.$parent, function(clone, innerScope) {
var cs = {}
angular.forEach(clone, function(c) {
var e = angular.element(c)
var a = e.attr(CONTENT_FOR)
if (!!a) {
cs[a] = $compile(e)(innerScope)
}
})
angular.forEach(element.find(YIELD), function(e) {
var el = angular.element(e)
var a = el.attr(CONTENT_FOR)
var c = cs[a]
if (!!c) {
el.parent().append(c)
el.remove()
}
})
})
})
}
}
}
}
])
26 changes: 26 additions & 0 deletions test/fixtures/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<html>
<head>
<script type="text/javascript" src="../../bower_components/angular/angular.js"></script>
<script type="text/javascript" src="../../ng-layout.js"></script>
<script type="text/javascript">
angular.module('app', ['ngLayout'])
.controller('Ctrl', ['$scope', function($scope){
$scope.left = "Ying"
$scope.right = "Yang"
}])
</script>
</head>
<body ng-app='app'>
<div ng-controller="Ctrl">
{{ left }}
<ng-layout src="layout.html">
<div content_for="left">
{{ left }}
</div>
<div content_for="right">
{{ right }}
</div>
</ng-layout>
</div>
</body>
</html>
10 changes: 10 additions & 0 deletions test/fixtures/layout.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<table>
<tr>
<td>
<yield content_for="left">
</td>
<td>
<yield content_for="right">
</td>
</tr>
</table>

0 comments on commit 4623f9c

Please sign in to comment.