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/")
65 timefmt = '%Y-%m-%dT%H:%M:%SZ'
66 @tags ||= `git tag -l`.split(/\n/).map do |tag|
67 if %r{\Av[\d\.]+} =~ tag
68 header, subject, body = `git cat-file tag #{tag}`.split(/\n\n/, 3)
69 header = header.split(/\n/)
70 tagger = header.grep(/\Atagger /).first
72 time = Time.at(tagger.split(/ /)[-2].to_i).utc
75 time: time.strftime(timefmt),
76 tagger_name: %r{^tagger ([^<]+)}.match(tagger)[1].strip,
77 tagger_email: %r{<([^>]+)>}.match(tagger)[1].strip,
78 id: `git rev-parse refs/tags/#{tag}`.chomp!,
84 end.compact.sort { |a,b| b[:time] <=> a[:time] }
87 def xml(dst, tag, text = nil, attrs = nil)
93 attrs = attrs.map { |k,v| "#{k}=#{v.encode(xml: :attr)}" }
94 attrs = "\n#{attrs.join("\n")}"
99 dst << "<#{tag}#{attrs}>"
103 dst << "<#{tag}#{attrs}/>"
106 dst << "<#{tag}#{attrs}>#{text.encode(xml: :text)}</#{tag}>"
110 desc 'prints news as an Atom feed'
111 task "NEWS.atom.xml" do
113 cgit_uri = URI('https://yhbt.net/yahns.git')
114 uri = URI('https://yhbt.net/yahns/')
115 new_tags = tags[0,10]
117 project_name = 'yahns'
118 short_desc = File.readlines('README')[0].split(' - ')[0]
119 new_tags = tags[0,10]
121 atom_uri.path += 'NEWS.atom.xml'
123 news_uri.path += 'NEWS.html'
125 xml(dst, 'feed', xmlns: 'http://www.w3.org/2005/Atom') do
126 xml(dst, 'id', atom_uri.to_s)
127 xml(dst, 'title', "#{project_name} news")
128 xml(dst, 'subtitle', short_desc)
129 xml(dst, 'link', rel: 'alternate', type: 'text/html', href: news_uri.to_s)
130 xml(dst, 'updated', new_tags.empty? ? '1970-01-01:00:00:00Z'
131 : new_tags[0][:time])
132 new_tags.each do |tag|
134 xml(dst, 'title', tag[:subject])
135 xml(dst, 'updated', tag[:time])
136 xml(dst, 'published', tag[:time])
137 xml(dst, 'author') do
138 xml(dst, 'name', tag[:tagger_name])
139 xml(dst, 'email', tag[:tagger_email])
143 uri.query = "id=#{tag[:tag]}"
145 xml(dst, 'link', rel: 'alternate', type: 'text/html', href: uri)
147 xml(dst, 'content', type: 'xhtml') do
148 xml(dst, 'div', xmlns: 'http://www.w3.org/1999/xhtml') do
149 xml(dst, 'pre', tag[:body])
156 fp = Tempfile.new('NEWS.atom.xml', '.')
160 File.utime(time, time, fp.path) if time
161 File.rename(fp.path, 'NEWS.atom.xml')
165 desc 'prints news as a text file'
167 fp = Tempfile.new('NEWS', '.')
171 time ||= tag[:time_obj]
172 line = tag[:subject] + ' / ' + tag[:time].sub(/T.*/, '')
174 fp.puts('-' * line.length)
179 fp.write("Unreleased\n\n") unless fp.size > 0
182 fp.puts "Copyright (C) 2013-2017 all contributors <yahns-public@yhbt.net>"
183 fp.puts "License: GPL-3.0+ <https://www.gnu.org/licenses/gpl-3.0.txt>"
185 File.utime(time, time, fp.path) if time
186 File.rename(fp.path, 'NEWS')