about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2017-01-22 21:24:26 +0000
committerEric Wong <e@80x24.org>2017-01-22 21:33:03 +0000
commitd9a30a80d4f5db132cb5cf990247f9392416dcea (patch)
treec20718fcb1d8122256e33fbfbd1b5c6ad7e48a3b
parent3ce524d064424f1685557545b5005bda80704084 (diff)
downloadolddoc-d9a30a80d4f5db132cb5cf990247f9392416dcea.tar.gz
Make this project easier-to-install.  Builder warns on the
Fixnum deprecation under Ruby 2.4, and it is overkill for what
we need given Ruby 1.9+ has native XML escaping.
-rw-r--r--lib/olddoc/news_atom.rb72
-rw-r--r--olddoc.gemspec1
2 files changed, 48 insertions, 25 deletions
diff --git a/lib/olddoc/news_atom.rb b/lib/olddoc/news_atom.rb
index a9e8002..ed01197 100644
--- a/lib/olddoc/news_atom.rb
+++ b/lib/olddoc/news_atom.rb
@@ -1,11 +1,33 @@
 # Copyright (C) 2015-2016 all contributors <olddoc-public@80x24.org>
 # License: GPL-3.0+ <https://www.gnu.org/licenses/gpl-3.0.txt>
-require 'builder'
 
 module Olddoc::NewsAtom # :nodoc:
   include Olddoc::History
   include Olddoc::Readme
 
+  def x(dst, tag, text = nil, attrs = nil)
+    if Hash === text
+      attrs = text
+      text = nil
+    end
+    if attrs
+      attrs = attrs.map { |k,v| "#{k}=#{v.encode(xml: :attr)}" }
+      attrs = "\n#{attrs.join("\n")}"
+    end
+    case text
+    when nil
+      if block_given?
+        dst << "<#{tag}#{attrs}>"
+        yield
+        dst << "</#{tag}>"
+      else
+        dst << "<#{tag}#{attrs}/>"
+      end
+    else
+      dst << "<#{tag}#{attrs}>#{text.encode(xml: :text)}</#{tag}>"
+    end
+  end
+
   # generates an Atom feed based on git tags in the document directory
   def news_atom_xml
     project_name, short_desc, _ = readme_metadata
@@ -14,34 +36,36 @@ module Olddoc::NewsAtom # :nodoc:
     atom_uri.path += "NEWS.atom.xml"
     news_uri = @rdoc_uri.dup
     news_uri.path += "NEWS.html"
-    x = Builder::XmlMarkup.new
-    x.feed(xmlns: "http://www.w3.org/2005/Atom") do
-      x.id(atom_uri.to_s)
-      x.title("#{project_name} news")
-      x.subtitle(short_desc)
-      x.link(rel: 'alternate', type: 'text/html', href: news_uri.to_s)
-      x.updated(new_tags.empty? ? '1970-01-01:00:00:00Z' : new_tags[0][:time])
+
+    dst = ''
+    x(dst, 'feed', xmlns: 'http://www.w3.org/2005/Atom') do
+      x(dst, 'id', atom_uri.to_s)
+      x(dst, 'title', "#{project_name} news")
+      x(dst, 'subtitle', short_desc)
+      x(dst, 'link', rel: 'alternate', type: 'text/html', href: news_uri.to_s)
+      x(dst, 'updated', new_tags.empty? ? '1970-01-01:00:00:00Z'
+                                        : new_tags[0][:time])
       new_tags.each do |tag|
-        x.entry do
-          x.title(tag[:subject])
-          x.updated(tag[:time])
-          x.published(tag[:time])
-          x.author do
-            x.name(tag[:tagger_name])
-            x.email(tag[:tagger_email])
+        x(dst, 'entry') do
+          x(dst, 'title', tag[:subject])
+          x(dst, 'updated', tag[:time])
+          x(dst, 'published', tag[:time])
+          x(dst, 'author') do
+            x(dst, 'name', tag[:tagger_name])
+            x(dst, 'email', tag[:tagger_email])
           end
           uri = tag_uri(tag[:tag]).to_s
-          x.link(rel: "alternate", type: 'text/html', href: uri)
-          x.id(uri)
-          x.content(type: :xhtml) do
-            x.div(xmlns: 'http://www.w3.org/1999/xhtml') do
-              x.pre(tag[:body])
-            end
-          end
+          x(dst, 'link', rel: 'alternate', type: 'text/html', href: uri)
+          x(dst, 'id', uri)
+          x(dst, 'content', type: 'xhtml') do
+            x(dst, 'div', xmlns: 'http://www.w3.org/1999/xhtml') do
+              x(dst, 'pre', tag[:body])
+            end # div
+          end # content
         end # entry
-      end # new_tags
+      end # new_tags.each
     end # feed
-    [ x.target!, new_tags ]
+    [ dst, new_tags ]
   end
 
   def news_atom(dest = "NEWS.atom.xml")
diff --git a/olddoc.gemspec b/olddoc.gemspec
index a09ffe0..f84ee6c 100644
--- a/olddoc.gemspec
+++ b/olddoc.gemspec
@@ -18,7 +18,6 @@ Gem::Specification.new do |s|
 
   # works fine with RDoc 5.x
   s.add_dependency('rdoc', ['>= 4.2', '< 6.0'])
-  s.add_dependency('builder', '~> 3.2')
   s.required_ruby_version = '>= 1.9.3'
   s.homepage = Olddoc.config['rdoc_url']
   s.licenses = 'GPL-3.0+'