* [PATCH] remove 'builder' dependency
@ 2017-01-22 21:33 Eric Wong
0 siblings, 0 replies; only message in thread
From: Eric Wong @ 2017-01-22 21:33 UTC (permalink / raw)
To: olddoc-public
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.
---
lib/olddoc/news_atom.rb | 72 ++++++++++++++++++++++++++++++++-----------------
olddoc.gemspec | 1 -
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+'
--
EW
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2017-01-22 21:33 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-01-22 21:33 [PATCH] remove 'builder' dependency Eric Wong
Code repositories for project(s) associated with this public inbox
http://80x24.org/olddoc.git/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).