Skip to content

Instantly share code, notes, and snippets.

@lamalex
Created May 8, 2013 21:31
Show Gist options
  • Save lamalex/5543831 to your computer and use it in GitHub Desktop.
Save lamalex/5543831 to your computer and use it in GitHub Desktop.
extends layout
block body
div
div(ng-controller="BrassCanklesController")
h2 PAST
div(ng-repeat="video in videos")
| {{video.content}}
div(ng-view)
h2 PRESENT
div(ng-view)
h2 FUTURE
script(src='//cdnjs.cloudflare.com/ajax/libs/jquery/1.8.3/jquery.min.js')
script(src='//cdnjs.cloudflare.com/ajax/libs/underscore.js/1.4.3/underscore-min.js')
script(src='js/lib/angular/angular.js')
script(src='js/app.js')
script(src='js/services.js')
script(src='js/controllers.js')
script(src='js/filters.js')
script(src='js/directives.js')
function BrassCanklesController($scope, $http) {
$scope.videos = [];
$scope.feedUrl = 'http://brasscankles.tumblr.com/rss';
var hostname = (function () {
var a = document.createElement('a');
return function (url) {
a.href = url;
return a.hostname;
}
})();
var parseEntry = function(el) {
var date = el.publishedDate || el.pubDate;
var content = el.content || el.description;
return { title: el.title, content: content, date: date, shortlink: hostname(el.link) };
};
var parseRSS = function(url, callback) {
$.ajax({
url: '//ajax.googleapis.com/ajax/services/feed/load?v=1.0&num=50&callback=?&q=' + encodeURIComponent(url),
dataType: 'json',
success: callback
});
}
parseRSS($scope.feedUrl, function(data) {
if(data == null) {
return;
}
$scope.videos = _.map(data.responseData.feed.entries, function(el) { return parseEntry(el); });
$scope.$apply(function() {
$scope.videos = _.sortBy($scope.videos, function(el) { return el.date; });
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment