Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
2ea5da5
Fixed first test for "no profile"
mkopala Jan 17, 2011
6423bed
Second test passing for "With a profile, user and photo requesting a …
mkopala Jan 17, 2011
ba0ae5e
Third test passing "With a profile, user and photo not requesting a l…
mkopala Jan 17, 2011
865f56f
Fouth test passing: "With a profile and user without a photo and the …
mkopala Jan 17, 2011
47e10b6
Fifth test passing: "With a profile and user without a photo and the …
mkopala Jan 17, 2011
a245512
Two more tests passing for 'NO DEFAULT' case
mkopala Jan 17, 2011
0553afc
Final test passing: "With a profile, no user, but requesting a link"
mkopala Jan 17, 2011
6d9d405
Refactor 'display_photo' code to make it simpler & more readable
mkopala Jan 17, 2011
09579b9
Add tests for display_X_photo methods, where X = small, medium, large…
mkopala Jan 17, 2011
28dfe12
Remove the individual display_X_photo methods and declare them using …
mkopala Jan 17, 2011
173cdb4
Removed 'profile.rb' - wasn't being used
mkopala Jan 17, 2011
51bc597
Added missing profile_path method and put in FIXME; missing test to d…
mkopala Jan 17, 2011
816c334
Added 'rails-commits.rb' script for Github challenge
mkopala Jan 17, 2011
4f0b5d5
Added resume in PDF format to 'resume' directory
mkopala Jan 17, 2011
c995b0d
Added a PHP version of the Github script as well
mkopala Jan 17, 2011
4361446
Added a README file for the github challenge directory
mkopala Jan 17, 2011
4750faa
Minor tweaks to the describe strings in 'helper_spec.rb'
mkopala Jan 17, 2011
cec360e
Add four extra tests for the display_X_photo methods, for the 'rep' u…
mkopala Jan 17, 2011
c43ca35
Removed unnecessary 'require' statements from 'helper_spec.rb'
mkopala Jan 17, 2011
db8f03e
Replaced object creation in tests with fixtures using Factory_girl
mkopala Jan 17, 2011
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions github-challenge/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
This directory contains script for fetching the most recent Ruby on Rails commits from Github.

Ruby:

Usage: ruby rails-commits.rb
Prerequisites:
- gem install json

PHP:

Usage: php rails-commits.php
Prerequisites:
- json extension installed & enabled
- short tags enabled

18 changes: 18 additions & 0 deletions github-challenge/rails-commits.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php
$url = "http://github.com/api/v2/json/commits/list/rails/rails/master";
$json = json_decode(file_get_contents($url));
$data = array();
foreach ($json->commits as $commit) {
$data[$commit->author->email][] = $commit;
}
ksort($data);
?>
<? foreach ($data as $email => $commits): ?>
<h1><?= $commits[0]->author->name . " (" . $email . ")"?></h1>
<ul>
<? foreach ($commits as $commit): ?>
<li><tt><?= $commit->id ?></tt><br/><?= $commit->message ?></li>
<? endforeach ?>
</ul>
</pre>
<? endforeach ?>
24 changes: 24 additions & 0 deletions github-challenge/rails-commits.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
require 'net/http'
require 'uri'
require 'rubygems'
require 'json'
require 'erb'

# REST URI for Ruby on Rails Github repository most recent commits
url = "http://github.com/api/v2/json/commits/list/rails/rails/master";

# Get the commits from the URL using JSON and group them by author
data = JSON.parse(Net::HTTP.get(URI.parse(url)))['commits'].group_by { |commit| commit['author'] }

# Print the HTML using the embedded ERB template
puts ERB.new(DATA.read).result(binding)

__END__
<% data.each do |author, commits| %>
<h1><%= author['name']%> (<%= author['email'] %>)</h1>
<ul>
<% commits.each do |commit| %>
<li><%= commit['id'] %><br/><%= commit['message'] %></li>
<% end %>
</ul>
<% end %>
4 changes: 4 additions & 0 deletions refactor-this/factories.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
u.email Factory.next(:email)
end

Factory.define(:user_profile) do |p|
p.name "Clayton"
end

Factory.define(:photo) do |p|

end
85 changes: 29 additions & 56 deletions refactor-this/helper.rb
Original file line number Diff line number Diff line change
@@ -1,67 +1,40 @@
class Helper
def self.foo
"foo"
end

def image_size(profile, non_rep_size)
if profile.user.rep?
'190x114'
else
non_rep_size

def profile_path(profile)
# FIXME: figure what this should actually be
"/path/to/profiles/#{profile.name}"
end

# Define methods for display_X_photo, where X can be small, medium, large, or huge
{:small => '32x32', :medium => '48x48', :large => '64x64', :huge => '200x200'}.each do |name, size|
send :define_method, "display_#{name}_photo" do |*args|
profile = args[0]
size = '190x119' if profile.user && profile.user.rep?
args = [profile, size, args[1], args[2]]
args << true if /large|huge/.match(name.to_s)
display_photo(*args)
end
end

def display_small_photo(profile, html = {}, options = {})
display_photo(profile, image_size(profile, "32x32"), html, options)
end

def display_medium_photo(profile, html = {}, options = {})
display_photo(profile, image_size(profile, "48x48"), html, options)
end

def display_large_photo(profile, html = {}, options = {}, link = true)
display_photo(profile, image_size(profile, "64x64"), html, options, link)
end

def display_huge_photo(profile, html = {}, options = {}, link = true)
display_photo(profile, image_size(profile, "200x200"), html, options, link)
end


def display_photo(profile, size, html = {}, options = {}, link = true)
return image_tag("wrench.png") unless profile # this should not happen
return image_tag("wrench.png") unless profile

show_default_image = !(options[:show_default] == false)
html.reverse_merge!(:class => 'thumbnail', :size => size, :title => "Link to #{profile.name}")

if profile && profile.user
if profile.user && profile.user.photo && File.exists?(profile.user.photo)
@user = profile.user
if link
return link_to(image_tag(url_for_file_column("user", "photo", size), html), profile_path(profile) )
else
return image_tag(url_for_file_column("user", "photo", size), html)
end
else
show_default_image ? default_photo(profile, size, {}, link) : ''
html.reverse_merge!(:class => 'thumbnail', :size => size, :title => "Link to #{profile.name}")

if profile.has_valid_photo?
imagefile = url_for_file_column("user", "photo", size)
else
if show_default_image && profile.user
size = '190x119' if profile.user.rep?
html = {}
elsif profile.user
return 'NO DEFAULT'
end
imagefile = "user#{size}.jpg"
end

show_default_image ? default_photo(profile, size, {}, link) : ''
end

def default_photo(profile, size, html={}, link = true)
if link
if profile.user.rep?
link_to(image_tag("user190x119.jpg", html), profile_path(profile) )
else
link_to(image_tag("user#{size}.jpg", html), profile_path(profile) )
end
else
if profile.user.rep?
image_tag("user190x119.jpg", html)
else
image_tag("user#{size}.jpg", html)
end
end
img = image_tag(imagefile, html)
return link ? link_to(img, profile_path(profile)) : img
end
end
Loading