Skip to content

Commit

Permalink
I heard you like title attributes, so I put more code in your code.
Browse files Browse the repository at this point in the history
  • Loading branch information
pda committed Jan 5, 2012
1 parent 797d8b8 commit 27d58ed
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
23 changes: 21 additions & 2 deletions app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 2 additions & 4 deletions views/index.haml
Original file line number Diff line number Diff line change
Expand Up @@ -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.