• R/O
  • SSH
  • HTTPS

hiki: コミット


コミットメタ情報

リビジョン1096 (tree)
日時2009-12-01 00:35:21
作者okkez

ログメッセージ

implement RSSPage

変更サマリ

差分

--- hiki/branches/rack/hiki/farm/wiki.rb (revision 1095)
+++ hiki/branches/rack/hiki/farm/wiki.rb (revision 1096)
@@ -1,7 +1,12 @@
1+require 'hiki/util'
2+
13 module Hiki
24 module Farm
35 class Wiki
6+ include ::Hiki::Util
7+
48 attr_reader :name, :title, :mtime, :last_modified_page, :pages_num, :pages
9+
510 def initialize(name, data_root)
611 @name = name
712 @pages_num = 0
@@ -36,6 +41,10 @@
3641 }
3742 end
3843 end
44+
45+ def description
46+ "#{unescape(last_modified_page)} was updated."
47+ end
3948 end
4049 end
4150 end
--- hiki/branches/rack/hiki/farm/page.rb (revision 1095)
+++ hiki/branches/rack/hiki/farm/page.rb (revision 1096)
@@ -106,7 +106,9 @@
106106 end
107107
108108 # TODO: refactor
109- class RSSPage < Page
109+ class RSSPage
110+ include ::Hiki::Util
111+
110112 class << self
111113 def command_name
112114 'rss'
@@ -113,140 +115,51 @@
113115 end
114116 end
115117
116- def initialize(farm, hikifarm_uri, template_dir, hikifarm_description,
117- author, mail, title)
118- super(template_dir)
119- @manager = farm
120- @hikifarm_uri = hikifarm_uri
121- @hikifarm_base_uri = @hikifarm_uri.sub(%r|[^/]*$|, '')
122- @hikifarm_description = hikifarm_description
123- @author = author
124- @mail = mail
125- @title = title
126- @wikilist = @manager.wikilist.sort_by{|x| x.mtime}.reverse[0..14]
127- setup_headings
118+ def initialize(conf, manager)
119+ @conf = conf
120+ @manager = manager
128121 end
129122
130- private
131- def template_name
132- 'rss.rdf'
123+ def to_s
124+ make_rss.to_s
133125 end
134126
135- def setup_headings
136- @headings['type'] = 'text/xml'
137- @headings['charset'] = 'EUC-JP'
138- @headings['Content-Language'] = 'ja'
139- @headings['Pragma'] = 'no-cache'
140- @headings['Cache-Control'] = 'no-cache'
141- lm = last_modified
142- # @headings['Last-Modified'] = CGI.rfc1123_date(lm) if lm
143- end
127+ private
144128
145- def last_modified
146- if @wikilist.empty?
147- nil
148- else
149- @wikilist.first.mtime
150- end
151- end
129+ def make_rss
130+ require 'rss'
131+ rss = RSS::Maker.make("1.0") do |maker|
132+ maker.channel.about = "http://example.com/index.rdf"
133+ maker.channel.title = @conf.title
134+ maker.channel.description = @conf.hikifarm_description
135+ maker.channel.link = "http://example.com/"
152136
153- def rss_uri
154- "#{@hikifarm_uri}#{@manager.command_query(self.class.command_name)}"
155- end
137+ maker.items.do_sort = true
138+ maker.items.max_size = 15
156139
157- def tag(name, content)
158- "<#{name}>#{escape_html(content)}</#{name}>"
159- end
160-
161- def dc_prefix
162- "dc"
163- end
164-
165- def content_prefix
166- "content"
167- end
168-
169- def dc_tag(name, content)
170- tag("#{dc_prefix}:#{name}", content)
171- end
172-
173- def content_tag(name, content)
174- tag("#{content_prefix}:#{name}", content)
175- end
176-
177- def dc_language
178- dc_tag("language", "ja-JP")
179- end
180-
181- def dc_creator
182- version = "#{HIKIFARM_VERSION} (#{HIKIFARM_RELEASE_DATE})"
183- creator = "HikiFarm version #{version}"
184- dc_tag("creator", creator)
185- end
186-
187- def dc_publisher
188- dc_tag("publisher", "#{@author} <#{@mail}>")
189- end
190-
191- def dc_rights
192- dc_tag("rights", "Copyright (C) #{@author} <#{@mail}>")
193- end
194-
195- def dc_date(date)
196- if date
197- dc_tag("date", date.iso8601)
198- else
199- ""
140+ @manager.wikilist.each do |wiki|
141+ maker.items.new_item do |item|
142+ item.link = "http://example.com/article.html"
143+ item.title = wiki.title
144+ item.date = wiki.mtime
145+ item.description = wiki.description
146+ content = %Q!<div class="recent-changes">\n!
147+ content << " <ol>\n"
148+ wiki.pages.each do |page|
149+ content << " <li>"
150+ content << %Q!<a href="">*</a>!
151+ content << %Q!<a href="">#{escape_html(unescape(page[:name]))}</a>!
152+ content << %Q!(#{escape_html(modified(page[:mtime]))})!
153+ content << "</li>\n"
154+ end
155+ content << " </ol>\n"
156+ content << %Q!</div>!
157+ item.content_encoded = content
158+ end
159+ end
200160 end
201161 end
202162
203- def rdf_lis(indent='')
204- @wikilist.collect do |wiki|
205- %Q[#{indent}<rdf:li rdf:resource="#{wiki_uri(wiki)}"/>]
206- end.join("\n")
207- end
208-
209- def rdf_items(indent="")
210- @wikilist.collect do |wiki|
211- <<-ITEM
212-#{indent}<item rdf:about="#{wiki_uri(wiki)}">
213-#{indent} #{tag('title', wiki.title)}
214-#{indent} #{tag('link', wiki_uri(wiki))}
215-#{indent} #{tag('description', wiki_description(wiki))}
216-#{indent} #{dc_date(wiki.mtime)}
217-#{indent} #{content_encoded(wiki)}
218-#{indent}</item>
219- ITEM
220- end.join("\n")
221- end
222-
223- def wiki_uri(wiki)
224- "#{@hikifarm_base_uri}#{wiki.name}/"
225- end
226-
227- def wiki_description(wiki)
228- "「#{unescape(wiki.last_modified_page)}」ページが変更されました."
229- end
230-
231- def content_encoded(wiki)
232- return '' if wiki.pages.empty?
233- base_uri = wiki_uri(wiki)
234- content = "<div class='recent-changes'>\n"
235- content << " <ol>\n"
236- wiki.pages.each do |page|
237- content << " <li>"
238- content << "<a href='#{base_uri}?c=diff;p=#{page[:name]}'>"
239- content << "*</a>\n"
240- content << "<a href='#{base_uri}?#{page[:name]}'>"
241- content << "#{escape_html(unescape(page[:name]))}</a>"
242- content << "(#{escape_html(modified(page[:mtime]))})"
243- content << "</li>\n"
244- end
245- content << " </ol>\n"
246- content << "</div>\n"
247- content_tag("encoded", content)
248- end
249-
250163 # from RWiki
251164 def modified(t)
252165 return '-' unless t
--- hiki/branches/rack/hiki/farm.rb (revision 1095)
+++ hiki/branches/rack/hiki/farm.rb (revision 1096)
@@ -37,7 +37,12 @@
3737
3838 def run(manager, request)
3939 case
40- when false # RSS
40+ when request.get? && %r!\A/hikifarm.rss\z! =~ request.path_info
41+ body = ::Hiki::Farm::RSSPage.new(@conf, manager).to_s
42+ ::Hiki::Response.new(body, 200, { })
43+ when request.get? && 'rss' == request.params[manager.command_key]
44+ body = ::Hiki::Farm::RSSPage.new(@conf, manager).to_s
45+ ::Hiki::Response.new(body, 200, { })
4146 when request.post? && request.params['wiki'] && !request.params['wiki'].empty?
4247 begin
4348 name = request.params['wiki']
旧リポジトリブラウザで表示