From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,BAYES_00 shortcircuit=no autolearn=ham autolearn_force=no version=3.4.0 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 04A0F20A17 for ; Sun, 22 Jan 2017 21:33:36 +0000 (UTC) From: Eric Wong To: Subject: [PATCH] remove 'builder' dependency Date: Sun, 22 Jan 2017 21:33:36 +0000 Message-Id: <20170122213336.30451-1-e@80x24.org> List-Id: 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 # License: GPL-3.0+ -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 << "" + else + dst << "<#{tag}#{attrs}/>" + end + else + dst << "<#{tag}#{attrs}>#{text.encode(xml: :text)}" + 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