Permalink
Browse files

Created Github related publishing rake tasks

  • Loading branch information...
1 parent 1be9ed5 commit 7cd5046f7a3e7b3631c68a19ade079d5bf03c8ea @mikedamage mikedamage committed Jan 24, 2009
Showing with 72 additions and 3 deletions.
  1. +1 −1 Sitefile
  2. +24 −2 content/blog/2009/01/22/jsonp-awesomeness.txt
  3. +35 −0 tasks/git.rake
  4. +12 −0 tasks/sync_local.rake
View
2 Sitefile
@@ -2,6 +2,6 @@
task :default => :build
desc 'deploy the site to the webserver'
-task :deploy => [:build, 'deploy:rsync']
+task :deploy => [:build, 'git:publish']
# EOF
View
26 content/blog/2009/01/22/jsonp-awesomeness.txt
@@ -21,11 +21,33 @@ So how can I put up-to-the-minute, dynamic feeds into a static HTML file? Some k
I finally remembered glossing over a little blurb about cross domain JSON requests when I was reading the "jQuery":http://www.jquery.com documentation a while ago. Turns out I can access JSON data from my web service of choice if I put the request into a script tag and specify a callback function on my page to munge the resulting output. Even better, jQuery completely automates this whole process so I don't have to bother with DOM scripting to insert a @script@ tag. Cheggit out:
-<script src="http://gist.github.com/50890.js" type="text/javascript"></script>
+"get this gist":http://gist.github.com/50890
+<!-- <script src="http://gist.github.com/50890.js" type="text/javascript"></script> -->
+<% uv(:lang => 'javascript', :theme => 'sunburst', :line_numbers => true) do -%>
+$.ajax({
+ dataType: 'jsonp',
+ data: { count: 3, callback: 'twitterFeed' },
+ url: 'http://twitter.com/statuses/user_timeline/mikedamage.json',
+ jsonp: 'twitterFeed'
+});
+<% end -%>
Deceptively simple, this bit of Javascript automatically inserts a new @script@ tag when the page loads, then uses the specified callback to process the JSON object returned. You'll notice that I specified the same callback in a couple places. It's kind of confusing, but I can't get it to work any other way. You need to pass the callback function name to the web service so that the object it returns includes a call to that function. This snippet assumes that you've already defined a function called @twitterFeed@ to process the JSON output. If you look in this page's source code, you'll see mine:
-<script src="http://gist.github.com/50897.js"></script>
+"get this gist":http://gist.github.com/50897
+<!-- <script src="http://gist.github.com/50897.js"></script> -->
+<% uv(:lang => 'javascript', :theme => 'sunburst', :line_numbers => true) do -%>
+function twitterFeed(feed) {
+ for (var i=0; i<feed.length; i++) {
+ $('#twitter-status ul').append('<li class="tweet">'
+ + feed[i].text
+ + '<br/><em>'
+ + jQuery.timeago(parseDate(feed[i].created_at))
+ + '</em>'
+ + '</li>');
+ }
+}
+<% end -%>
There's a little bit of jQuery magic going on around where it says @parseDate(...@, but I'm saving that for another blog post where I'll extoll the virtues of the "jQuery Time Ago":http://timeago.yarp.com/ plugin. Basically @twitterFeed@ takes a JSON array, iterates through its contents and injects HTML into an existing @ul@ element in the sidebar.
View
35 tasks/git.rake
@@ -0,0 +1,35 @@
+namespace :git do
+ require 'git'
+
+ desc "commits changes into local dev repository"
+ task :commit do
+ repo = Git.open(Dir.pwd)
+ repo.chdir do
+ repo.add
+ print "Commit Message: "
+ msg = $stdin.gets.chomp
+ repo.commit(msg)
+ end
+ end
+
+ desc "pushes to remote dev repository"
+ task :push => [:commit] do
+ repo = Git.open(Dir.pwd)
+ repo.chdir do
+ repo.push('origin', 'master')
+ end
+ end
+
+ desc "pushes local output repo to Github Pages"
+ task :publish => ['sync:local'] do
+ repo = Git.open('/Users/mike/Development/mikedamage.github.com')
+ repo.chdir do
+ repo.add
+ print "Commit Message: "
+ msg = $stdin.gets.chomp
+ repo.commit(msg)
+ repo.push('origin', 'master')
+ end
+ end
+
+end
View
12 tasks/sync_local.rake
@@ -0,0 +1,12 @@
+namespace :sync do
+
+ desc "syncs this site's output dir with another local dir"
+ task :local do
+ rsync = %x(which rsync).chomp
+ output_dir = SITE.output_dir
+ sync_dir = '/Users/mike/Development/mikedamage.github.com'
+ cmd = "#{rsync} -avr #{output_dir}/ #{sync_dir}/"
+ %x(#{cmd})
+ end
+
+end

0 comments on commit 7cd5046

Please sign in to comment.