From 45eba957b91a77103ec19870f89549cfe151c3c9 Mon Sep 17 00:00:00 2001 From: Nick Quaranto Date: Wed, 29 Jul 2009 18:23:31 -0400 Subject: [PATCH] Adding a directory-style index to /gems so it's actually useful. Closes #20 --- app/controllers/rubygems_controller.rb | 3 ++- app/helpers/rubygems_helper.rb | 5 +++++ app/views/rubygems/index.html.haml | 2 ++ config/environment.rb | 18 ++++++++++-------- features/push.feature | 2 ++ public/stylesheets/application.css | 20 ++++++++++++++++++-- test/functional/rubygems_controller_test.rb | 20 ++++++++++++++++++-- test/unit/helpers/rubygems_helper_test.rb | 7 +++++++ 8 files changed, 64 insertions(+), 13 deletions(-) diff --git a/app/controllers/rubygems_controller.rb b/app/controllers/rubygems_controller.rb index 0bb379095c6..48031f38470 100644 --- a/app/controllers/rubygems_controller.rb +++ b/app/controllers/rubygems_controller.rb @@ -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 diff --git a/app/helpers/rubygems_helper.rb b/app/helpers/rubygems_helper.rb index 7af0b1d1e66..25b304d56d3 100644 --- a/app/helpers/rubygems_helper.rb +++ b/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 diff --git a/app/views/rubygems/index.html.haml b/app/views/rubygems/index.html.haml index 10472ec7999..ceb25eb33e7 100644 --- a/app/views/rubygems/index.html.haml +++ b/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| diff --git a/config/environment.rb b/config/environment.rb index 307df713495..f464e29f7e1 100644 --- a/config/environment.rb +++ b/config/environment.rb @@ -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 diff --git a/features/push.feature b/features/push.feature index 3c73b61a357..3884f224a4d 100644 --- a/features/push.feature +++ b/features/push.feature @@ -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" @@ -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" diff --git a/public/stylesheets/application.css b/public/stylesheets/application.css index 796e661cd79..febcf7a05f6 100644 --- a/public/stylesheets/application.css +++ b/public/stylesheets/application.css @@ -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; diff --git a/test/functional/rubygems_controller_test.rb b/test/functional/rubygems_controller_test.rb index bfc6e7ea9dd..90537419f42 100644 --- a/test/functional/rubygems_controller_test.rb +++ b/test/functional/rubygems_controller_test.rb @@ -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 @@ -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) diff --git a/test/unit/helpers/rubygems_helper_test.rb b/test/unit/helpers/rubygems_helper_test.rb index 2477a03e96d..ea29fdec023 100644 --- a/test/unit/helpers/rubygems_helper_test.rb +++ b/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)