From 98d7029fd0744300c47f2483b792bff8d7d74736 Mon Sep 17 00:00:00 2001 From: Daniel Huckstep Date: Thu, 31 Dec 2009 16:17:52 -0700 Subject: [PATCH] Show tweet text as the rollover hint on links that go to a status --- .gems | 3 ++- darkblog.rb | 7 +++++++ lib/blog_helper.rb | 5 +++++ public/javascripts/jquery.darkhax.js | 12 ++++++++++++ 4 files changed, 26 insertions(+), 1 deletion(-) diff --git a/.gems b/.gems index abef99b..4998ddc 100644 --- a/.gems +++ b/.gems @@ -14,4 +14,5 @@ newrelic_rpm texticle term_extraction addressable -darkhelmet-sanitize \ No newline at end of file +darkhelmet-sanitize +hashie \ No newline at end of file diff --git a/darkblog.rb b/darkblog.rb index 03106ac..4ffd4a2 100755 --- a/darkblog.rb +++ b/darkblog.rb @@ -80,6 +80,7 @@ named_routes[:redirections] = '/redirections' named_routes[:announce] = '/announce' named_routes[:admin_index] = '/index' +named_routes[:twitter] = '/twitter/:status' # main index with pagination named_route(:get, :index) do |page| @@ -288,4 +289,10 @@ @posts = Post.published.ptitle(title) not_found if @posts.empty? redirect(@posts.first.permalink, 301) +end + +# get twitter statuses +named_route(:post, :twitter) do |status_id| + content_type('text/plain') + individual_tweet(status_id).text end \ No newline at end of file diff --git a/lib/blog_helper.rb b/lib/blog_helper.rb index 70a61f7..9348713 100644 --- a/lib/blog_helper.rb +++ b/lib/blog_helper.rb @@ -37,6 +37,7 @@ require 'texticle' require 'term_extraction' require 'sanitize' +require 'hashie' class String def url_encode @@ -258,6 +259,10 @@ def announce RestClient.get('http://pingomatic.com/ping/?title=verbose+logging&blogurl=http%3A%2F%2Fblog.darkhax.com%2F&rssurl=http%3A%2F%2Fblog.darkhax.com%2Ffeed&chk_weblogscom=on&chk_blogs=on&chk_technorati=on&chk_feedburner=on&chk_syndic8=on&chk_newsgator=on&chk_myyahoo=on&chk_pubsubcom=on&chk_blogdigger=on&chk_blogrolling=on&chk_blogstreet=on&chk_moreover=on&chk_weblogalot=on&chk_icerocket=on&chk_newsisfree=on&chk_topicexchange=on&chk_google=on&chk_tailrank=on&chk_bloglines=on&chk_postrank=on&chk_skygrid=on&chk_collecta=on') RestClient.get('http://feedburner.google.com/fb/a/pingSubmit?bloglink=http://blog.darkhax.com/') end + + def individual_tweet(id) + Hashie::Mash.new(Crack::JSON.parse(RestClient.get("http://twitter.com/statuses/show/#{id}.json"))) + end end module Caching diff --git a/public/javascripts/jquery.darkhax.js b/public/javascripts/jquery.darkhax.js index dff376d..d6181da 100644 --- a/public/javascripts/jquery.darkhax.js +++ b/public/javascripts/jquery.darkhax.js @@ -46,4 +46,16 @@ $(document).ready(function() { return 'url' + index + '=' + encodeURIComponent(a.href); }).join('&'); $.getScript('http://disqus.com/forums/verboselogging/get_num_replies.js?' + query); + + $('#posts-container a').each(function() { + var re = /http:\/\/twitter\.com\/\w+\/status\/(\d+)/; + var matches = re.exec($(this).attr('href')); + if (null != matches && 1 < matches.length) { + var id = matches[1]; + var link = this; + $.post('/twitter/' + id, null, function(data) { + $(link).attr('title', data); + }, 'text'); + } + }); }); \ No newline at end of file