diff options
author | kou <kou@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2004-11-19 08:25:25 +0000 |
---|---|---|
committer | kou <kou@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2004-11-19 08:25:25 +0000 |
commit | 9be1ed43c888249563f32a3df394a9841e4f9601 (patch) | |
tree | 4a484468fdf164dca7059a0d0e6ea6155ecd5682 /lib/rss/0.9.rb | |
parent | 1c453c06081222e9b75dac428b08ffd26f1ca2a7 (diff) | |
download | ruby-9be1ed43c888249563f32a3df394a9841e4f9601.tar.gz |
* lib/rss/rss.rb (RSS::VERSION): 0.1.0 -> 0.1.1.
* lib/rss: #to_s used #tag.
* test/rss/test_to_s.rb: added.
* lib/rss/maker.rb (RSS::Maker.make): changed API. It's not
received modules which is used as the second argument.
* lib/rss/xml-stylesheet.rb (RSS::XMLStyleSheet#alternate):
changed return value type which is not String but Boolean.
* lib/rss/2.0.rb (RSS::Rss::Channel#ttl): changed return value
type which is not String but Integer.
* lib/rss/0.9.rb (RSS::Rss::Channel): <skipDays> has <day>s and
<skipHours> has <hour>s.
* lib/rss/maker/0.9.rb (RSS::Maker::RSS09::Channel): ditto.
* lib/rss/0.9.rb (RSS::Rss::Channel::Item): <item> has <category>s.
* lib/rss/maker/2.0.rb (RSS::Maker::Rss20::Channel::Item): ditto.
* lib/rss/2.0.rb (RSS::Rss::Channel): <channel> has <category>s.
* lib/rss/maker/2.0.rb (RSS::Maker::RSS20::Channel): ditto.
* lib/rss/trackback.rb: parent element has <trackback:about>s.
* lib/rss/maker/trackback.rb: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7319 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/rss/0.9.rb')
-rw-r--r-- | lib/rss/0.9.rb | 302 |
1 files changed, 184 insertions, 118 deletions
diff --git a/lib/rss/0.9.rb b/lib/rss/0.9.rb index c772e80870..20a229b926 100644 --- a/lib/rss/0.9.rb +++ b/lib/rss/0.9.rb @@ -60,17 +60,14 @@ module RSS end def to_s(convert=true, indent=calc_indent) - next_indent = indent + INDENT - rv = <<-EOR -#{xmldecl} -#{xml_stylesheet_pi} -#{indent}<rss version="#{@rss_version}"#{ns_declaration(next_indent)}> -#{channel_element(false, next_indent)} -#{other_element(false, next_indent)} -#{indent}</rss> -EOR + rv = tag(indent, ns_declarations) do |next_indent| + [ + channel_element(false, next_indent), + other_element(false, next_indent), + ] + end rv = @converter.convert(rv) if convert and @converter - remove_empty_newline(rv) + rv end private @@ -86,7 +83,7 @@ EOR def _attrs [ - ["version", true], + ["version", true, "rss_version"], ] end @@ -104,8 +101,6 @@ EOR ["webMaster", "?"], ["rating", "?"], ["docs", "?"], - ["skipDays", "?"], - ["skipHours", "?"], ].each do |x, occurs| install_text_element(x) install_model(x, occurs) @@ -120,6 +115,8 @@ EOR end [ + ["skipDays", "?"], + ["skipHours", "?"], ["image", nil], ["textInput", "?"], ].each do |x, occurs| @@ -146,35 +143,35 @@ EOR end def to_s(convert=true, indent=calc_indent) - next_indent = indent + INDENT - rv = <<-EOT -#{indent}<channel> -#{title_element(false, next_indent)} -#{link_element(false, next_indent)} -#{description_element(false, next_indent)} -#{language_element(false, next_indent)} -#{copyright_element(false, next_indent)} -#{managingEditor_element(false, next_indent)} -#{webMaster_element(false, next_indent)} -#{rating_element(false, next_indent)} -#{pubDate_element(false, next_indent)} -#{lastBuildDate_element(false, next_indent)} -#{docs_element(false, next_indent)} -#{skipDays_element(false, next_indent)} -#{skipHours_element(false, next_indent)} -#{image_element(false, next_indent)} -#{item_elements(false, next_indent)} -#{textInput_element(false, next_indent)} -#{other_element(false, next_indent)} -#{indent}</channel> -EOT + rv = tag(indent) do |next_indent| + [ + title_element(false, next_indent), + link_element(false, next_indent), + description_element(false, next_indent), + language_element(false, next_indent), + copyright_element(false, next_indent), + managingEditor_element(false, next_indent), + webMaster_element(false, next_indent), + rating_element(false, next_indent), + pubDate_element(false, next_indent), + lastBuildDate_element(false, next_indent), + docs_element(false, next_indent), + cloud_element(false, next_indent), + skipDays_element(false, next_indent), + skipHours_element(false, next_indent), + image_element(false, next_indent), + item_elements(false, next_indent), + textInput_element(false, next_indent), + other_element(false, next_indent), + ] + end rv = @converter.convert(rv) if convert and @converter rv end private def children - [@image, @textInput, @cloud, *@item] + [@skipDays, @skipHours, @image, @textInput, @cloud, *@item] end def _tags @@ -206,6 +203,101 @@ EOT rv end + class SkipDays < Element + include RSS09 + + [ + ["day", "*"] + ].each do |x, occurs| + install_have_children_element(x) + install_model(x, occurs) + end + + def to_s(convert=true, indent=calc_indent) + rv = tag(indent) do |next_indent| + [ + day_elements(false, next_indent) + ] + end + rv = @converter.convert(rv) if convert and @converter + rv + end + + private + def children + @day + end + + def _tags + @day.compact.collect do + [nil, "day"] + end + end + + class Day < Element + include RSS09 + + content_setup + + def initialize(content=nil) + super() + @content = content + end + + end + + end + + class SkipHours < Element + include RSS09 + + [ + ["hour", "*"] + ].each do |x, occurs| + install_have_children_element(x) + install_model(x, occurs) + end + + def to_s(convert=true, indent=calc_indent) + rv = tag(indent) do |next_indent| + [ + hour_elements(false, next_indent) + ] + end + rv = @converter.convert(rv) if convert and @converter + rv + end + + private + def children + @hour + end + + def _tags + @hour.compact.collect do + [nil, "hour"] + end + end + + class Hour < Element + include RSS09 + + content_setup + + def initialize(content=nil) + super() + @content = content + end + + undef :content= + def content=(value) + @content = value.to_i + end + + end + + end + class Image < Element include RSS09 @@ -220,18 +312,17 @@ EOT end def to_s(convert=true, indent=calc_indent) - next_indent = indent + INDENT - rv = <<-EOT -#{indent}<image> -#{url_element(false, next_indent)} -#{title_element(false, next_indent)} -#{link_element(false, next_indent)} -#{width_element(false, next_indent)} -#{height_element(false, next_indent)} -#{description_element(false, next_indent)} -#{other_element(false, next_indent)} -#{indent}</image> -EOT + rv = tag(indent) do |next_indent| + [ + url_element(false, next_indent), + title_element(false, next_indent), + link_element(false, next_indent), + width_element(false, next_indent), + height_element(false, next_indent), + description_element(false, next_indent), + other_element(false, next_indent), + ] + end rv = @converter.convert(rv) if convert and @converter rv end @@ -245,7 +336,7 @@ EOT end end end - + class Cloud < Element include RSS09 @@ -270,16 +361,8 @@ EOT end def to_s(convert=true, indent=calc_indent) - next_indent = indent + INDENT - rv = <<-EOT -#{indent}<cloud -#{next_indent}domain="#{h @domain}" -#{next_indent}port="#{h @port}" -#{next_indent}path="#{h @path}" -#{next_indent}registerProcedure="#{h @registerProcedure}" -#{next_indent}protocol="#{h @protocol}"/> -EOT - rv = @converter.convert(rv) if convert and @converter + rv = tag(indent) + rv = @converter.convert(rv) if convert and @converter rv end @@ -300,15 +383,21 @@ EOT install_text_element(x) end - %w(category source enclosure).each do |x| + %w(source enclosure).each do |x| install_have_child_element(x) end [ + %w(category categories), + ].each do |name, plural_name| + install_have_children_element(name, plural_name) + end + + [ ["title", '?'], ["link", '?'], ["description", '?'], - ["category", '?'], + ["category", '*'], ["source", '?'], ["enclosure", '?'], ].each do |tag, occurs| @@ -316,34 +405,39 @@ EOT end def to_s(convert=true, indent=calc_indent) - next_indent = indent + INDENT - rv = <<-EOT -#{indent}<item> -#{title_element(false, next_indent)} -#{link_element(false, next_indent)} -#{description_element(false, next_indent)} -#{category_element(false, next_indent)} -#{source_element(false, next_indent)} -#{enclosure_element(false, next_indent)} -#{other_element(false, next_indent)} -#{indent}</item> -EOT - rv = @converter.convert(rv) if convert and @converter + rv = tag(indent) do |next_indent| + [ + title_element(false, next_indent), + link_element(false, next_indent), + description_element(false, next_indent), + category_elements(false, next_indent), + source_element(false, next_indent), + enclosure_element(false, next_indent), + other_element(false, next_indent), + ] + end + rv = @converter.convert(rv) if convert and @converter rv end private def children - [@category, @source, @enclosure,].compact + [@source, @enclosure, *@category].compact end def _tags - %w(title link description author comments category + rv = %w(title link description author comments source enclosure).delete_if do |x| send(x).nil? end.collect do |x| [nil, x] end + + @category.each do + rv << [nil, "category"] + end + + rv end class Source < Element @@ -364,17 +458,6 @@ EOT @content = content end - def to_s(convert=true, indent=calc_indent) - if @url - rv = %Q! <source url="#{@url}">! - rv << %Q!#{@content}</source>! - rv = @converter.convert(rv) if convert and @converter - rv - else - '' - end - end - private def _tags [] @@ -408,14 +491,9 @@ EOT end def to_s(convert=true, indent=calc_indent) - if @url and @length and @type - rv = %Q!<enclosure url="#{h @url}" ! - rv << %Q!length="#{h @length}" type="#{h @type}"/>! - rv = @converter.convert(rv) if convert and @converter - rv - else - '' - end + rv = tag(indent) + rv = @converter.convert(rv) if convert and @converter + rv end private @@ -447,17 +525,6 @@ EOT @content = content end - def to_s(convert=true, indent=calc_indent) - if @domain - rv = %Q!<category domain="#{h @domain}">! - rv << %Q!#{h @content}</category>! - rv = @converter.convert(rv) if convert and @converter - rv - else - '' - end - end - private def _attrs [ @@ -470,7 +537,7 @@ EOT end class TextInput < Element - + include RSS09 %w(title description name link).each do |x| @@ -479,17 +546,16 @@ EOT end def to_s(convert=true, indent=calc_indent) - next_indent = indent + INDENT - rv = <<-EOT -#{indent}<textInput> -#{title_element(false, next_indent)} -#{description_element(false, next_indent)} -#{name_element(false, next_indent)} -#{link_element(false, next_indent)} -#{other_element(false, next_indent)} -#{indent}</textInput> -EOT - rv = @converter.convert(rv) if convert and @converter + rv = tag(indent) do |next_indent| + [ + title_element(false, next_indent), + description_element(false, next_indent), + name_element(false, next_indent), + link_element(false, next_indent), + other_element(false, next_indent), + ] + end + rv = @converter.convert(rv) if convert and @converter rv end |