Created
August 25, 2012 21:43
-
-
Save jweaver/3471232 to your computer and use it in GitHub Desktop.
Wrapping Repojs as an Angularjs Directive
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
var myApp = angular.module('myApp', []); | |
myApp.directive('repository', function() { | |
return { | |
restrict: 'C', | |
scope: { | |
owner: '@repoOwner', | |
name: '@repoName' | |
}, | |
link: function(scope, element, attrs, controller) { | |
//attach to 'repoOwner' due to ordering of attributes in element. TODO: Is there a better way? | |
attrs.$observe('repoOwner', function(value) { | |
element.repo({ | |
user: scope.owner, | |
name: scope.name | |
}); | |
}); | |
} | |
}; | |
}) | |
//Replace 'jweaver' with the github username you wish to use | |
function GithubController($scope, $http) { | |
$http.get('https://api.github.com/users/jweaver/repos').success(function(data) { | |
$scope.repos = data; | |
}); | |
} |
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
<html xmlns="http://www.w3.org/1999/xhtml" ng-app="myApp"> | |
<head> | |
<!-- Note library names. Angular is Angular.js (http://www.angularjs.org/). Repo is Repo.js (http://darcyclarke.me/dev/repojs/) --> | |
<link rel="stylesheet" type="text/css" href="styles.css" /> | |
<script type="text/javascript" src="lib/jquery-1.7.2.js"></script> | |
<script type="text/javascript" src="lib/repo.min.js"></script> | |
<script type="text/javascript" src="lib/angular-1.0.1.js"></script> | |
<script type="text/javascript" src="js/app.js"></script> | |
</head> | |
<body> | |
<div ng-app="myApp" ng:controller="GithubController"> | |
<div ng-repeat="repo in repos" class="repository" | |
id="{{repo.name}}" repo-name="{{repo.name}}" repo-owner="{{repo.owner.login}}"> | |
</div> | |
</div> | |
</body> | |
</html> |
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
.strong { background-color: #060; border-color: #0F0;} | |
.medium { background-color: #C60; border-color: #FC0;} | |
.weak { background-color: #900; border-color: #F00;} | |
.strength { padding: 1px 10px; border: 2px solid; color: #FFF;} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For the fiddle of what this looks like, see: http://jsfiddle.net/jweaver/HNkPh/