Permalink
Browse files

The plumbing is hooked up! There are a many tweaks I can think of to …

…tackle next:

Add posted time at bottom of each post
Add link to actual blog in side bar
Show labels
Show number of comments (slide-toggle them when clicked)
Add favicon
Add pagination (without and then with ajax calls)

But let's not get ahead of ourselves--that contact form still isn't functional.
  • Loading branch information...
1 parent 692d314 commit fab89191da624da335f9d345da77e941e1414852 @chadoh committed Apr 29, 2010
Showing with 47 additions and 21 deletions.
  1. +1 −0 .gitignore
  2. +16 −13 controls.rb
  3. +20 −0 partials.rb
  4. +9 −0 views/_post.haml
  5. +1 −8 views/thoughts.haml
View
@@ -1,2 +1,3 @@
# Ignore temporary files
+.*.sw*
*~
View
@@ -5,16 +5,7 @@
require 'pony'
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
+require 'partials'
set :sass, { :style => :compact }
set :haml, { :ugly => true }
@@ -25,6 +16,8 @@ def method_missing(name)
end
helpers do
+ include Sinatra::Partials
+
#Helper function to add class="current" to the active tab
#Allows passing in either a simple string with the route name
#to flag on,
@@ -44,14 +37,24 @@ def current_tab_if(route)
#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,
+ #TODO: 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
+
+ #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
end
get "/" do
@@ -62,11 +65,11 @@ def time_from_iso_format_str(iso_8601_string)
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'
+ url = 'http://www.blogger.com/feeds/9096209599953091034/posts/default?max-results=11'
xml = open(url).read
feed = Crack::XML.parse(xml).feed
@posts = feed.entry
-
+
haml :thoughts
end
View
@@ -0,0 +1,20 @@
+# stolen from http://github.com/cschneid/irclogger/blob/master/lib/partials.rb
+# and made a lot more robust by me
+# this implementation uses erb by default. if you want to use any other template mechanism
+# then replace `erb` on line 13 and line 17 with `haml` or whatever
+module Sinatra::Partials
+ def partial(template, *args)
+ template_array = template.to_s.split('/')
+ template = template_array[0..-2].join('/') + "/_#{template_array[-1]}"
+ options = args.last.is_a?(Hash) ? args.pop : {}
+ options.merge!(:layout => false)
+ if collection = options.delete(:collection) then
+ collection.inject([]) do |buffer, member|
+ buffer << haml(:"#{template}", options.merge(:layout =>
+ false, :locals => {template_array[-1].to_sym => member}))
+ end.join("\n")
+ else
+ haml(:"#{template}", options)
+ end
+ end
+end
View
@@ -0,0 +1,9 @@
+-if post['published'] != "2009-11-17T19:01:00.001-05:00"
+ -t = time_from_iso_format_str(post['published'])
+ %h2.date-header= t.strftime('%A, %B %d, %Y')
+ .post
+ %h3.post-title= post.title
+ .post-body
+ %div
+ %div(style="clear:both;")
+ %p= post.content
View
@@ -1,8 +1 @@
--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
+= partial(:post, :collection => @posts)

0 comments on commit fab8919

Please sign in to comment.