yahns Ruby server user/dev discussion
 help / color / Atom feed
From: Eric Wong <yahns-public@yhbt.net>
To: yahns-public@yhbt.net
Subject: [PATCH 3/4] Revert "use olddoc 1.1.0 for generating NEWS + NEWS.atom.xml"
Date: Sun,  5 Mar 2017 22:30:01 +0000
Message-ID: <20170305223002.9822-4-yahns-public@yhbt.net> (raw)
In-Reply-To: <20170305223002.9822-1-yahns-public@yhbt.net>

This reverts commit bcf0f0efb3173b18957ddba2af6592219a2d72a3.

The dependency on olddoc makes it slightly more difficult for
users to package their own and distribute RubyGems.  We will
also not host HTML RDoc files since we have no internal API
to support.
---
 .gitignore  |   1 -
 .olddoc.yml |   7 -----
 Rakefile    | 101 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++---
 3 files changed, 97 insertions(+), 12 deletions(-)
 delete mode 100644 .olddoc.yml

diff --git a/.gitignore b/.gitignore
index c1c147f..45603bb 100644
--- a/.gitignore
+++ b/.gitignore
@@ -15,4 +15,3 @@
 .gem-manifest
 .tgz-manifest
 /doc
-/LATEST
diff --git a/.olddoc.yml b/.olddoc.yml
deleted file mode 100644
index 67b78d0..0000000
--- a/.olddoc.yml
+++ /dev/null
@@ -1,7 +0,0 @@
----
-cgit_url: https://yhbt.net/yahns.git
-git_url: git://yhbt.net/yahns.git
-rdoc_url: https://yhbt.net/yahns/
-ml_url: https://yhbt.net/yahns-public/
-public_email: yahns-public@yhbt.net
-private_email: yahns@yhbt.net
diff --git a/Rakefile b/Rakefile
index b776c4a..3eb0219 100644
--- a/Rakefile
+++ b/Rakefile
@@ -66,12 +66,105 @@ def tags
   end.compact.sort { |a,b| b[:time] <=> a[:time] }
 end
 
+def xml(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
+
 desc 'prints news as an Atom feed'
 task "NEWS.atom.xml" do
-  # gem install 'olddoc', 'olddoc prepare' has no API besides the
-  # command-line.  This requires olddoc 1.1 or later.
-  system('olddoc', 'prepare') or abort "olddoc prepare failed #$?"
+  require 'uri'
+  cgit_uri = URI('https://yhbt.net/yahns.git')
+  uri = URI('https://yhbt.net/yahns/')
+  new_tags = tags[0,10]
+  time = nil
+  project_name = 'yahns'
+  short_desc = File.readlines('README')[0].split(' - ')[0]
+  new_tags = tags[0,10]
+  atom_uri = uri.dup
+  atom_uri.path += 'NEWS.atom.xml'
+  news_uri = uri.dup
+  news_uri.path += 'NEWS.html'
+  dst = ''
+  xml(dst, 'feed', xmlns: 'http://www.w3.org/2005/Atom') do
+    xml(dst, 'id', atom_uri.to_s)
+    xml(dst, 'title', "#{project_name} news")
+    xml(dst, 'subtitle', short_desc)
+    xml(dst, 'link', rel: 'alternate', type: 'text/html', href: news_uri.to_s)
+    xml(dst, 'updated', new_tags.empty? ? '1970-01-01:00:00:00Z'
+                                      : new_tags[0][:time])
+    new_tags.each do |tag|
+      xml(dst, 'entry') do
+        xml(dst, 'title', tag[:subject])
+        xml(dst, 'updated', tag[:time])
+        xml(dst, 'published', tag[:time])
+        xml(dst, 'author') do
+          xml(dst, 'name', tag[:tagger_name])
+          xml(dst, 'email', tag[:tagger_email])
+        end
+        uri = cgit_uri.dup
+        uri.path += '/tag/'
+        uri.query = "id=#{tag[:tag]}"
+        uri = uri.to_s
+        xml(dst, 'link', rel: 'alternate', type: 'text/html', href: uri)
+        xml(dst, 'id', uri)
+        xml(dst, 'content', type: 'xhtml') do
+          xml(dst, 'div', xmlns: 'http://www.w3.org/1999/xhtml') do
+            xml(dst, 'pre', tag[:body])
+          end # div
+        end # content
+      end # entry
+    end # new_tags.each
+  end # feed
+
+  fp = Tempfile.new('NEWS.atom.xml', '.')
+  fp.sync = true
+  fp.write(dst)
+  fp.chmod 0644
+  File.utime(time, time, fp.path) if time
+  File.rename(fp.path, 'NEWS.atom.xml')
+  fp.close!
 end
 
 desc 'prints news as a text file'
-task 'NEWS' => 'NEWS.atom.xml'
+task 'NEWS' do
+  fp = Tempfile.new('NEWS', '.')
+  fp.sync = true
+  time = nil
+  tags.each do |tag|
+    time ||= tag[:time_obj]
+    line = tag[:subject] + ' / ' + tag[:time].sub(/T.*/, '')
+    fp.puts line
+    fp.puts('-' * line.length)
+    fp.puts
+    fp.puts tag[:body]
+    fp.puts
+  end
+  fp.write("Unreleased\n\n") unless fp.size > 0
+  fp.puts "COPYRIGHT"
+  fp.puts "---------"
+  fp.puts "Copyright (C) 2013-2017 all contributors <yahns-public@yhbt.net>"
+  fp.puts "License: GPL-3.0+ <https://www.gnu.org/licenses/gpl-3.0.txt>"
+  fp.chmod 0644
+  File.utime(time, time, fp.path) if time
+  File.rename(fp.path, 'NEWS')
+  fp.close!
+end
-- 
EW


  parent reply index

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-05 22:29 [PATCH 0/4] documentation cleanups and tidying Eric Wong
2017-03-05 22:29 ` [PATCH 1/4] update more referenced URLs to be HTTPS Eric Wong
2017-03-05 22:30 ` [PATCH 2/4] chunk_body: nodoc this internal class Eric Wong
2017-03-05 22:30 ` Eric Wong [this message]
2017-03-05 22:30 ` [PATCH 4/4] gemspec: stop advertising "private" email address Eric Wong

Reply instructions:

You may reply publically to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://yhbt.net/yahns/README

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170305223002.9822-4-yahns-public@yhbt.net \
    --to=yahns-public@yhbt.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

yahns Ruby server user/dev discussion

Archives are clonable:
	git clone --mirror https://yhbt.net/yahns-public
	git clone --mirror http://ou63pmih66umazou.onion/yahns-public

Newsgroups are available over NNTP:
	nntp://news.public-inbox.org/inbox.comp.lang.ruby.yahns
	nntp://ou63pmih66umazou.onion/inbox.comp.lang.ruby.yahns

 note: .onion URLs require Tor: https://www.torproject.org/

AGPL code for this site: git clone https://public-inbox.org/ public-inbox