From a74b3f8934ab002ba1650d13b60379c4c7d6e14d Mon Sep 17 00:00:00 2001 From: Alexey Verkhovsky Date: Thu, 7 Apr 2005 03:24:02 +0000 Subject: [PATCH] Extracted categories menu to a helper, and got rid of hrefs --- app/controllers/wiki_controller.rb | 9 +-------- app/helpers/application_helper.rb | 15 +++++++++++++++ app/views/wiki/list.rhtml | 8 +------- app/views/wiki/recently_revised.rhtml | 8 +------- test/functional/wiki_controller_test.rb | 10 ---------- 5 files changed, 18 insertions(+), 32 deletions(-) diff --git a/app/controllers/wiki_controller.rb b/app/controllers/wiki_controller.rb index 06448c2a..f11d5dc5 100644 --- a/app/controllers/wiki_controller.rb +++ b/app/controllers/wiki_controller.rb @@ -120,7 +120,7 @@ class WikiController < ApplicationController @page.unlock redirect_show end - + def edit if @page.nil? redirect_to :action => 'index' @@ -294,13 +294,6 @@ class WikiController < ApplicationController @pages_in_category = PageSet.new(@web).by_name @set_name = 'the web' end - @category_links = @categories.map { |c| - if @category == c - %{#{c}} - else - %{#{c}} - end - } end def parse_rss_params diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index a8d6ee3f..cad785c0 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -50,4 +50,19 @@ module ApplicationHelper web.make_link(page_name, text, options.merge(:base_url => base_url)) end + # Creates a menu of categories + def categories_menu + if @categories.empty? + '' + else + "
\n" + + 'Categories:' + + '[' + link_to_unless_current('Any', :web => @web.address, :action => @action_name) + "]\n" + + @categories.map { |c| + link_to_unless_current(c, :web => @web.address, :action => @action_name, :category => c) + }.join(', ') + "\n" + + '
' + end + end + end diff --git a/app/views/wiki/list.rhtml b/app/views/wiki/list.rhtml index 02c0bcf6..b38ebc2b 100644 --- a/app/views/wiki/list.rhtml +++ b/app/views/wiki/list.rhtml @@ -1,12 +1,6 @@ <% @title = "All Pages" %> -<% unless @categories.empty? %> -
- Categories: - [Any] - <%= @category_links.join(', ') %> -
-<% end %> +<%= categories_menu unless @categories.empty? %>
<% unless @pages_that_are_orphaned.empty? && @page_names_that_are_wanted.empty? %> diff --git a/app/views/wiki/recently_revised.rhtml b/app/views/wiki/recently_revised.rhtml index 1e4364d6..a3196a59 100644 --- a/app/views/wiki/recently_revised.rhtml +++ b/app/views/wiki/recently_revised.rhtml @@ -1,12 +1,6 @@ <% @title = "Recently Revised" %> -<% unless @categories.empty? %> -
- Categories: - [Any] - <%= @category_links.join(', ') %> -
-<% end %> +<%= categories_menu %> <% unless @pages_by_revision.empty? %> <% revision_date = @pages_by_revision.first.revised_on %> diff --git a/test/functional/wiki_controller_test.rb b/test/functional/wiki_controller_test.rb index 7227879a..800c324a 100755 --- a/test/functional/wiki_controller_test.rb +++ b/test/functional/wiki_controller_test.rb @@ -197,8 +197,6 @@ class WikiControllerTest < Test::Unit::TestCase assert_equal ['animals', 'trees'], r.template_objects['categories'] assert_nil r.template_objects['category'] - assert_equal ['animals', 'trees'], - r.template_objects['category_links'] assert_equal [@elephant, @home, @oak], r.template_objects['pages_in_category'] end @@ -281,7 +279,6 @@ class WikiControllerTest < Test::Unit::TestCase assert_nil r.template_objects['category'] assert_equal [@home], r.template_objects['pages_in_category'] assert_equal 'the web', r.template_objects['set_name'] - assert_equal [], r.template_objects['category_links'] end def test_recently_revised_with_categorized_page @@ -300,8 +297,6 @@ class WikiControllerTest < Test::Unit::TestCase "Pages are not as expected: " + r.template_objects['pages_in_category'].map {|p| p.name}.inspect assert_equal 'the web', r.template_objects['set_name'] - assert_equal ['categorized'], - r.template_objects['category_links'] end def test_recently_revised_with_categorized_page_multiple_categories @@ -317,9 +312,6 @@ class WikiControllerTest < Test::Unit::TestCase "Pages are not as expected: " + r.template_objects['pages_in_category'].map {|p| p.name}.inspect assert_equal 'the web', r.template_objects['set_name'] - assert_equal ['animals', - 'trees'], - r.template_objects['category_links'] end def test_recently_revised_with_specified_category @@ -333,8 +325,6 @@ class WikiControllerTest < Test::Unit::TestCase assert_equal 'animals', r.template_objects['category'] assert_equal [@elephant], r.template_objects['pages_in_category'] assert_equal "category 'animals'", r.template_objects['set_name'] - assert_equal ['animals', 'trees'], - r.template_objects['category_links'] end