1 # Copyright (C) 2013-2016 all contributors <yahns-public@yhbt.net>
2 # License: GPL-3.0+ (https://www.gnu.org/licenses/gpl-3.0.txt)
7 'doc/Yahns.html' => 'lib/yahns.rb',
8 'doc/Yahns/ProxyPass.html' => 'lib/yahns/proxy_pass.rb'
11 task apidoc.keys[0] => apidoc.values do
12 rdoc = ENV['rdoc'] || 'rdoc'
13 system("git", "set-file-times", *(apidoc.values))
14 sh "#{rdoc} -f dark216" # dark216 requires olddoc 1.7+
16 apidoc.each do |dst, src|
18 File.utime(src.atime, src.mtime, dst)
22 gendocs = %W(NEWS NEWS.atom.xml #{apidoc.keys[0]})
23 task html: apidoc.keys[0]
24 task rsync_docs: gendocs do
25 dest = ENV["RSYNC_DEST"] || "yhbt.net:/srv/yhbt/yahns/"
26 top = %w(INSTALL HACKING README COPYING)
28 # git-set-file-times is distributed with rsync,
29 # Also available at: https://yhbt.net/git-set-file-times
30 # on Debian systems: /usr/share/doc/rsync/scripts/git-set-file-times.gz
31 sh("git", "set-file-times", "Documentation", "examples", *top)
32 make = ENV['MAKE'] || 'make'
33 sh(%Q(#{make} -C Documentation))
35 do_gzip = lambda do |txt|
38 sh("gzip --rsyncable -9 < #{txt} > #{tmp}")
40 File.utime(st.atime, st.mtime, tmp) # make nginx gzip_static happy
45 files = `git ls-files Documentation/*.txt`.split(/\n/)
48 files.concat(%w(doc/Yahns.html))
49 files.concat(%w(yahns yahns-rackup yahns_config).map! { |x|
50 "Documentation/#{x}.txt"
52 gzfiles = files.map { |txt| do_gzip.call(txt) }
55 sh("rsync --chmod=Fugo=r -av #{files.join(' ')} #{dest}")
57 examples = `git ls-files examples`.split(/\n/)
58 gzex = examples.map { |txt| do_gzip.call(txt) }
61 sh("rsync --chmod=Fugo=r -av #{examples.join(' ')} #{dest}/examples/")
63 rdoc = apidoc.keys.grep(%r{\Adoc/Yahns/})
64 gzex = rdoc.map { |txt| do_gzip.call(txt) }
66 sh("rsync --chmod=Fugo=r -av #{rdoc.join(' ')} #{dest}/Yahns/")
70 timefmt = '%Y-%m-%dT%H:%M:%SZ'
71 @tags ||= `git tag -l`.split(/\n/).map do |tag|
72 if %r{\Av[\d\.]+} =~ tag
73 header, subject, body = `git cat-file tag #{tag}`.split(/\n\n/, 3)
74 header = header.split(/\n/)
75 tagger = header.grep(/\Atagger /).first
77 time = Time.at(tagger.split(/ /)[-2].to_i).utc
80 time: time.strftime(timefmt),
81 tagger_name: %r{^tagger ([^<]+)}.match(tagger)[1].strip,
82 tagger_email: %r{<([^>]+)>}.match(tagger)[1].strip,
83 id: `git rev-parse refs/tags/#{tag}`.chomp!,
89 end.compact.sort { |a,b| b[:time] <=> a[:time] }
92 def xml(dst, tag, text = nil, attrs = nil)
98 attrs = attrs.map { |k,v| "#{k}=#{v.encode(xml: :attr)}" }
99 attrs = "\n#{attrs.join("\n")}"
104 dst << "<#{tag}#{attrs}>"
108 dst << "<#{tag}#{attrs}/>"
111 dst << "<#{tag}#{attrs}>#{text.encode(xml: :text)}</#{tag}>"
115 desc 'prints news as an Atom feed'
116 task "NEWS.atom.xml" do
118 cgit_uri = URI('https://yhbt.net/yahns.git')
119 uri = URI('https://yhbt.net/yahns/')
120 new_tags = tags[0,10]
122 project_name = 'yahns'
123 short_desc = File.readlines('README')[0].split(' - ')[0]
124 new_tags = tags[0,10]
126 atom_uri.path += 'NEWS.atom.xml'
128 news_uri.path += 'NEWS.html'
130 xml(dst, 'feed', xmlns: 'http://www.w3.org/2005/Atom') do
131 xml(dst, 'id', atom_uri.to_s)
132 xml(dst, 'title', "#{project_name} news")
133 xml(dst, 'subtitle', short_desc)
134 xml(dst, 'link', rel: 'alternate', type: 'text/html', href: news_uri.to_s)
135 xml(dst, 'updated', new_tags.empty? ? '1970-01-01:00:00:00Z'
136 : new_tags[0][:time])
137 new_tags.each do |tag|
139 xml(dst, 'title', tag[:subject])
140 xml(dst, 'updated', tag[:time])
141 xml(dst, 'published', tag[:time])
142 xml(dst, 'author') do
143 xml(dst, 'name', tag[:tagger_name])
144 xml(dst, 'email', tag[:tagger_email])
148 uri.query = "id=#{tag[:tag]}"
150 xml(dst, 'link', rel: 'alternate', type: 'text/html', href: uri)
152 xml(dst, 'content', type: 'xhtml') do
153 xml(dst, 'div', xmlns: 'http://www.w3.org/1999/xhtml') do
154 xml(dst, 'pre', tag[:body])
161 fp = Tempfile.new('NEWS.atom.xml', '.')
165 File.utime(time, time, fp.path) if time
166 File.rename(fp.path, 'NEWS.atom.xml')
170 desc 'prints news as a text file'
172 fp = Tempfile.new('NEWS', '.')
176 time ||= tag[:time_obj]
177 line = tag[:subject] + ' / ' + tag[:time].sub(/T.*/, '')
179 fp.puts('-' * line.length)
184 fp.write("Unreleased\n\n") unless fp.size > 0
187 fp.puts "Copyright (C) 2013-2017 all contributors <yahns-public@yhbt.net>"
188 fp.puts "License: GPL-3.0+ <https://www.gnu.org/licenses/gpl-3.0.txt>"
190 File.utime(time, time, fp.path) if time
191 File.rename(fp.path, 'NEWS')