Permalink
Browse files

Getting it working

  • Loading branch information...
1 parent 04b01a0 commit 8e5072da6c2130de48bb47546f5a1b043e6306fc @ircmaxell committed Feb 2, 2012
Showing with 1,497 additions and 53 deletions.
  1. +1 −0 .gitignore
  2. +6 −0 public/.htaccess
  3. BIN public/assets/icons/stackoverflow.png
  4. BIN public/assets/icons/twitter.png
  5. +43 −0 public/assets/js/Models/Post.js
  6. +37 −0 public/assets/js/Models/Post/StackOverflow.js
  7. +37 −0 public/assets/js/Models/Post/StackOverflowComment.js
  8. +37 −0 public/assets/js/Models/Post/Twitter.js
  9. +31 −0 public/assets/js/Resources/Post.js
  10. +50 −0 public/assets/js/Template.js
  11. +25 −0 public/assets/js/ircmaxell.js
  12. +49 −0 public/assets/js/jquery.tools.js
  13. +564 −0 public/assets/js/mustache.js
  14. +23 −0 public/assets/templates/index.html
  15. +4 −0 public/assets/templates/post.html
  16. +5 −0 public/assets/templates/posts.html
  17. +23 −10 public/index.php
  18. +6 −2 src/bootstrap.php
  19. +25 −0 src/ircmaxell/com/Models/Post.php
  20. +57 −0 src/ircmaxell/com/Models/Post/StackOverflow.php
  21. +53 −0 src/ircmaxell/com/Models/Post/StackOverflowComment.php
  22. +55 −0 src/ircmaxell/com/Models/Post/Twitter.php
  23. +26 −0 src/ircmaxell/com/Models/Source.php
  24. +79 −0 src/ircmaxell/com/Models/Source/StackOverflow.php
  25. +64 −0 src/ircmaxell/com/Models/Source/Twitter.php
  26. +22 −19 src/ircmaxell/com/Request.php
  27. +32 −0 src/ircmaxell/com/Resources/Post.php
  28. +40 −0 src/ircmaxell/com/Resources/Post/Twitter.php
  29. +0 −9 src/ircmaxell/com/Resources/twitter.php
  30. +9 −9 src/ircmaxell/com/Response.php
  31. +5 −4 src/ircmaxell/com/Router.php
  32. +7 −0 src/ircmaxell/com/Sources/Mongo.php
  33. +82 −0 src/ircmaxell/com/Sources/REST.php
View
@@ -0,0 +1 @@
+config
View
@@ -0,0 +1,6 @@
+Options +FollowSymlinks
+RewriteEngine on
+
+RewriteCond %{REQUEST_FILENAME} !-f
+RewriteCond %{REQUEST_FILENAME} !-d
+RewriteRule . /index.php [L]
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -0,0 +1,43 @@
+
+var ircmaxell = ircmaxell || {};
+
+ircmaxell.Models = ircmaxell.Models || {};
+
+(function($, ircmaxell) {
+ var map = function(array, callback) {
+ if (Array.prototype.map) {
+ return array.map(callback);
+ } else {
+ var ret = [];
+ for (var i = 0; i < array.length; i++) {
+ ret.push(callback(array[i]));
+ }
+ return ret;
+ }
+ };
+ ircmaxell.Models.Post = new function() {
+ $.extend(this, {
+ getData: function(post) {
+ return {
+ body: post.getBody(),
+ children: map(post.getChildren(), this.getData),
+ icon: post.getIcon(),
+ summary: post.getSummary(),
+ thumbnail: post.getThumbnail(),
+ title: post.getTitle()
+ };
+ },
+ loadPost: function(data) {
+ if (data.type && data.data && this[data.type]) {
+ return new this[data.type](data.data);
+ }
+ return null;
+ },
+ loadPosts: function(data) {
+ var self = this;
+
+ return map(data, function(post) { return self.loadPost(post); });
+ }
+ });
+ };
+})(jQuery, ircmaxell);
@@ -0,0 +1,37 @@
+
+var ircmaxell = ircmaxell || {};
+
+ircmaxell.Models = ircmaxell.Models || {};
+
+ircmaxell.Models.Post = ircmaxell.Models.Post || {};
+
+(function($, ircmaxell) {
+ ircmaxell.Models.Post.StackOverflow = function(data) {
+ $.extend(this, {
+ getBody: function() {
+ return data.body;
+ },
+ getChildren: function() {
+ return [];
+ },
+ getData: function() {
+ return ircmaxell.Models.Post.getData(this);
+ },
+ getIcon: function() {
+ return 'stackoverflow.png';
+ },
+ getSummary: function() {
+ return data.body;
+ },
+ getThumbnail: function() {
+ return '';
+ },
+ getTitle: function() {
+ return data.title;
+ },
+ hasChildren: function() {
+ return false;
+ }
+ });
+ };
+})(jQuery, ircmaxell);
@@ -0,0 +1,37 @@
+
+var ircmaxell = ircmaxell || {};
+
+ircmaxell.Models = ircmaxell.Models || {};
+
+ircmaxell.Models.Post = ircmaxell.Models.Post || {};
+
+(function($, ircmaxell) {
+ ircmaxell.Models.Post.StackOverflowComment = function(data) {
+ $.extend(this, {
+ getBody: function() {
+ return data.body;
+ },
+ getChildren: function() {
+ return [];
+ },
+ getData: function() {
+ return ircmaxell.Models.Post.getData(this);
+ },
+ getIcon: function() {
+ return 'stackoverflow.png';
+ },
+ getSummary: function() {
+ return data.body;
+ },
+ getThumbnail: function() {
+ return '';
+ },
+ getTitle: function() {
+ return data.body.substr(0, 30);
+ },
+ hasChildren: function() {
+ return false;
+ }
+ });
+ };
+})(jQuery, ircmaxell);
@@ -0,0 +1,37 @@
+
+var ircmaxell = ircmaxell || {};
+
+ircmaxell.Models = ircmaxell.Models || {};
+
+ircmaxell.Models.Post = ircmaxell.Models.Post || {};
+
+(function($, ircmaxell) {
+ ircmaxell.Models.Post.Twitter = function(data) {
+ $.extend(this, {
+ getBody: function() {
+ return data.text;
+ },
+ getChildren: function() {
+ return [];
+ },
+ getData: function() {
+ return ircmaxell.Models.Post.getData(this);
+ },
+ getIcon: function() {
+ return 'twitter.png';
+ },
+ getSummary: function() {
+ return data.text;
+ },
+ getThumbnail: function() {
+ return '';
+ },
+ getTitle: function() {
+ return data.text.substr(0, 30);
+ },
+ hasChildren: function() {
+ return false;
+ }
+ });
+ };
+})(jQuery, ircmaxell);
@@ -0,0 +1,31 @@
+
+var ircmaxell = ircmaxell || {};
+
+ircmaxell.Resources = ircmaxell.Resources || {};
+
+(function($, ircmaxell) {
+
+ ircmaxell.Resources.Post = new function() {
+ var root = '/post/';
+ $.extend(this, {
+ loadPost: function(type, id, callback) {
+ var uri = root + type + '/' + id;
+ $.get(uri, function(data) {
+ callback(ircmaxell.Models.Post.loadPost(data));
+ }, 'json');
+ },
+ loadPosts: function(type, callback) {
+ var uri = root;
+ if (typeof type !== 'function') {
+ uri += type;
+ } else {
+ callback = type;
+ }
+ $.get(uri, function(data) {
+ callback(ircmaxell.Models.Post.loadPosts(data));
+ }, 'json');
+ }
+ });
+ }
+
+})(jQuery, ircmaxell);
@@ -0,0 +1,50 @@
+
+var ircmaxell = ircmaxell || {};
+
+(function($, ircmaxell) {
+ var templateCache = {};
+
+ var templateCallbacks = {};
+
+ ircmaxell.Template = function(file, onReady) {
+ var tmpl = this;
+ if (!templateCache[file]) {
+ templateCallbacks[file] = $.Callbacks();
+ /**
+ * Start the template fetch now
+ */
+ $.get(file, function(data) {
+ templateCache[file] = data;
+ templateCallbacks[file].fire(data);
+ if (onReady) {
+ onReady(tmpl);
+ }
+ }, 'html');
+ } else {
+ if (onReady) {
+ onReady(tmpl);
+ }
+ }
+ $.extend(this, {
+ render: function(target, data, partials) {
+ this.renderToString(data, partials, function(html) {
+ $(target).html(html);
+ });
+ },
+ renderToString: function(data, partials, callback) {
+ var value = '';
+ if (templateCache[file]) {
+ value = $.mustache(templateCache[file], data, partials);
+ if (callback) {
+ callback(value);
+ }
+ } else {
+ templateCallbacks[file].add(function(template) {
+ callback.html($.mustache(template, data, partials));
+ })
+ }
+ return value;
+ }
+ });
+ }
+})(jQuery, ircmaxell);
@@ -0,0 +1,25 @@
+
+var ircmaxell = (function($) {
+ var ircmaxell = new function() {
+
+ $.extend(this, {
+
+ });
+ };
+
+
+ $(function() {
+ var template = new ircmaxell.Template('/assets/templates/posts.html');
+ ircmaxell.Resources.Post.loadPosts(function(posts) {
+ new ircmaxell.Template('/assets/templates/post.html', function(postTemplate) {
+ var data = posts.map(function(post) {
+ return postTemplate.renderToString(post.getData());
+ });
+ template.render('body', {posts: data});
+ });
+
+ });
+ });
+
+ return ircmaxell;
+})(jQuery);
Oops, something went wrong.

0 comments on commit 8e5072d

Please sign in to comment.