Skip to content

Commit

Permalink
Adding a directory-style index to /gems so it's actually useful. Closes
Browse files Browse the repository at this point in the history
  • Loading branch information
qrush committed Jul 29, 2009
1 parent 5ae9691 commit 45eba95
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 13 deletions.
3 changes: 2 additions & 1 deletion app/controllers/rubygems_controller.rb
Expand Up @@ -9,7 +9,8 @@ def mine
end

def index
@gems = Rubygem.paginate :page => params[:page], :order => "name asc", :conditions => "name <> ''"
params[:letter] = "a" unless params[:letter]
@gems = Rubygem.name_starts_with(params[:letter]).paginate(:page => params[:page])
end

def show
Expand Down
5 changes: 5 additions & 0 deletions app/helpers/rubygems_helper.rb
@@ -1,5 +1,10 @@
module RubygemsHelper

def link_to_page(text, url)
link_to text, url unless url.blank?
end

def link_to_directory
("A".."Z").map { |letter| link_to(letter, rubygems_path(:letter => letter)) }.join
end
end
2 changes: 2 additions & 0 deletions app/views/rubygems/index.html.haml
@@ -1,6 +1,8 @@
-@title = "all gems"
-@subtitle = ""
.grid_12
.directory
=link_to_directory
=will_paginate @gems
.gems
-@gems.each do |gem|
Expand Down
18 changes: 10 additions & 8 deletions config/environment.rb
Expand Up @@ -35,14 +35,16 @@

DO_NOT_REPLY = "donotreply@gemcutter.org"

require 'lib/rubygems'
require 'lib/rubygems/format'
require 'lib/rubygems/indexer'
require 'lib/rubygems/platform'
require 'lib/rubygems/source_index'
require 'lib/rubygems/version'
require 'lib/indexer'
require 'lib/core_ext/string'
silence_warnings do
require 'lib/rubygems'
require 'lib/rubygems/format'
require 'lib/rubygems/indexer'
require 'lib/rubygems/platform'
require 'lib/rubygems/source_index'
require 'lib/rubygems/version'
require 'lib/indexer'
require 'lib/core_ext/string'
end

Gem.configuration.verbose = false

Expand Down
2 changes: 2 additions & 0 deletions features/push.feature
Expand Up @@ -10,6 +10,7 @@ Feature: Push Gems
When I push the gem "RGem-1.2.3.gem" with my api key
And I go to the homepage
And I follow "list"
And I follow "R"
And I follow "RGem (1.2.3)"
Then I should see "RGem"
And I should see "1.2.3"
Expand All @@ -23,6 +24,7 @@ Feature: Push Gems
When I push the gem "BGem-3.0.0.gem" with my api key
And I go to the homepage
And I follow "list"
And I follow "B"
And I follow "BGem (3.0.0)"
Then I should see "BGem"
And I should see "2.0.0"
Expand Down
20 changes: 18 additions & 2 deletions public/stylesheets/application.css
Expand Up @@ -192,12 +192,28 @@ h3 {
.what {
text-align: center;
font-weight: bold;
text-align: center;
text-align: center;
font-size: 1.1em;
margin-bottom: 50px;
}

.directory {
text-align: center;
margin-bottom: 10px;
}

.directory a {
font-weight: bold;
font-size: 1.8em;
padding: 10px;
color: #ffffff;
background:#900000;
}

.directory a:hover {
background:#600000;
cursor: pointer;
}

.gems a {
background:#900000;
border-top:1px solid #C2C2C2;
Expand Down
20 changes: 18 additions & 2 deletions test/functional/rubygems_controller_test.rb
Expand Up @@ -209,9 +209,10 @@ def create_gem(owner, opts = {})
should_redirect_to('the homepage') { root_url }
end

context "On GET to index" do
context "On GET to index with no parameters" do
setup do
@gems = (1..3).map { Factory(:rubygem) }
@gems = (1..3).map { |n| Factory(:rubygem, :name => "agem#{n}") }
Factory(:rubygem, :name => "zeta")
get :index
end

Expand All @@ -226,6 +227,21 @@ def create_gem(owner, opts = {})
end
end

context "On GET to index with a letter" do
setup do
@gems = (1..3).map { |n| Factory(:rubygem, :name => "agem#{n}") }
@zgem = Factory(:rubygem, :name => "zeta")
get :index, :letter => "z"
end
should_respond_with :success
should_render_template :index
should_assign_to(:gems) { [@zgem] }
should "render links" do
assert_contain @zgem.name
assert_have_selector "a[href='#{rubygem_path(@zgem)}']"
end
end

context "On GET to show" do
setup do
@current_version = Factory(:version)
Expand Down
7 changes: 7 additions & 0 deletions test/unit/helpers/rubygems_helper_test.rb
@@ -1,6 +1,13 @@
require 'test_helper'

class RubygemsHelperTest < ActionView::TestCase
should "create the directory" do
directory = link_to_directory
("A".."Z").each do |letter|
assert_match rubygems_path(:letter => letter), directory
end
end

context "creating linkset links" do
setup do
@linkset = Factory.build(:linkset)
Expand Down

0 comments on commit 45eba95

Please sign in to comment.