Extracted categories menu to a helper, and got rid of hrefs

instiki-madeleine
Alexey Verkhovsky 2005-04-07 03:24:02 +00:00
parent 1df5f3f764
commit a74b3f8934
5 changed files with 18 additions and 32 deletions

View File

@ -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
%{<span class="selected">#{c}</span>}
else
%{<a href="?category=#{c}">#{c}</a>}
end
}
end
def parse_rss_params

View File

@ -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
"<div id=\"categories\">\n" +
'<strong>Categories</strong>:' +
'[' + 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" +
'</div>'
end
end
end

View File

@ -1,12 +1,6 @@
<% @title = "All Pages" %>
<% unless @categories.empty? %>
<div id="categories">
<strong>Categories</strong>:
[<a href=".">Any</a>]
<%= @category_links.join(', ') %>
</div>
<% end %>
<%= categories_menu unless @categories.empty? %>
<div id="allPages" style="float: left; width: 280px; margin-right: 30px">
<% unless @pages_that_are_orphaned.empty? && @page_names_that_are_wanted.empty? %>

View File

@ -1,12 +1,6 @@
<% @title = "Recently Revised" %>
<% unless @categories.empty? %>
<div id="categories">
<strong>Categories</strong>:
[<a href=".">Any</a>]
<%= @category_links.join(', ') %>
</div>
<% end %>
<%= categories_menu %>
<% unless @pages_by_revision.empty? %>
<% revision_date = @pages_by_revision.first.revised_on %>

View File

@ -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 ['<a href="?category=animals">animals</a>', '<a href="?category=trees">trees</a>'],
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 ['<a href="?category=categorized">categorized</a>'],
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 ['<a href="?category=animals">animals</a>',
'<a href="?category=trees">trees</a>'],
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 ['<span class="selected">animals</span>', '<a href="?category=trees">trees</a>'],
r.template_objects['category_links']
end