Permalink
Browse files

Correctly displaying one blog post from Blogger on the :thoughts page.

Next: get all of them loaded in, and put this on Heroku.
  • Loading branch information...
1 parent 942ef43 commit 692d314ce989256977462899a29603f8be3e44fb @chadoh committed Apr 26, 2010
Showing with 50 additions and 12 deletions.
  1. +26 −1 controls.rb
  2. +16 −0 views/styles.sass
  3. +8 −11 views/thoughts.haml
View
@@ -6,6 +6,16 @@
require 'crack'
require 'open-uri'
+#Extend Hash class so that keys can be accessed as attributes, with dot notation.
+#Courtesy of http://www.goodercode.com/wp/convert-your-hash-keys-to-object-properties-in-ruby/
+class ::Hash
+ def method_missing(name)
+ return self[name] if key? name
+ self.each { |k,v| return v if k.to_s.to_sym == name }
+ super.method_missing name
+ end
+end
+
set :sass, { :style => :compact }
set :haml, { :ugly => true }
@@ -30,6 +40,18 @@ def current_tab_if(route)
end
flag
end
+
+ #Helper to turn date returned from blogger into a ruby date. Assumes Eastern Standard Time (New York)
+ #Assumes format like this: 2009-11-16T23:28:00.000-05:00
+ #
+ #It would be nice to generalize this to deal with any iso formatted string,
+ #make it extend the Time class,
+ #and turn it into a gem.
+ def time_from_iso_format_str(iso_8601_string)
+ iso_8601_string [/(\d+)-(\d+)-(\d+)T(\d+):(\d+):(\d+)/];
+ y=$1;mon=$2;d=$3;h=$4;min=$5;s=$6
+ Time.local(y,mon,d,h,min,s)
+ end
end
get "/" do
@@ -38,9 +60,12 @@ def current_tab_if(route)
#loads in blogger feed
get "/thoughts" do
+ #for testing in irb:
+ #require 'open-uri'; require 'crack'; url = 'http://www.blogger.com/feeds/9096209599953091034/posts/default';xml = open(url).read;feed = Crack::XML.parse(xml).feed;posts = feed.entry;
url = 'http://www.blogger.com/feeds/9096209599953091034/posts/default'
xml = open(url).read
- @feed = Crack::XML.parse(xml)
+ feed = Crack::XML.parse(xml).feed
+ @posts = feed.entry
haml :thoughts
end
View
@@ -128,6 +128,20 @@ p
width: 660px
h2
display: none
+ h2.date-header
+ display: block
+ color: #999
+ font: normal 78%/1.4em 'Trebuchet MS', Trebuchet, Arial, Verdana, sans-serif
+ letter-spacing: 0.2em
+ text-transform: uppercase
+ h3.post-title
+ display: block
+ color:#c60
+ font-size: 140%
+ font-weight: normal
+ line-height: 1.4em
+ margin: 0.25em 0 0
+ padding: 0 0 4px
h1
display: block
+sans-heading-font
@@ -147,6 +161,8 @@ p
img
border: 1px solid #ddd
padding: 4px
+ div.blogger-post-footer
+ display: none
.post-title
color: #c60
View
@@ -1,11 +1,8 @@
-%h2 Thoughts
-:markdown
- So I want to [embed a wave](http://code.google.com/apis/wave/embed/guide.html) in this here page.
-
- Doesn't seem very complicated, I agree. But! I need scripts on _this_ page that the other pages on the site don't have. These need to go in the <head>. But I insist that I shall only have one layout. And I don't want to clutter it up with logic.
-
- At this point I'm thinking the best way to do this would be with helper functions? I'll create separate branches for each approach.
-
-%hr
-
-%p Test to check if the feed was gotten properly: #{@feed['feed']['title']}
+-t = time_from_iso_format_str(@posts[1]['published'])
+%h2.date-header= t.strftime('%A, %B %d, %Y')
+.post
+ %h3.post-title= @posts[1].title
+ .post-body
+ %div
+ %div(style="clear:both;")
+ %p= @posts[1].content

0 comments on commit 692d314

Please sign in to comment.