RSS feeds accept query parameter start, end and limit

This commit is contained in:
Alexey Verkhovsky 2005-02-18 02:24:16 +00:00
parent 5e25a94e51
commit aa95acb4f7
4 changed files with 73 additions and 6 deletions

View file

@ -1,4 +1,6 @@
HEAD:
RSS feeds accept query parameters, sush as
http://localhost:2500/wiki/rss_with_headlines?start=2005-02-18&end=2005-02-19&limit=10
RedCloth 3.0.3 (read: mixing Textile and Markdown in the same page)
Files/pictures can be uploaded to a wiki and served from / displayed in wiki pages
Wiki link syntax doesn't conflict with Textile hyperlink syntax. Therefore

View file

@ -1,10 +1,11 @@
require 'application'
require 'fileutils'
require 'redcloth_for_tex'
require 'parsedate'
class WikiController < ApplicationController
layout 'default', :except => [:rss_feed, :rss_with_headlines, :tex, :export_tex, :export_html]
layout 'default', :except => [:rss_feed, :rss_with_content, :rss_with_headlines, :tex, :export_tex, :export_html]
def index
if @web_name
@ -89,11 +90,11 @@ class WikiController < ApplicationController
end
def rss_with_content
render_rss
render_rss(hide_description = false, *parse_rss_params)
end
def rss_with_headlines
render_rss(hide_description = true)
render_rss(hide_description = true, *parse_rss_params)
end
def search
@ -291,6 +292,18 @@ class WikiController < ApplicationController
}
end
def parse_rss_params
if @params.include? 'limit'
limit = @params['limit'].to_i rescue nil
limit = nil if limit == 0
else
limit = 15
end
start_date = Time.local(*ParseDate::parsedate(@params['start'])) rescue nil
end_date = Time.local(*ParseDate::parsedate(@params['end'])) rescue nil
[ limit, start_date, end_date ]
end
def password_check(password)
if password == @web.password
cookies['web_address'] = password
@ -306,8 +319,15 @@ class WikiController < ApplicationController
ip
end
def render_rss(hide_description = false)
@pages_by_revision = @web.select.by_revision.first(15)
def render_rss(hide_description = false, limit = 15, start_date = nil, end_date = nil)
if limit && !start_date && !end_date
@pages_by_revision = @web.select.by_revision.first(limit)
else
@pages_by_revision = @web.select.by_revision
@pages_by_revision.reject! { |page| page.created_at < start_date } if start_date
@pages_by_revision.reject! { |page| page.created_at > end_date } if end_date
end
@hide_description = hide_description
@response.headers['Content-Type'] = 'text/xml'
render 'wiki/rss_feed'

View file

@ -344,7 +344,6 @@ class WikiControllerTest < Test::Unit::TestCase
assert_equal @home.revisions[0], r.template_objects['revision']
end
def test_rss_with_content
setup_wiki_with_three_pages
@ -388,6 +387,45 @@ class WikiControllerTest < Test::Unit::TestCase
assert_template_xpath_match '/rss/channel/item/link', expected_page_links
end
def test_rss_with_params
setup_wiki_with_30_pages
r = process 'rss_with_headlines', 'web' => 'wiki1'
assert_success
pages = r.template_objects['pages_by_revision']
assert_equal 15, pages.size, 15
r = process 'rss_with_headlines', 'web' => 'wiki1', 'limit' => '5'
assert_success
pages = r.template_objects['pages_by_revision']
assert_equal 5, pages.size
r = process 'rss_with_headlines', 'web' => 'wiki1', 'limit' => '25'
assert_success
pages = r.template_objects['pages_by_revision']
assert_equal 25, pages.size
r = process 'rss_with_headlines', 'web' => 'wiki1', 'limit' => 'all'
assert_success
pages = r.template_objects['pages_by_revision']
assert_equal 31, pages.size
r = process 'rss_with_headlines', 'web' => 'wiki1', 'start' => '1976-10-16'
assert_success
pages = r.template_objects['pages_by_revision']
assert_equal 16, pages.size
r = process 'rss_with_headlines', 'web' => 'wiki1', 'end' => '1976-10-16'
assert_success
pages = r.template_objects['pages_by_revision']
assert_equal 15, pages.size
r = process 'rss_with_headlines', 'web' => 'wiki1', 'start' => '1976-10-01', 'end' => '1976-10-06'
assert_success
pages = r.template_objects['pages_by_revision']
assert_equal 5, pages.size
end
def test_save
r = process 'save', 'web' => 'wiki1', 'id' => 'NewPage', 'content' => 'Contents of a new page',
'author' => 'AuthorOfNewPage'

View file

@ -45,6 +45,13 @@ class Test::Unit::TestCase
10.minutes.ago, Author.new('Guest', '127.0.0.2'))
end
def setup_wiki_with_30_pages
(1..30).each { |i|
@wiki.write_page('wiki1', "page#{i}", "Test page #{i}\ncategory: test",
Time.local(1976, 10, i, 12, 00, 00), Author.new('Dema', '127.0.0.2'))
}
end
def tear_down_wiki
ApplicationController.wiki = nil
end