Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

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

Merged
merged 1 commit into from

2 participants

@pda
pda commented

No description provided.

@benschwarz benschwarz merged commit 0a590dd into benschwarz:master
@benschwarz
Owner

Good stuff mate !
I knew someone'd dive in after some groundwork :beer:

@benschwarz
Owner

(deployed)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
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
6 views/index.haml
@@ -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}
Something went wrong with that request. Please try again.