[Hiki-cvs 1549] [1096] implement RSSPage

Back to archive index

svnno****@sourc***** svnno****@sourc*****
2009年 12月 1日 (火) 00:35:21 JST


Revision: 1096
          http://sourceforge.jp/projects/hiki/svn/view?view=rev&revision=1096
Author:   okkez
Date:     2009-12-01 00:35:21 +0900 (Tue, 01 Dec 2009)

Log Message:
-----------
implement RSSPage

Modified Paths:
--------------
    hiki/branches/rack/hiki/farm/page.rb
    hiki/branches/rack/hiki/farm/wiki.rb
    hiki/branches/rack/hiki/farm.rb

Modified: hiki/branches/rack/hiki/farm/page.rb
===================================================================
--- hiki/branches/rack/hiki/farm/page.rb	2009-11-30 15:35:19 UTC (rev 1095)
+++ hiki/branches/rack/hiki/farm/page.rb	2009-11-30 15:35:21 UTC (rev 1096)
@@ -106,147 +106,60 @@
     end
 
     # TODO: refactor
-    class RSSPage < Page
+    class RSSPage
+      include ::Hiki::Util
+
       class << self
         def command_name
           'rss'
         end
       end
 
-      def initialize(farm, hikifarm_uri, template_dir, hikifarm_description,
-                     author, mail, title)
-        super(template_dir)
-        @manager = farm
-        @hikifarm_uri = hikifarm_uri
-        @hikifarm_base_uri = @hikifarm_uri.sub(%r|[^/]*$|, '')
-        @hikifarm_description = hikifarm_description
-        @author = author
-        @mail = mail
-        @title = title
-        @wikilist =****@manag*****_by{|x| x.mtime}.reverse[0..14]
-        setup_headings
+      def initialize(conf, manager)
+        @conf = conf
+        @manager = manager
       end
 
-      private
-      def template_name
-        'rss.rdf'
+      def to_s
+        make_rss.to_s
       end
 
-      def setup_headings
-        @headings['type'] = 'text/xml'
-        @headings['charset'] = 'EUC-JP'
-        @headings['Content-Language'] = 'ja'
-        @headings['Pragma'] = 'no-cache'
-        @headings['Cache-Control'] = 'no-cache'
-        lm = last_modified
-        # @headings['Last-Modified'] = CGI.rfc1123_date(lm) if lm
-      end
+      private
 
-      def last_modified
-        if****@wikil*****?
-          nil
-        else
-          @wikilist.first.mtime
-        end
-      end
+      def make_rss
+        require 'rss'
+        rss = RSS::Maker.make("1.0") do |maker|
+          maker.channel.about = "http://example.com/index.rdf"
+          maker.channel.title =****@conf*****
+          maker.channel.description =****@conf*****_description
+          maker.channel.link = "http://example.com/"
 
-      def rss_uri
-        "#{@hikifarm_uri}#{@manager.command_query(self.class.command_name)}"
-      end
+          maker.items.do_sort  = true
+          maker.items.max_size = 15
 
-      def tag(name, content)
-        "<#{name}>#{escape_html(content)}</#{name}>"
-      end
-
-      def dc_prefix
-        "dc"
-      end
-
-      def content_prefix
-        "content"
-      end
-
-      def dc_tag(name, content)
-        tag("#{dc_prefix}:#{name}", content)
-      end
-
-      def content_tag(name, content)
-        tag("#{content_prefix}:#{name}", content)
-      end
-
-      def dc_language
-        dc_tag("language", "ja-JP")
-      end
-
-      def dc_creator
-        version = "#{HIKIFARM_VERSION} (#{HIKIFARM_RELEASE_DATE})"
-        creator = "HikiFarm version #{version}"
-        dc_tag("creator", creator)
-      end
-
-      def dc_publisher
-        dc_tag("publisher", "#{@author} <#{@mail}>")
-      end
-
-      def dc_rights
-        dc_tag("rights", "Copyright (C) #{@author} <#{@mail}>")
-      end
-
-      def dc_date(date)
-        if date
-          dc_tag("date", date.iso8601)
-        else
-          ""
+          @manager.wikilist.each do |wiki|
+            maker.items.new_item do |item|
+              item.link  = "http://example.com/article.html"
+              item.title = wiki.title
+              item.date  = wiki.mtime
+              item.description = wiki.description
+              content = %Q!<div class="recent-changes">\n!
+              content << "  <ol>\n"
+              wiki.pages.each do |page|
+                content << "    <li>"
+                content << %Q!<a href="">*</a>!
+                content << %Q!<a href="">#{escape_html(unescape(page[:name]))}</a>!
+                content << %Q!(#{escape_html(modified(page[:mtime]))})!
+                content << "</li>\n"
+              end
+              content << "  </ol>\n"
+              content << %Q!</div>!
+              item.content_encoded = content
+            end
+          end
         end
       end
 
-      def rdf_lis(indent='')
-        @wikilist.collect do |wiki|
-          %Q[#{indent}<rdf:li rdf:resource="#{wiki_uri(wiki)}"/>]
-        end.join("\n")
-      end
-
-      def rdf_items(indent="")
-        @wikilist.collect do |wiki|
-          <<-ITEM
-#{indent}<item rdf:about="#{wiki_uri(wiki)}">
-#{indent}  #{tag('title', wiki.title)}
-#{indent}  #{tag('link', wiki_uri(wiki))}
-#{indent}  #{tag('description', wiki_description(wiki))}
-#{indent}  #{dc_date(wiki.mtime)}
-#{indent}  #{content_encoded(wiki)}
-#{indent}</item>
-      ITEM
-        end.join("\n")
-      end
-
-      def wiki_uri(wiki)
-        "#{@hikifarm_base_uri}#{wiki.name}/"
-      end
-
-      def wiki_description(wiki)
-        "「#{unescape(wiki.last_modified_page)}」ページが変更されました."
-      end
-
-      def content_encoded(wiki)
-        return '' if wiki.pages.empty?
-        base_uri = wiki_uri(wiki)
-        content = "<div class='recent-changes'>\n"
-        content << "  <ol>\n"
-        wiki.pages.each do |page|
-          content << "    <li>"
-          content << "<a href='#{base_uri}?c=diff;p=#{page[:name]}'>"
-          content << "*</a>\n"
-          content << "<a href='#{base_uri}?#{page[:name]}'>"
-          content << "#{escape_html(unescape(page[:name]))}</a>"
-          content << "(#{escape_html(modified(page[:mtime]))})"
-          content << "</li>\n"
-        end
-        content << "  </ol>\n"
-        content << "</div>\n"
-        content_tag("encoded", content)
-      end
-
       # from RWiki
       def modified(t)
         return '-' unless t

Modified: hiki/branches/rack/hiki/farm/wiki.rb
===================================================================
--- hiki/branches/rack/hiki/farm/wiki.rb	2009-11-30 15:35:19 UTC (rev 1095)
+++ hiki/branches/rack/hiki/farm/wiki.rb	2009-11-30 15:35:21 UTC (rev 1096)
@@ -1,7 +1,12 @@
+require 'hiki/util'
+
 module Hiki
   module Farm
     class Wiki
+      include ::Hiki::Util
+
       attr_reader :name, :title, :mtime, :last_modified_page, :pages_num, :pages
+
       def initialize(name, data_root)
         @name = name
         @pages_num = 0
@@ -36,6 +41,10 @@
           }
         end
       end
+
+      def description
+        "#{unescape(last_modified_page)} was updated."
+      end
     end
   end
 end

Modified: hiki/branches/rack/hiki/farm.rb
===================================================================
--- hiki/branches/rack/hiki/farm.rb	2009-11-30 15:35:19 UTC (rev 1095)
+++ hiki/branches/rack/hiki/farm.rb	2009-11-30 15:35:21 UTC (rev 1096)
@@ -37,7 +37,12 @@
 
       def run(manager, request)
         case
-        when false # RSS
+        when request.get? && %r!\A/hikifarm.rss\z! =~ request.path_info
+          body = ::Hiki::Farm::RSSPage.new(@conf, manager).to_s
+          ::Hiki::Response.new(body, 200, { })
+        when request.get? && 'rss' == request.params[manager.command_key]
+          body = ::Hiki::Farm::RSSPage.new(@conf, manager).to_s
+          ::Hiki::Response.new(body, 200, { })
         when request.post? && request.params['wiki'] && !request.params['wiki'].empty?
           begin
             name = request.params['wiki']




Hiki-cvs メーリングリストの案内
Back to archive index