rubyで構築された、Atom Feedの管理ツールです
Revision | 3a26f8049ee2a4d597e235906039fe046a70269c (tree) |
---|---|
Time | 2009-12-10 16:11:31 |
Author | unknown <SEA@.(no...> |
Commiter | unknown |
add experimental method : convert xml to html.
@@ -60,10 +60,10 @@ class Object | ||
60 | 60 | mode = arg[1] |
61 | 61 | rdonly_p = true |
62 | 62 | case mode |
63 | - when String | |
63 | + when String | |
64 | 64 | arg[1] = mode[/[^:]+/] if RUBY_VERSION < "1.8.7" && mode.include?(':') |
65 | 65 | rdonly_p = /\A[^:]*[wa+]/ !~ mode |
66 | - when Numeric | |
66 | + when Numeric | |
67 | 67 | rdonly_p = !(mode & (IO::WRONY | IO::RDWR)) |
68 | 68 | end |
69 | 69 | open(*arg) do |f| |
@@ -407,6 +407,42 @@ class Entry < AbstractEntry | ||
407 | 407 | return entrylist |
408 | 408 | end |
409 | 409 | |
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 | + | |
410 | 446 | # Entry挿入メソッド |
411 | 447 | def self.insert(path, entry) |
412 | 448 | feed = Feed.readxml(path) |