Permalink
Browse files

I heard you like title attributes, so I put more code in your code.

  • Loading branch information...
1 parent 797d8b8 commit 27d58ed70fdf30767b399cd05523fce28ecf3499 @pda pda committed Jan 5, 2012
Showing with 23 additions and 6 deletions.
  1. +21 −2 app.rb
  2. +2 −4 views/index.haml
View
23 app.rb
@@ -7,7 +7,26 @@
require 'sinatra/reloader' if development?
get '/' do
- @attendees = CSV.read("rcx.csv")[1..-2].map{|a| a[2][1..-1] if a[2] }
+ @attendees = AttendeeList.new("rcx.csv").with_twitter
haml :index
-end
+end
+
+# Sinatra::Reloader can't reload Struct subclasses :(
+if defined?(AttendeeList)
+ [ :AttendeeList, :Attendee ].each { |c| Object.send(:remove_const, c) }
+end
+
+class AttendeeList < Struct.new(:path)
+ def all; CSV.read(path)[1..-1].map { |row| Attendee.new(*row) } end
+ def with_twitter; all.select(&:twitter?) end
+end
+
+class Attendee < Struct.new(:first_name, :last_name, :twitter)
+ def full_name; [ first_name, last_name ].compact.join(" ") end
+ def twitter?; !twitter.nil? && twitter.length > 0 end
+ def username; twitter[1..-1] end
+ def url; "https://twitter.com/#{username}" end
+ def image_url; "http://img.tweetimag.es/i/#{username}_b" end
+ def description; "#{full_name} (#{twitter})" end
+end
View
@@ -8,7 +8,5 @@
%body
- for attendee in @attendees
%article
- - if attendee
- %a{href: "http://twitter.com/#{attendee}", rel: 'external'}
- %img{alt: attendee, src: "http://img.tweetimag.es/i/#{attendee}_b"}
-
+ %a{href: attendee.url, title: attendee.description, rel: 'external'}
+ %img{alt: attendee.description, src: attendee.image_url, height: 73, width: 73}

0 comments on commit 27d58ed

Please sign in to comment.