• R/O
  • HTTP
  • SSH
  • HTTPS

feedgenerator: Commit

rubyで構築された、Atom Feedの管理ツールです


Commit MetaInfo

Revision3a26f8049ee2a4d597e235906039fe046a70269c (tree)
Time2009-12-10 16:11:31
Authorunknown <SEA@.(no...>
Commiterunknown

Log Message

add experimental method : convert xml to html.

Change Summary

Incremental Difference

--- a/feedgenerator.rb
+++ b/feedgenerator.rb
@@ -60,10 +60,10 @@ class Object
6060 mode = arg[1]
6161 rdonly_p = true
6262 case mode
63- when String
63+ when String
6464 arg[1] = mode[/[^:]+/] if RUBY_VERSION < "1.8.7" && mode.include?(':')
6565 rdonly_p = /\A[^:]*[wa+]/ !~ mode
66- when Numeric
66+ when Numeric
6767 rdonly_p = !(mode & (IO::WRONY | IO::RDWR))
6868 end
6969 open(*arg) do |f|
@@ -407,6 +407,42 @@ class Entry < AbstractEntry
407407 return entrylist
408408 end
409409
410+ # Atom XMLファイルを読み込んで解析し、テンプレートファイルにしたがってHTMLに変換するメソッドです
411+ def self.to_html(xmlpath, destpath, entry_temppath, html_temppath)
412+ # 引数チェック - 全必須
413+ if xmlpath.empty? or destpath.empty? or entry_temppath.empty? or html_temppath.empty?
414+ raise ArgumentError
415+ end
416+
417+ # 必須ファイル存在チェック
418+ unless File.exist?(xmlpath) and File.exist?(entry_temppath) and File.exist?(html_temppath)
419+ raise IOError
420+ end
421+
422+ # XML読み込み
423+ entrylist = Entry.readxml(xmlpath)
424+
425+ content = ''
426+ entrylist.each { |e|
427+ # Entry毎のHTML表示部分を生成
428+ content << e.to_template(entry_temppath)
429+ }
430+
431+ # HTML全体のテンプレートを生成
432+ html_temp = HtmlWriter.new(html_temppath, binding)
433+
434+ # HTMLに書き込み
435+ myopen(destpath, 'w:utf-8') { |f|
436+ f.write(CGI.pretty(html_temp.to_code))
437+ }
438+ end
439+
440+ # Entryをテンプレートに沿って変形するメソッド
441+ def to_template(temppath)
442+ erb = HtmlWriter.new(temppath)
443+ erb.to_code
444+ end
445+
410446 # Entry挿入メソッド
411447 def self.insert(path, entry)
412448 feed = Feed.readxml(path)
Show on old repository browser