Permalink
Browse files

Add attributes to sort the pages

  • Loading branch information...
DefV committed Jun 10, 2009
1 parent cde11bf commit cad1684b4102d61ee3cdecfc3aae64ba58e35568
@@ -26,11 +26,18 @@ class TagSearchPage < Page
end
end
- desc %{ Renders the contained block for each result page. The context
- inside the tag refers to the found page.}
+ desc %{ <r:search:results:each [sort_by="id"] [order="asc"]/>
+ Renders the contained block for each result page. The context
+ inside the tag refers to the found page. The optional sort_by and order attributes
+ specify how the results are sorted}
tag 'search:results:each' do |tag|
+ # Ordering in Ruby because we already fetched our resultset before
+ tags = found_tags
+ tags = tags.sort_by(&tag.attr['sort_by'].to_sym) if tag.attr['sort_by']
+ tags = tags.reverse if tag.attr['order'].to_s =~ /desc/i
+
returning String.new do |content|
- found_tags.each do |page|
+ tags.each do |page|
tag.locals.page = page
content << tag.expand
end
@@ -10,7 +10,7 @@ display_tags_part:
<r:search:results>
<h2>These pages are tagged with "<r:search:query/>".</h2>
<ul>
- <r:search:results:each>
+ <r:search:results:each order="desc" by="published_at">
<li><r:link/> door <r:author/> op <r:date/></li>
</r:search:results:each>
</ul>
View
@@ -14,7 +14,7 @@ documentation:
slug: documentation
status_id: 100
parent_id: 1
- published_at: 2006-01-30 08:41:07
+ published_at: 2006-01-31 08:41:07
books:
id: 3
title: Books
@@ -29,6 +29,12 @@ def test_page_should_show_posts_tagged_with_tag
assert_match /Documentation/, output
end
+ def test_resulting_pages_should_be_sorted
+ @page.request.request_parameters = {:tag => "lorem"}
+ output = @page.render
+ assert_match /Documentation.*Ruby Home Page/, output
+ end
+
def test_unknown_tag_should_say_so
@page.request.request_parameters = {:tag => "foobarbar"}
output = @page.render

0 comments on commit cad1684

Please sign in to comment.