pax_global_header00006660000000000000000000000064122143417050014511gustar00rootroot0000000000000052 comment=188f6c41675e8ce2217693a4d2179e19d7a0e166 td2planet-0.3.0/000077500000000000000000000000001221434170500134065ustar00rootroot00000000000000td2planet-0.3.0/ChangeLog000066400000000000000000000037601221434170500151660ustar00rootroot000000000000002013-09-12 Kazuhiro NISHIYAMA * bin/td2planet.rb: set $KCODE="u" unless ruby 1.9 or later. 2013-09-12 Kazuhiro NISHIYAMA * bin/td2planet.rb: remove -Ku and use ruby instead of ruby1.8. 2013-09-12 Kazuhiro NISHIYAMA * lib/td2planet/version.rb: use RUBY_DESCRIPTION if available. 2013-09-12 Kazuhiro NISHIYAMA * lib/td2planet/version.rb: bump version to 0.3.0. 2013-09-12 Kazuhiro NISHIYAMA * td2planet.gemspec: add license. 2013-09-12 Kazuhiro NISHIYAMA * setup.rb: removed. * README.rdoc: remove about setup.rb. * README.ja.rdoc: ditto. 2013-09-12 Kazuhiro NISHIYAMA * README.rdoc: rename from README. * README.ja.rdoc: rename from README.ja. 2013-09-12 Kazuhiro NISHIYAMA * td2planet.gemspec: change homepage from rubyforge to github. 2009-10-29 Kazuhiro NISHIYAMA * td2planet.gemspec: add description. 2009-10-28 Kazuhiro NISHIYAMA * lib/td2planet/version.rb: bump up version. * README, README.ja: update copyright year. * lib/td2planet/*.rb: update copyright year. remove #-- and #++. * README: update description. thanks debian-l10n-english ML. http://lists.debian.org/debian-l10n-english/2007/06/msg00123.html 2009-10-28 Kazuhiro NISHIYAMA * lib/td2planet/formatter.rb: ignore error of URI.parse. see http://bugs.debian.org/552186 2009-10-28 Kazuhiro NISHIYAMA * lib/td2planet/fetcher.rb: add User-Agent. * lib/td2planet/fetcher.rb, lib/td2planet/formatter.rb, data/td2planet/templates/day.rhtml, data/td2planet/templates/footer.rhtml, data/td2planet/templates/opml.rxml: allow missing properties. 2007-06-05 Kazuhiro NISHIYAMA * lib/td2planet/fetcher.rb (TD2Planet::Fetcher#fetch_all_rss): do not stop when exception. 2007-02-22 Kazuhiro NISHIYAMA * Initial public release. td2planet-0.3.0/MIT-LICENSE000066400000000000000000000020461221434170500150440ustar00rootroot00000000000000Copyright (c) 2006 Kazuhiro NISHIYAMA Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. td2planet-0.3.0/README.ja.rdoc000066400000000000000000000050161221434170500156070ustar00rootroot00000000000000= TD2Planet これはrubyによるplanet実装です。 主にtDiaryのmakerss.rbプラグインの出力を扱う用に調整してあります。 planetとは何かについては http://www.planetplanet.org などを 参照してください。 == インストール === rubygemsを使ったインストール 1. gem build *.gemspec 2. gem install *.gem == 使い方 1. config.yamlを適当なところにコピーして編集 2. td2planet.rb config.yaml 3. 必要なら出力されたファイルを公開ディレクトリにコピー 4. 必要ならcronなどで定期的に実行 === インストールせずに使う方法 1. config.yamlを編集 2. ruby -I lib bin/td2planet.rb config.yaml 3. 以降は上と同じ == セキュリティ上の注意 信頼できないRSSは設定しないでください。 output_htmlで指定したファイルには元のRSSのcontent:encodedの内容が、 スクリプトなどを含んでいたとしても、そのまま出力されます。 セキュリティ上の問題を避けるため、このplanetのドメインを他の コンテンツのドメインとわけることをお薦めします。 (例えば planet.example.jp) == 出力のカスタマイズ カスタマイズ後、"td2planet.rb -n config.yaml"で出力を更新できます。 === テンプレートのカスタマイズ 1. カスタマイズするテンプレート用のディレクトリを作成 2. カスタマイズしたいテンプレートファイルをtemplates以下からコピー 3. コピーしたテンプレートファイルを編集 4. カスタマイズしたテンプレート用のディレクトリをconfig.yamlのtemplates_pathに追加 === Formatterのカスタマイズ 1. default_formatter.rbかsample_formatter.rbを./your_formatter.rbなどにコピー 2. ファイルを編集(DefaultFormatterかSampleFormatterをファイル名がyour_formatter.rbならYourFormatterに変更する必要あり) == Q&A [Q. なぜcontent:encodedをそのまま出力?] A. 安全なホワイトリストやブラックリストを保守できないため。 (ホワイトリストの例: http://d.hatena.ne.jp/keyword/%A4%CF%A4%C6%A4%CA%A5%C0%A5%A4%A5%A2%A5%EA%A1%BCXSS%C2%D0%BA%F6 ) [Q. RSSに内容をいれていないのはなぜ?] A. 他のフィードリーダーを使っているのなら、opmlを使って 元のフィードをインポートして購読できるから。 == License MIT-LICENSE Copyright (c) 2006, 2007, 2009, 2013 Kazuhiro NISHIYAMA -- # -*- coding: utf-8 -*- # vim: ts=2 sw=2 sts=2: td2planet-0.3.0/README.rdoc000066400000000000000000000037131221434170500152200ustar00rootroot00000000000000= TD2Planet - Ruby-based server-side blog aggregator This package is a server-side blog aggregator (commonly called a 'planet') which is well-suited for aggregating tDiary-based blogs. See http://www.planetplanet.org about 'planet'. == Install === Install using rubygems 1. gem build *.gemspec 2. gem install *.gem == Usage 1. copy and edit config.yaml 2. run "td2planet.rb config.yaml" 3. copy output files to public directory if need be 4. set cron and so on if need be === Usage without install 1. copy and edit config.yaml 2. run "ruby -I lib bin/td2planet.rb config.yaml" 3. same as above == SECURITY NOTICE Do not add untrusted feeds. All content:encoded in feeds output to the file of output_html as is, even if content:encoded includes scripts and so on. To avoid security problem, I recommend to divide the domain of this planet from the domains of other contents. (e.g. planet.example.jp) == Customize Output After customize, run "td2planet.rb -n config.yaml" to update output files. === Customize Template 1. make override templates directory 2. copy the file under templates to the override templates directory 3. edit the file 4. add the override templates directory to templates_path in config.yaml === Customize Formatter 1. copy default_formatter.rb or sample_formatter.rb to ./your_formatter.rb 2. edit the file (you must change class name from DefaultFormatter or SampleFormatter to YourFormatter if the filename is your_formatter.rb) == Q&A [Q. Why do this planet outputs content:encoded as is?] A. I can not keep safe white lists and/or black lists. (see one of white lists: http://d.hatena.ne.jp/keyword/%A4%CF%A4%C6%A4%CA%A5%C0%A5%A4%A5%A2%A5%EA%A1%BCXSS%C2%D0%BA%F6 (Japanese)) [Q. Why do not output feeds include contents?] A. If you use other feed reader, you can import original feeds from opml to the feed reader. == License MIT-LICENSE Copyright (c) 2006, 2007, 2009, 2013 Kazuhiro NISHIYAMA -- # -*- coding: utf-8 -*- # vim: ts=2 sw=2 sts=2: td2planet-0.3.0/bin/000077500000000000000000000000001221434170500141565ustar00rootroot00000000000000td2planet-0.3.0/bin/td2planet.rb000077500000000000000000000004111221434170500163770ustar00rootroot00000000000000#! /usr/bin/ruby # -*- mode: ruby; coding: utf-8 -*- # vim: set filetype=ruby ts=2 sw=2 sts=2: # # copyright (c) 2006, 2007, 2013 Kazuhiro NISHIYAMA if RUBY_VERSION < "1.9" $KCODE = "u" end require 'td2planet/runner' require 'td2planet/version' TD2Planet.main td2planet-0.3.0/config.yaml000066400000000000000000000027441221434170500155460ustar00rootroot00000000000000## general config title: TD2Planet Sample base_uri: http://planet.example.jp/ ## feed URIs uri: - http://kazuhiko.tdiary.net/index.rdf - http://sho.tdiary.net/index.rdf - http://www.tdiary.net/index.rdf - http://www.tdiary.org/index.rdf ## feeds cache into cache_dir cache_dir: cache ## generated files into output_dir output_dir: output output_html: planet.html ## themes #tdiary_theme_path: http://localhost/tdiary/theme tdiary_theme_path: /var/www/tdiary/theme tdiary_theme: light-blue ## parts of templates #author: Your name #made: mailto:webmaster@example.jp #favicon: /favicon.ico #logo_html: date_strftime_format: '%Y-%m-%d' sanchor_strftime_format: '%H:%M:%S' ## templates search path #templates_path: # - /path/to/override/templates # - /path/to/other/override/templates ## formatter formatter: default_formatter #formatter: sample_formatter #formatter: your_formatter ## spam filter (default_formatter feature) ## (filtered if last value is true, output if false) filter: | if (/ツッコミ/ =~ k(item.title) && ( (k(item.content_encoded).scan(/http:/).size >= 5) || (k(item.description).scan(/http:/).size >= 5) || (/\[\/url\]/ =~ k(item.content_encoded)) || (/\[\/url\]/ =~ k(item.description)) || (/★/ =~ k(item.dc_creator)) || /@google\.com/ =~ k(item.dc_creator) )) true else false end td2planet-0.3.0/data/000077500000000000000000000000001221434170500143175ustar00rootroot00000000000000td2planet-0.3.0/data/td2planet/000077500000000000000000000000001221434170500162145ustar00rootroot00000000000000td2planet-0.3.0/data/td2planet/templates/000077500000000000000000000000001221434170500202125ustar00rootroot00000000000000td2planet-0.3.0/data/td2planet/templates/day.rhtml000066400000000000000000000015151221434170500220410ustar00rootroot00000000000000

<%=h date_format(items[0]) %> <% if rss.channel.link -%> <%=hk rss.channel.title %> <% else -%> <%=hk rss.channel.title %> <% end -%> <% if rss.channel.respond_to?(:dc_creator) && rss.channel.dc_creator -%> (<%=hk rss.channel.dc_creator %>) <% end -%>

<% items.each do |item| -%> <%= section(item, rss) -%> <% end -%>
<% if rss.channel.respond_to?(:dc_rights) && /./ =~ rss.channel.dc_rights.to_s -%>

<%=hk rss.channel.dc_rights %>

<% end -%>
td2planet-0.3.0/data/td2planet/templates/footer.rhtml000066400000000000000000000015401221434170500225600ustar00rootroot00000000000000 td2planet-0.3.0/data/td2planet/templates/header.rhtml000066400000000000000000000000231221434170500225050ustar00rootroot00000000000000
td2planet-0.3.0/data/td2planet/templates/layout.rhtml000066400000000000000000000025711221434170500226040ustar00rootroot00000000000000 <% if @config['author'] -%> <% end -%> <% if @config['made'] -%> <% end -%> <% if @config['favicon'] -%> <% end -%> <%=h @config['title'] %>

<%=h @config['title'] %>

<%= header %> <% days.each do |day| -%> <%= move_tukkomi_link(day(day[:items], day[:rss])) %> <% end -%>
<%= footer %> td2planet-0.3.0/data/td2planet/templates/opml.rxml000066400000000000000000000012311221434170500220620ustar00rootroot00000000000000 <%=h @config['title'] %> <%=h Time.now %> <%=h Time.now %> <% if @config.key?('author') -%> <%=h @config['author'] %> <% end -%> <% if @config.key?('made') -%> <%=h @config['made'].sub(/^mailto:/, '') %> <% end -%> <% rss_list.sort_by{|rss| rss.respond_to?(:item) && rss.item.respond_to?(:date) ? -rss.item.date.to_i : 0 }.each do |rss| -%> <% end -%> td2planet-0.3.0/data/td2planet/templates/section.rhtml000066400000000000000000000007241221434170500227310ustar00rootroot00000000000000
<% section_body = to_section_body(item) # tdiary makerss.rb plugin if /

<%= section_body.sub(//) do $& + to_sanchor(item) # + to_categories(item) # categories in original h3 end.sub(/<\/h3>/) do to_author(item) + $& end %> <% else -%>

<%= to_sanchor(item) %> <%= to_categories(item) %> <%=hk item.title %> <%= to_author(item) %>

<%= to_section_body(item) %> <% end -%>

td2planet-0.3.0/lib/000077500000000000000000000000001221434170500141545ustar00rootroot00000000000000td2planet-0.3.0/lib/td2planet/000077500000000000000000000000001221434170500160515ustar00rootroot00000000000000td2planet-0.3.0/lib/td2planet/default_formatter.rb000066400000000000000000000006611221434170500221100ustar00rootroot00000000000000# -*- mode: ruby; coding: utf-8 -*- # vim: set filetype=ruby ts=2 sw=2 sts=2: # # copyright (c) 2006, 2007, 2009 Kazuhiro NISHIYAMA require 'td2planet/formatter' module TD2Planet class DefaultFormatter < Formatter def initialize(config) super unless @config.key?('filter') @config['filter'] = 'true' end end def skip?(item) eval(@config['filter']) or too_old?(item) end end end td2planet-0.3.0/lib/td2planet/fetcher.rb000066400000000000000000000031441221434170500200200ustar00rootroot00000000000000# -*- mode: ruby; coding: utf-8 -*- # vim: set filetype=ruby ts=2 sw=2 sts=2: # # copyright (c) 2006, 2007, 2009 Kazuhiro NISHIYAMA require 'erb' require 'pathname' require 'rss' require 'uri' module TD2Planet class Fetcher def initialize(cache_dir, dry_run=false, user_agent="td2planet") @cache_dir = Pathname.new(cache_dir) unless @cache_dir.exist? @cache_dir.mkdir end @dry_run = dry_run @user_agent = user_agent end def fetch_all_rss(uris) rss_list = [] uris.each do |uri| cache_file = @cache_dir + ERB::Util.u(uri) if @dry_run puts "use cache: #{cache_file}" text = cache_file.read else text = nil begin puts "fetch: #{uri}" text = URI.parse(uri).read("User-Agent" => @user_agent) rescue Timeout::Error # fallback puts "ERROR: timeout #{uri}" text = cache_file.read rescue Exception puts "ERROR: #{$!} (#{$!.class}) on #{uri}" next else if text.status[0] == '200' && /rss/ =~ text cache_file.open('wb'){|f| f.write(text) } else # fallback puts "ERROR: fetch failed #{uri} #{text.status}" text = cache_file.read end end end text = fixup_rss(text) rss_list << RSS::Parser.parse(text, false) end rss_list end # euc-jp may fail to parse def fixup_rss(text) text.sub(/\bencoding="euc-jp"/ni, 'encoding="euc-jp-ms"') end end end td2planet-0.3.0/lib/td2planet/formatter.rb000066400000000000000000000152451221434170500204100ustar00rootroot00000000000000# -*- mode: ruby; coding: utf-8 -*- # vim: set filetype=ruby ts=2 sw=2 sts=2: # # copyright (c) 2006, 2007, 2009 Kazuhiro NISHIYAMA require 'erb' require 'nkf' require 'uri' require 'rss/maker' module TD2Planet class Formatter include ERB::Util ERB_METHODS = [] def self.def_erb_method(method_name, fname=nil) if /\A\w+/ =~ method_name fname ||= "#{$&}.rhtml" end ERB_METHODS << [method_name, fname] end def_erb_method('layout(days)') def_erb_method('day(items, rss)') def_erb_method('section(item, rss)') def_erb_method('header()') def_erb_method('footer()') def k(s) NKF.nkf('-wm0', s.to_s) end def hk(s) h(k(s)) end def default_templates_dir basename = 'layout.rhtml' dir = File.expand_path('../../data/td2planet/templates', File.dirname(__FILE__)) if File.exist?(File.join(dir, basename)) return dir end require 'rbconfig' dir = File.expand_path('td2planet/templates', Config::CONFIG['datadir']) if File.exist?(File.join(dir, basename)) return dir end raise "not found templates" end def initialize(config) @config = config @config['title'] ||= '(no title Planet)' @config['tdiary_theme_path'] ||= '/tdiary/theme' @config['tdiary_theme'] ||= 'default' @config['date_strftime_format'] ||= '%Y-%m-%d' @config['sanchor_strftime_format'] ||= '%H:%M:%S' @base_uri = URI.parse(@config['base_uri']) @config['templates_path'] ||= [] @config['templates_path'].push(default_templates_dir) ERB_METHODS.each do |method_name, basename| @config['templates_path'].find do |dir| fname = File.expand_path(basename, dir) if File.exist?(fname) puts "use template #{basename}: #{fname}" erb = ERB.new(File.read(fname), nil, '-') eval("def self.#{method_name}\n#{erb.src}\nend\n", binding, fname, 0) true else false end end end end def date_format(item) return "" unless item.respond_to?(:date) && item.date item.date.localtime.strftime(@config['date_strftime_format']) end def sanchor_format(item) return "" unless item.respond_to?(:date) && item.date item.date.localtime.strftime(@config['sanchor_strftime_format']) end def too_old?(item, sec=7*24*60*60) return false unless item.respond_to?(:date) && item.date item.date < Time.now - sec end # override def skip?(item) false end def to_html(rss_list) @rss_list = rss_list day_rss = {} rss_list.each do |rss| next unless rss.items rss.items.each do |item| next if skip?(item) day = (day_rss[[date_format(item), rss]] ||= Array.new) day.push(item) end end days = [] day_rss.keys.sort_by do |date, rss| date end.reverse_each do |key| date, rss = key items = day_rss[key] items = items.sort_by do |item| # tdiary makerss plugin generates same time entries item.date.to_s + item.link end days << {:items => items, :rss => rss} end days = days.sort_by do |day| -day[:items].collect{|item| item.date.to_i}.max end layout(days) end def relative_path_to_absolute_uri(attr_value, base_uri) uri = URI.parse(attr_value) if uri.scheme.nil? URI.parse(base_uri) + uri else uri end rescue URI::InvalidURIError attr_value end def tag_attr_relative_path_to_absolute_uri(tag, attr_name, base_uri) tag.gsub!(/#{Regexp.quote(attr_name)}=([\"\'])([^\"\']*)\1/i) do %Q!#{attr_name}=#{$1}#{relative_path_to_absolute_uri($2, base_uri)}#{$1}! end or tag.gsub!(/#{Regexp.quote(attr_name)}=(\S+)/) do %Q!#{attr_name}=#{relative_path_to_absolute_uri($1, base_uri)}! end tag end def to_section_body(item) if item.respond_to?(:content_encoded) && item.content_encoded k(item.content_encoded).gsub(/<([aA]\b[\s\S]+?)>/) do a = tag_attr_relative_path_to_absolute_uri($1, "href", item.link) %Q!<#{a} rel="nofollow">! #end.gsub(//i) do # tag_attr_relative_path_to_absolute_uri($&, "src", item.link) end.gsub(//i) do img = $& case img when /alt=([\"\'])(.+?)\1/ $2 when /alt=(\S+?)/ $1 else "[img]" end end else '

' + h(k(item.description)).gsub(/\r?\n/, '
') + '

' end end def to_sanchor(item) %Q!#{h sanchor_format(item)} ! end def to_categories(item) return "" unless item.respond_to?(:dc_subjects) h(item.dc_subjects.collect{|s|"[#{k(s.content)}]" if /./ =~ s.content}) end def to_author(item) if item.respond_to?(:dc_creator) && item.dc_creator " (#{hk(item.dc_creator)})" else "" end end TukkomiLinkRe = /^

ツッコミを入れる<\/a><\/p>$/ def move_tukkomi_link(html) if TukkomiLinkRe =~ html tukkomi_link = $& tukkomi_uri = $1 re = Regexp.new(Regexp.quote(tukkomi_link)) tukkomi_moved_html = html.gsub(re, '') re = Regexp.new(Regexp.quote('')) tukkomi_moved_html.sub!(re) { %Q|

| } # other day tukkomi_link found if TukkomiLinkRe =~ tukkomi_moved_html html.gsub!(TukkomiLinkRe) { %Q|| } else html = tukkomi_moved_html end end html end def_erb_method('to_opml(rss_list)', 'opml.rxml') def to_rss(rss_list, version='1.0', basename='rss.xml') RSS::Maker.make(version) do |maker| maker.channel.about = @base_uri + basename maker.channel.title = @config['title'] maker.channel.link = @base_uri maker.channel.description = "#{@base_uri} - #{@config['title']}" maker.items.do_sort = true rss_list.each do |rss| rss.items.each do |item| next if skip?(item) new_item = maker.items.new_item %w"link title date".each do |attr| value = item.__send__(attr) value = k(value) if value.is_a?(String) new_item.__send__("#{attr}=", value) end end end end end end end td2planet-0.3.0/lib/td2planet/runner.rb000066400000000000000000000030301221434170500177030ustar00rootroot00000000000000# -*- mode: ruby; coding: utf-8 -*- # vim: set filetype=ruby ts=2 sw=2 sts=2: # # copyright (c) 2006, 2007, 2009 Kazuhiro NISHIYAMA require 'optparse' require 'td2planet/fetcher' require 'td2planet/formatter' require 'td2planet/writer' require 'yaml' module TD2Planet module_function def main(argv=ARGV) opts = OptionParser.new usage = proc { puts opts; exit(1) } opts.banner << " config.yaml" @dry_run = false opts.on('-n', '--dry-run', 'do not fetch, generate files only') { @dry_run = true } opts.on('-h', '--help', 'show this message') { usage.call } opts.parse!(argv) if argv.empty? usage.call end argv.each do |filename| config = YAML.load(File.read(filename)) run(config) end end def get_formatter_class(formatter_name) formatter_class_name = formatter_name.gsub(/(^|_)(.)/) { $2.upcase } begin require formatter_name rescue LoadError begin require "td2planet/#{formatter_name}" rescue LoadError raise LoadError, "no such formatter: #{formatter_name}" end end formatter = const_get(formatter_class_name) end def run(config) formatter_name = config['formatter'] || 'default_formatter' formatter = get_formatter_class(formatter_name).new(config) writer = Writer.new(config, formatter) fetcher = Fetcher.new(config['cache_dir'], @dry_run) rss_list = fetcher.fetch_all_rss(config['uri']) writer.output_html(rss_list) writer.output_opml(rss_list) writer.output_rss(rss_list) end end td2planet-0.3.0/lib/td2planet/sample_formatter.rb000066400000000000000000000007541221434170500217500ustar00rootroot00000000000000# -*- mode: ruby; coding: utf-8 -*- # vim: set filetype=ruby ts=2 sw=2 sts=2: # # copyright (c) 2006, 2007, 2009 Kazuhiro NISHIYAMA require 'td2planet/formatter' module TD2Planet class SampleFormatter < Formatter def spam?(item) if /ツッコミ/ =~ k(item.title) && /casino/ =~ item.dc_creator && /casino/ =~ item.description true else false end end def skip?(item) spam?(item) or too_old?(item) end end end td2planet-0.3.0/lib/td2planet/version.rb000066400000000000000000000015721221434170500200700ustar00rootroot00000000000000# -*- mode: ruby; coding: utf-8 -*- # vim: set filetype=ruby ts=2 sw=2 sts=2: # # copyright (c) 2006, 2007, 2009, 2013 Kazuhiro NISHIYAMA module TD2Planet TD2PLANET_VERSION = "0.3.0" TD2PLANET_RELEASE_DATE = "2013-09-12" # return ruby version string (simulate output of ruby -v) def self.ruby_version if defined?(RUBY_DESCRIPTION) RUBY_DESCRIPTION elsif defined?(RUBY_PATCHLEVEL) "ruby #{RUBY_VERSION} (#{RUBY_RELEASE_DATE} patchlevel #{RUBY_PATCHLEVEL}) [#{RUBY_PLATFORM}]" else "ruby #{RUBY_VERSION} (#{RUBY_RELEASE_DATE}) [#{RUBY_PLATFORM}]" end end # return TD2Planet version string def self.td2planet_version "TD2Planet #{TD2PLANET_VERSION} (#{TD2PLANET_RELEASE_DATE})" end # return string for meta generator (see templates/layout.rhtml) def self.generator "#{td2planet_version} / Powered by #{ruby_version}" end end td2planet-0.3.0/lib/td2planet/writer.rb000066400000000000000000000022731221434170500177160ustar00rootroot00000000000000# -*- mode: ruby; coding: utf-8 -*- # vim: set filetype=ruby ts=2 sw=2 sts=2: # # copyright (c) 2006, 2007, 2009 Kazuhiro NISHIYAMA require 'pathname' module TD2Planet class Writer def initialize(config, formatter) @config = config @output_dir ||= Pathname.new(config['output_dir']) unless @output_dir.exist? @output_dir.mkdir end @formatter = formatter end def output_html(rss_list) if @config.key?('output_html') output_html = @output_dir + @config['output_html'] else output_html = @output_dir + 'index.html' end output_html.open('wb') do |f| f.write(@formatter.to_html(rss_list)) end end def output_opml(rss_list) output_opml = @output_dir + 'opml.xml' output_opml.open('wb') do |f| f.write(@formatter.to_opml(rss_list)) end end def output_rss(rss_list) [ ['1.0', 'rss10.xml'], ['2.0', 'rss20.xml'], ].each do |rss_version, basename| output_rss = @output_dir + basename output_rss.open('wb') do |f| f.write(@formatter.to_rss(rss_list, rss_version, basename)) end end end end end td2planet-0.3.0/td2planet.gemspec000066400000000000000000000017251221434170500166550ustar00rootroot00000000000000$LOAD_PATH.push File.join(File.dirname(__FILE__), 'lib') require 'td2planet/version' Gem::Specification.new do |s| s.name = "td2planet" s.version = TD2Planet::TD2PLANET_VERSION s.date = TD2Planet::TD2PLANET_RELEASE_DATE s.author = "Kazuhiro NISHIYAMA" s.email = "zn@mbf.nifty.com" s.homepage = "https://github.com/znz/td2planet" s.rubyforge_project = "td2planet" s.platform = Gem::Platform::RUBY s.description = "Ruby-based server-side blog aggregator" s.summary = "planet of ruby, mainly for tdiary" s.license = 'MIT' s.files = [ Dir.glob("{bin,lib}/**/*.rb"), %w"ChangeLog MIT-LICENSE README.rdoc README.ja.rdoc", %w"config.yaml", Dir.glob("**/templates/*.r{html,xml}"), ].flatten.sort s.require_path = "lib" s.executables = %w"td2planet.rb" s.has_rdoc = true s.rdoc_options = %w"--charset utf-8 --inline-source --line-numbers --main README.rdoc" s.extra_rdoc_files = %w"README.rdoc README.ja.rdoc" end