Skip to content

Instantly share code, notes, and snippets.

@jweaver
Created August 25, 2012 21:43
Show Gist options
  • Save jweaver/3471232 to your computer and use it in GitHub Desktop.
Save jweaver/3471232 to your computer and use it in GitHub Desktop.
Wrapping Repojs as an Angularjs Directive
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;
});
}​
<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>
.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;}​
@jweaver
Copy link
Author

jweaver commented Aug 25, 2012

For the fiddle of what this looks like, see: http://jsfiddle.net/jweaver/HNkPh/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment