Fixed caching of RSS feeds; changed from caches_page to caches_action to make authentication and other filters work

This commit is contained in:
Alexey Verkhovsky 2005-09-12 01:12:00 +00:00
parent cc99790a4a
commit 4c14f07100
6 changed files with 38 additions and 33 deletions

View file

@ -2,7 +2,7 @@
# Likewise will all the methods added be available for all controllers.
class ApplicationController < ActionController::Base
before_filter :set_utf8_http_header, :connect_to_model, :setup_url_generator
before_filter :connect_to_model, :setup_url_generator, :set_content_type_header
after_filter :remember_location, :teardown_url_generator
observer :page_observer
@ -144,8 +144,12 @@ class ApplicationController < ActionController::Base
end
end
def set_utf8_http_header
@response.headers['Content-Type'] = 'text/html; charset=UTF-8'
def set_content_type_header
if %w(rss_with_content rss_with_headlines).include?(action_name)
@response.headers['Content-Type'] = 'text/xml; charset=UTF-8'
else
@response.headers['Content-Type'] = 'text/html; charset=UTF-8'
end
end
def setup_url_generator

View file

@ -16,9 +16,12 @@ class RevisionSweeper < ActionController::Caching::Sweeper
private
def expire_caches(page)
expire_page :controller => 'wiki', :web => page.web.address,
web = page.web
expire_action :controller => 'wiki', :web => web.address,
:action => %w(show published), :id => page.name
expire_page :controller => 'wiki', :web => page.web.address,
:action => %w(authors recently_revised list rss_with_content rss_with_headlines)
expire_action :controller => 'wiki', :web => web.address,
:action => %w(authors recently_revised list)
expire_fragment :controller => 'wiki', :web => web.address,
:action => %w(rss_with_headlines rss_with_content)
end
end

View file

@ -6,7 +6,7 @@ require 'zip/zip'
class WikiController < ApplicationController
# TODO implement cache sweeping
caches_page :show, :published, :authors, :recently_revised, :list, :rss_with_content, :rss_with_headlines
caches_action :show, :published, :authors, :recently_revised, :list
cache_sweeper :revision_sweeper
layout 'default', :except => [:rss_feed, :rss_with_content, :rss_with_headlines, :tex, :export_tex, :export_html]
@ -330,10 +330,9 @@ class WikiController < ApplicationController
end
@hide_description = hide_description
@response.headers['Content-Type'] = 'text/xml'
@link_action = @web.password ? 'published' : 'show'
render 'wiki/rss_feed'
render :action => 'rss_feed'
end
def render_tex_web
@ -346,7 +345,7 @@ class WikiController < ApplicationController
def render_to_string(template_name, with_layout = false)
add_variables_to_assigns
self.assigns['content_for_layout'] = @template.render_file(template_name)
if with_layout
if with_layout
@template.render_file('layouts/default')
else
self.assigns['content_for_layout']

View file

@ -1,22 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
<channel>
<title><%= @web.name %></title>
<link><%= url_for :only_path => false, :web => @web_name, :action => @link_action, :id => 'HomePage' %></link>
<description>An Instiki wiki</description>
<language>en-us</language>
<ttl>40</ttl>
<% for page in @pages_by_revision %>
<item>
<title><%= h page.plain_name %></title>
<% unless @hide_description %>
<description><%= h rendered_content(page) %></description>
<% end %>
<pubDate><%= page.revised_at.getgm.strftime "%a, %d %b %Y %H:%M:%S Z" %></pubDate>
<guid><%= url_for :only_path => false, :web => @web_name, :action => @link_action, :id => page.name %></guid>
<link><%= url_for :only_path => false, :web => @web_name, :action => @link_action, :id => page.name %></link>
<dc:creator><%= WikiWords.separate(page.author) %></dc:creator>
</item>
<% end %>
</channel>
</rss>

View file

@ -0,0 +1,21 @@
xml.rss('version' => '2.0') do
xml.channel do
xml.title(@web.name)
xml.link(url_for(:only_path => false, :web => @web_name, :action => @link_action, :id => 'HomePage'))
xml.description('An Instiki wiki')
xml.language('en-us')
xml.ttl('40')
for page in @pages_by_revision
xml.item do
xml.title(page.plain_name)
unless @hide_description
xml.description(rendered_content(page))
end
xml.pubDate(page.revised_at.getgm.strftime('%a, %d %b %Y %H:%M:%S Z'))
xml.guid(url_for(:only_path => false, :web => @web_name, :action => @link_action, :id => page.name))
xml.link(url_for(:only_path => false, :web => @web_name, :action => @link_action, :id => page.name))
end
end
end
end

View file

@ -485,7 +485,7 @@ class WikiControllerTest < Test::Unit::TestCase
end
def test_rss_title_with_ampersand
# was ticket:143
# was ticket:143
@wiki.write_page('wiki1', 'Title&With&Ampersands',
'About spaces', 1.hour.ago, Author.new('NitPicker', '127.0.0.3'), test_renderer)