wrongdoc 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,68 @@
1
+ # we won't deal with the non-Darkfish RDoc in older rubies, it has frames :<
2
+ if (!defined?(RUBY_ENGINE) || RUBY_ENGINE == "ruby") && \
3
+ RUBY_VERSION.to_f <= 1.8
4
+ require 'rubygems'
5
+ gem 'rdoc', '~> 3.0.1'
6
+ end
7
+ require 'rdoc/rdoc'
8
+
9
+ class Wrongdoc::Rdoc
10
+ include Wrongdoc::RdocOptions
11
+ include Wrongdoc::ParseXML
12
+
13
+ def initialize(opts)
14
+ @rdoc_uri = URI.parse(opts[:rdoc_url])
15
+ @cgit_uri = URI.parse(opts[:cgit_url])
16
+ end
17
+
18
+ def run(argv = [])
19
+ rdoc(argv)
20
+ add_atom("doc/ChangeLog.html", cgit_atom_uri)
21
+ add_atom("doc/NEWS.html", news_atom_uri)
22
+ add_atom("doc/README.html", news_atom_uri)
23
+
24
+ # the stock RDoc index page layout lacks a vertical sidebar full of links
25
+ rdoc_index = "doc/rdoc_index.html"
26
+ File.exist?(rdoc_index) and File.unlink(rdoc_index)
27
+ File.rename("doc/index.html", rdoc_index)
28
+ File.link("doc/README.html", "doc/index.html")
29
+ end
30
+
31
+ def rdoc(argv)
32
+ r = RDoc::RDoc.new
33
+ r.document(rdoc_options.concat(argv))
34
+ end
35
+
36
+ def add_atom(path, atom_uri)
37
+ File.open(path, "a+") do |fp|
38
+ doc = parse_xml(fp.read)
39
+ doc.search("title").each { |t|
40
+ t.add_next_sibling(atom_node(doc, atom_uri))
41
+ }
42
+ fp.truncate 0
43
+ fp.write doc.to_xhtml
44
+ end
45
+ end
46
+
47
+ def cgit_atom_uri
48
+ uri = @cgit_uri.dup
49
+ uri.path += "/atom/"
50
+ uri.query = "h=master"
51
+ uri
52
+ end
53
+
54
+ def news_atom_uri
55
+ uri = @rdoc_uri.dup
56
+ uri.path += "NEWS.atom.xml"
57
+ uri
58
+ end
59
+
60
+ def atom_node(doc, uri, title = 'Atom feed')
61
+ link = Nokogiri::XML::Node.new('link', doc)
62
+ link['rel'] = 'alternate'
63
+ link['title'] = title
64
+ link['href'] = uri.to_s
65
+ link['type'] = 'application/atom+xml'
66
+ link
67
+ end
68
+ end
@@ -0,0 +1,11 @@
1
+ module Wrongdoc::RdocOptions
2
+ include Wrongdoc::Readme
3
+
4
+ def rdoc_options
5
+ webcvs = URI.parse(Wrongdoc.config[:cgit_url])
6
+ webcvs.path += "/tree"
7
+ webcvs = "#{webcvs}/%s"
8
+ _, _, title = readme_metadata
9
+ [ '-t', title, '-W', webcvs ]
10
+ end
11
+ end
@@ -0,0 +1,20 @@
1
+ # helpers for parsing the top-level README file (no suffix support :P)
2
+ module Wrongdoc::Readme
3
+
4
+ # returns a one-paragraph summary from the README
5
+ def readme_description
6
+ File.read("README").split(/\n\n/)[1]
7
+ end
8
+
9
+ # parses the README file in the top-level directory for project metadata
10
+ def readme_metadata
11
+ l = File.readlines("README")[0].strip!
12
+ l.gsub!(/^=\s+/, '') or abort "#{l.inspect} doesn't start with '='"
13
+ title = l.dup
14
+ if l.gsub!(/^(\w+\!)\s+/, '') # Rainbows!
15
+ return $1, l, title
16
+ else
17
+ return (l.split(/\s*[:-]\s*/, 2)).push(title)
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,44 @@
1
+ module Wrongdoc::Release
2
+ self.extend Wrongdoc::History
3
+
4
+ def self.changes(io)
5
+ vtags = tags.map { |tag| tag[:tag] =~ /\Av/ and tag[:tag] }.sort
6
+ cmds = []
7
+ if vtags.empty?
8
+ cmds << %w(git log)
9
+ else
10
+ version = vtags[0]
11
+ prev = vtags[vtags.index(version) - 1]
12
+ if prev
13
+ cmds << [ 'git', 'diff', '--stat', prev, version ]
14
+ cmds << [ 'git', 'log', "#{prev}..#{version}" ]
15
+ else
16
+ cmds << [ 'git', 'log', version ]
17
+ end
18
+ end
19
+
20
+ io.sync = true
21
+ cmds.each_with_index do |cmd,i|
22
+ i > 0 and io.puts
23
+ pid, status = Process.waitpid2(fork do
24
+ $stdout.reopen(io)
25
+ io.close
26
+ exec *cmd
27
+ end)
28
+ status.success? or abort status.inspect
29
+ end
30
+ end
31
+
32
+ def self.notes(io, opts)
33
+ spec = Gem::Specification.load(Dir['*.gemspec'][0])
34
+ io.puts spec.description.strip
35
+ io.puts
36
+ io.puts "* #{spec.homepage}"
37
+ io.puts "* #{spec.email}"
38
+ io.puts "* #{opts[:git_url] || opts[:cgit_url]}"
39
+
40
+ _, _, body = `git cat-file tag v#{spec.version}`.split(/\n\n/, 3)
41
+ io.print "\nChanges:\n\n"
42
+ io.puts body
43
+ end
44
+ end
data/lib/wrongdoc.rb ADDED
@@ -0,0 +1,35 @@
1
+ require 'tempfile'
2
+ require 'uri'
3
+ require 'yaml'
4
+ require 'tidy_ffi'
5
+ require 'nokogiri'
6
+
7
+ module Wrongdoc
8
+
9
+ # the version of wrongdoc, currently 1.0.0
10
+ VERSION = '1.0.0'
11
+
12
+ autoload :Readme, 'wrongdoc/readme'
13
+ autoload :History, 'wrongdoc/history'
14
+ autoload :Release, 'wrongdoc/release'
15
+
16
+ autoload :Changelog, 'wrongdoc/changelog'
17
+ autoload :NewsRdoc, 'wrongdoc/news_rdoc'
18
+ autoload :NewsAtom, 'wrongdoc/news_atom'
19
+ autoload :ParseXML, 'wrongdoc/parse_xml'
20
+
21
+ autoload :Prepare, 'wrongdoc/prepare'
22
+ autoload :Rdoc, 'wrongdoc/rdoc'
23
+ autoload :Merge, 'wrongdoc/merge'
24
+ autoload :Final, 'wrongdoc/final'
25
+
26
+ autoload :Gemspec, 'wrongdoc/gemspec'
27
+ autoload :RdocOptions, 'wrongdoc/rdoc_options'
28
+
29
+ def self.config(path = ".wrongdoc.yml")
30
+ File.exist?(path) or abort "#{path} not found in current directory"
31
+ opts = YAML.load(File.read(path))
32
+ opts.keys.each { |k| opts[k.to_sym] = opts.delete(k) } # symbolize keys
33
+ opts
34
+ end
35
+ end
@@ -0,0 +1,19 @@
1
+ .\" generated with Ronn/v0.7.3
2
+ .\" http://github.com/rtomayko/ronn/tree/0.7.3
3
+ .
4
+ .TH "WRONGDOC" "1" "December 2010" "" ""
5
+ .
6
+ .SH "NAME"
7
+ \fBwrongdoc\fR \- removes JavaScript from RDoc
8
+ .
9
+ .SH "SYNOPSIS"
10
+ \fBwrongdoc\fR prepare
11
+ .
12
+ .P
13
+ \fBwrongdoc\fR
14
+ .
15
+ .SH "DESCRIPTION"
16
+ \fBWrongdoc\fR does horrible things to your RDoc project\. It\'s own documentation sucks, but it\'ll help to make your documentation JavaScript\-free and therefore suck less :)
17
+ .
18
+ .SH "SEE ALSO"
19
+ dotwrongdoc(5)
@@ -0,0 +1,22 @@
1
+ .\" generated with Ronn/v0.7.3
2
+ .\" http://github.com/rtomayko/ronn/tree/0.7.3
3
+ .
4
+ .TH "DOTWRONGDOC" "5" "December 2010" "" ""
5
+ .
6
+ .SH "NAME"
7
+ \fBdotwrongdoc\fR \- wrongdoc config file format
8
+ .
9
+ .SH "SYNOPSIS"
10
+ A YAML file in the top\-level project directory named "\.wrongdoc\.yml"
11
+ .
12
+ .SH "DESCRIPTION"
13
+ As wrongdoc favors consistency over configuration, there is minimal configuration to deal with\.
14
+ .
15
+ .SH "KEYS"
16
+ \fBrdoc_url\fR, \fBcgit_url\fR should be obvious
17
+ .
18
+ .P
19
+ \fBmerge_html\fR is a key\-value mapping of (empty) RDoc source files to an HTML file that will be merged into RDoc after\-the\-fact\. It is useful for merging non\-RDoc generated HTML into the project\.
20
+ .
21
+ .SH "SEE ALSO"
22
+ wrongdoc(1)