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. # Likewise will all the methods added be available for all controllers.
class ApplicationController < ActionController::Base 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 after_filter :remember_location, :teardown_url_generator
observer :page_observer observer :page_observer
@ -144,9 +144,13 @@ class ApplicationController < ActionController::Base
end end
end end
def set_utf8_http_header 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' @response.headers['Content-Type'] = 'text/html; charset=UTF-8'
end end
end
def setup_url_generator def setup_url_generator
PageRenderer.setup_url_generator(UrlGenerator.new(self)) PageRenderer.setup_url_generator(UrlGenerator.new(self))

View file

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

View file

@ -6,7 +6,7 @@ require 'zip/zip'
class WikiController < ApplicationController class WikiController < ApplicationController
# TODO implement cache sweeping # 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 cache_sweeper :revision_sweeper
layout 'default', :except => [:rss_feed, :rss_with_content, :rss_with_headlines, :tex, :export_tex, :export_html] layout 'default', :except => [:rss_feed, :rss_with_content, :rss_with_headlines, :tex, :export_tex, :export_html]
@ -330,10 +330,9 @@ class WikiController < ApplicationController
end end
@hide_description = hide_description @hide_description = hide_description
@response.headers['Content-Type'] = 'text/xml'
@link_action = @web.password ? 'published' : 'show' @link_action = @web.password ? 'published' : 'show'
render 'wiki/rss_feed' render :action => 'rss_feed'
end end
def render_tex_web def render_tex_web

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