reacco 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/HISTORY.md +9 -0
- data/README.md +87 -3
- data/Rakefile +2 -1
- data/bin/reacco +11 -8
- data/data/index.erb +13 -0
- data/data/style.css +8 -5
- data/lib/reacco.rb +8 -2
- data/lib/reacco/filters/sections.rb +11 -4
- data/lib/reacco/readme.rb +69 -9
- data/lib/reacco/version.rb +1 -1
- metadata +8 -8
data/HISTORY.md
CHANGED
data/README.md
CHANGED
@@ -1,11 +1,95 @@
|
|
1
|
-
# Reacco
|
1
|
+
# [Reacco](http://ricostacruz.com/reacco)
|
2
2
|
#### Readme documentation prettifier
|
3
3
|
|
4
|
-
|
4
|
+
Reacco is a dead simple documentation generator that lets you document your
|
5
|
+
project using Markdown.
|
6
|
+
|
7
|
+
## Usage
|
8
|
+
|
9
|
+
#### Installation
|
10
|
+
Install Reacco first. It is a Ruby gem.
|
11
|
+
|
12
|
+
$ gem install reacco
|
13
|
+
|
14
|
+
#### Generation
|
15
|
+
To generate documentation, type `reacco`. This takes your `README.md` file and
|
16
|
+
prettifies it.
|
17
|
+
|
18
|
+
$ reacco
|
19
|
+
|
20
|
+
#### Literate style blocks
|
21
|
+
To make literate-style blocks (that is, code on the right, explanation on the
|
22
|
+
left), use `reacco --literate`.
|
23
|
+
|
24
|
+
$ reacco --literate
|
25
|
+
|
26
|
+
## Documenting API
|
27
|
+
To extract documentation from your code files, add `--api <path here>`. This
|
28
|
+
extracts comment blocks from files in that path.
|
29
|
+
|
30
|
+
As Reacco only parses out Markdown from your comments, almost all programming
|
31
|
+
languages are supported. It does not care about code at all, just comments.
|
32
|
+
|
33
|
+
$ reacco --literate --api lib/
|
34
|
+
|
35
|
+
#### Documenting classes
|
36
|
+
You will need to add Markdown comment blocks to your code. The first line needs
|
37
|
+
to be a Markdown heading in the form of `### <heading name>`.
|
38
|
+
|
39
|
+
Classes are often made to be H2's.
|
40
|
+
|
41
|
+
``` ruby
|
42
|
+
# ## Reacco [class]
|
43
|
+
# The main class.
|
44
|
+
#
|
45
|
+
# Class documentation goes here in Markdown form.
|
46
|
+
#
|
47
|
+
class Reacco
|
48
|
+
...
|
49
|
+
end
|
50
|
+
```
|
51
|
+
|
52
|
+
#### Documenting class methods
|
53
|
+
Class methods are often made as H3's. Sub-sections are often always H4's.
|
54
|
+
|
55
|
+
``` ruby
|
56
|
+
# ## Reacco [class]
|
57
|
+
# The main class.
|
58
|
+
#
|
59
|
+
class Reacco
|
60
|
+
# ### version [class method]
|
61
|
+
# Returns a string of the library's version.
|
62
|
+
#
|
63
|
+
# #### Example
|
64
|
+
# This example returns the version.
|
65
|
+
#
|
66
|
+
# Reacco.version
|
67
|
+
# #=> "0.0.1"
|
68
|
+
#
|
69
|
+
def self.version
|
70
|
+
...
|
71
|
+
end
|
72
|
+
end
|
73
|
+
```
|
74
|
+
|
75
|
+
#### Adding the placeholder
|
76
|
+
To specify where the docs will be in the README, put a line with the text
|
77
|
+
`[](#api_reference)`. This will tell Reacco where to "inject" your API
|
78
|
+
documentation.
|
79
|
+
|
80
|
+
# README.md:
|
81
|
+
Please see http://you.github.com/project. [](#api_reference)
|
5
82
|
|
6
83
|
# API reference
|
7
84
|
|
8
|
-
|
85
|
+
For usage and API reference, please see http://ricostacruz.com/reacco. [](#api_reference)
|
86
|
+
|
87
|
+
Warning
|
88
|
+
-------
|
89
|
+
|
90
|
+
**Here be dragons!** this is mostly made for my own projects, so I may change
|
91
|
+
things quite often (though I'd try to be mostly API-compatible with older
|
92
|
+
versions).
|
9
93
|
|
10
94
|
Acknowledgements
|
11
95
|
----------------
|
data/Rakefile
CHANGED
@@ -18,7 +18,8 @@ namespace :doc do
|
|
18
18
|
# http://github.com/rstacruz/reacco
|
19
19
|
desc "Builds the documentation into doc/"
|
20
20
|
task :build do
|
21
|
-
|
21
|
+
analytics = "--analytics #{ENV['ANALYTICS_ID']}" if ENV['ANALYTICS_ID']
|
22
|
+
system "reacco -a --github #{gh} #{analytics} --api lib"
|
22
23
|
end
|
23
24
|
|
24
25
|
# http://github.com/rstacruz/git-update-ghpages
|
data/bin/reacco
CHANGED
@@ -27,6 +27,7 @@ if ARGV == ['-h'] || ARGV == ['--help']
|
|
27
27
|
tip " --api PATH Where to get stuff."
|
28
28
|
tip ""
|
29
29
|
tip "More:"
|
30
|
+
tip " --analytics ID Google Analytics ID."
|
30
31
|
tip " --github REPO Adds a 'Fork me on GitHub' badge. Repo should be in"
|
31
32
|
tip " 'username/reponame' format."
|
32
33
|
tip " -o, --output PATH Sets the path to put HTML files in. Defaults to 'doc/'."
|
@@ -35,13 +36,14 @@ if ARGV == ['-h'] || ARGV == ['--help']
|
|
35
36
|
|
36
37
|
else
|
37
38
|
# Build options from arguments.
|
38
|
-
switches
|
39
|
-
docpath
|
40
|
-
template
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
39
|
+
switches = [:literate, :toc]
|
40
|
+
docpath = ARGV.extract('-o') || ARGV.extract('--output') || 'doc'
|
41
|
+
template = ARGV.extract('-t') || ARGV.extract('--template') || nil
|
42
|
+
analytics = ARGV.extract('--analytics') || nil
|
43
|
+
github = ARGV.extract('--github') || nil
|
44
|
+
css = ARGV.extract('--css') || nil
|
45
|
+
awesome = ARGV.delete('-a') || ARGV.extract('--awesome')
|
46
|
+
options = Hash.new
|
45
47
|
|
46
48
|
extract = Array.new
|
47
49
|
while (x = ARGV.extract('--api'))
|
@@ -54,7 +56,8 @@ else
|
|
54
56
|
|
55
57
|
switches.each { |opt| options[opt] = true } if awesome
|
56
58
|
|
57
|
-
options[:github]
|
59
|
+
options[:github] = github if github
|
60
|
+
options[:analytics] = analytics if analytics
|
58
61
|
|
59
62
|
if ARGV.any?
|
60
63
|
puts "Invalid usage. See `reacco --help` for help."
|
data/data/index.erb
CHANGED
@@ -5,6 +5,19 @@
|
|
5
5
|
<title><%= title %></title>
|
6
6
|
<link href="style.css" rel="stylesheet" />
|
7
7
|
<link href='http://fonts.googleapis.com/css?family=Shanti:400|PT+Sans:700,700italic' rel='stylesheet' type='text/css'>
|
8
|
+
<% if analytics %>
|
9
|
+
<script type='text/javascript'>
|
10
|
+
var _gaq = _gaq || [];
|
11
|
+
_gaq.push(['_setAccount', '<%= analytics %>']);
|
12
|
+
_gaq.push(['_trackPageview']);
|
13
|
+
|
14
|
+
(function() {
|
15
|
+
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
|
16
|
+
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
|
17
|
+
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
|
18
|
+
})();
|
19
|
+
</script>
|
20
|
+
<% end %>
|
8
21
|
</head>
|
9
22
|
<body class='<%= body_class %>'>
|
10
23
|
<% if github %>
|
data/data/style.css
CHANGED
@@ -285,7 +285,6 @@ aside#toc {
|
|
285
285
|
aside#toc h1,
|
286
286
|
aside#toc h2,
|
287
287
|
aside#toc h3 {
|
288
|
-
overflow: hidden;
|
289
288
|
margin: 10px 0;
|
290
289
|
padding: 0;
|
291
290
|
font-size: 1.1em; }
|
@@ -295,12 +294,14 @@ aside#toc h1 {
|
|
295
294
|
text-shadow: none;
|
296
295
|
font-size: 1.3em; }
|
297
296
|
|
297
|
+
aside#toc h2,
|
298
298
|
aside#toc h3 {
|
299
299
|
border-top: solid 1px #ddd;
|
300
300
|
padding-top: 10px; }
|
301
301
|
|
302
302
|
aside#toc h2 .type,
|
303
303
|
aside#toc h3 .type {
|
304
|
+
margin-top: 2px;
|
304
305
|
margin-left: 0; }
|
305
306
|
|
306
307
|
aside#toc ul,
|
@@ -315,7 +316,10 @@ aside#toc h3 a {
|
|
315
316
|
color: #333; }
|
316
317
|
|
317
318
|
aside#toc a {
|
319
|
+
height: 1.6em;
|
318
320
|
overflow: hidden;
|
321
|
+
line-height: 1.6em;
|
322
|
+
position: relative;
|
319
323
|
display: block;
|
320
324
|
border-bottom: 0;
|
321
325
|
color: #555; }
|
@@ -324,11 +328,10 @@ aside#toc a span.args {
|
|
324
328
|
display: none; }
|
325
329
|
|
326
330
|
aside#toc a span.type {
|
327
|
-
font-
|
331
|
+
font-weight: normal;
|
332
|
+
color: #999;
|
328
333
|
text-transform: uppercase;
|
329
|
-
|
330
|
-
|
331
|
-
aside#toc .type {
|
334
|
+
font-size: 8pt;
|
332
335
|
float: right; }
|
333
336
|
|
334
337
|
aside#toc::-webkit-scrollbar {
|
data/lib/reacco.rb
CHANGED
@@ -14,14 +14,20 @@ module Reacco
|
|
14
14
|
# Returns the root path of the Reacco gem.
|
15
15
|
# You may pass additional parameters.
|
16
16
|
#
|
17
|
-
# Reacco.root
|
17
|
+
# Reacco.root
|
18
|
+
# #=> '/usr/local/ruby/gems/reacco-0.0.1'
|
18
19
|
#
|
19
20
|
def root(*a)
|
20
21
|
File.join File.expand_path('../../', __FILE__), *a
|
21
22
|
end
|
22
23
|
|
23
24
|
# ### markdown [class method]
|
24
|
-
# Returns the Redcarpet Markdown processor.
|
25
|
+
# Returns the Redcarpet Markdown processor. This is an instance of
|
26
|
+
# `Redcarpet` with all the right options plugged in.
|
27
|
+
#
|
28
|
+
# Reacco.markdown
|
29
|
+
# #=> #<Redcarpet::Markdown ...>
|
30
|
+
#
|
25
31
|
def markdown
|
26
32
|
Redcarpet::Markdown.new(Redcarpet::Render::HTML,
|
27
33
|
:fenced_code_blocks => true)
|
@@ -3,7 +3,8 @@ module Reacco
|
|
3
3
|
module Sections
|
4
4
|
# Wraps in sections.
|
5
5
|
def section_wrap(html)
|
6
|
-
%w(h1 h2 h3 h4 h5)
|
6
|
+
headings = %w(h1 h2 h3 h4 h5)
|
7
|
+
headings.each do |h|
|
7
8
|
nodes = html.css(h)
|
8
9
|
nodes.each do |alpha|
|
9
10
|
# For those affected by --hgroup, don't bother.
|
@@ -11,7 +12,7 @@ module Reacco
|
|
11
12
|
next unless alpha.parent
|
12
13
|
|
13
14
|
# Find the boundary, and get the nodes until that one.
|
14
|
-
omega = from_x_until(alpha, alpha.name)
|
15
|
+
omega = from_x_until(alpha, *headings[0..headings.index(alpha.name)])
|
15
16
|
section_nodes = between(alpha, omega)
|
16
17
|
|
17
18
|
# Create the <section>.
|
@@ -26,13 +27,19 @@ module Reacco
|
|
26
27
|
end
|
27
28
|
|
28
29
|
private
|
29
|
-
def from_x_until(alpha,
|
30
|
+
def from_x_until(alpha, *names)
|
30
31
|
omega = nil
|
31
32
|
n = alpha
|
32
33
|
|
33
34
|
while true
|
34
35
|
n = n.next_sibling
|
35
|
-
break if n.nil?
|
36
|
+
break if n.nil?
|
37
|
+
|
38
|
+
name = n.name
|
39
|
+
if name == 'section'
|
40
|
+
name = (h = n.at_css('h1, h2, h3, h4, h5, h6')) && h.name
|
41
|
+
end
|
42
|
+
break if !name || names.include?(name)
|
36
43
|
omega = n
|
37
44
|
end
|
38
45
|
|
data/lib/reacco/readme.rb
CHANGED
@@ -1,5 +1,21 @@
|
|
1
1
|
# ## Reacco::Readme [class]
|
2
2
|
# A readme file.
|
3
|
+
#
|
4
|
+
# #### Instanciating
|
5
|
+
# This is often instanciated by the `reacco` executable, but you can instantiate
|
6
|
+
# it yourself like so. It's assumed the the base dir will be the current working
|
7
|
+
# directory.
|
8
|
+
#
|
9
|
+
# readme = Reacco::Readme.new
|
10
|
+
# readme = Reacco::Readme.new [OPTIONS HASH]
|
11
|
+
#
|
12
|
+
# #### Options
|
13
|
+
# Avaiable options are *(all are optional)*:
|
14
|
+
#
|
15
|
+
# * `file` - String *(the filename of the README file)*
|
16
|
+
# * `literate` - Boolean
|
17
|
+
# * `toc` - Boolean
|
18
|
+
#
|
3
19
|
module Reacco
|
4
20
|
class Readme
|
5
21
|
def initialize(options={})
|
@@ -8,7 +24,10 @@ module Reacco
|
|
8
24
|
end
|
9
25
|
|
10
26
|
# ### file [method]
|
11
|
-
# The path to the README file. Returns nil if not available.
|
27
|
+
# The path to the README file. Returns `nil` if not available.
|
28
|
+
#
|
29
|
+
# readme.file #=> "README.md"
|
30
|
+
#
|
12
31
|
def file
|
13
32
|
@file ||= (Dir['README.*'].first || Dir['readme.*'].first || Dir['README'].first)
|
14
33
|
end
|
@@ -18,25 +37,42 @@ module Reacco
|
|
18
37
|
end
|
19
38
|
|
20
39
|
# ### switches [method]
|
21
|
-
# The switches, like
|
40
|
+
# The switches, like *literate* and *toc*. Returns an array of strings.
|
41
|
+
#
|
42
|
+
# readme.switches #=> [ 'literate' ]
|
22
43
|
def switches
|
23
44
|
@options.keys.map { |k| k.to_s }
|
24
45
|
end
|
25
46
|
|
26
47
|
# ### exists? [method]
|
27
48
|
# Returns true if the file (given in the constructor) exists.
|
49
|
+
#
|
50
|
+
# readme = Readme.new :file => 'non-existent-file.txt'
|
51
|
+
# readme.exists?
|
52
|
+
# #=> false (maybe)
|
53
|
+
#
|
28
54
|
def exists?
|
29
55
|
file && File.exists?(file)
|
30
56
|
end
|
31
57
|
|
32
58
|
# ### raw [method]
|
33
59
|
# Returns raw Markdown markup.
|
60
|
+
#
|
61
|
+
# readme.raw
|
62
|
+
# #=> "# My project\n#### This is my project\n\n..."
|
63
|
+
#
|
34
64
|
def raw
|
35
65
|
@raw ||= File.read(file)
|
36
66
|
end
|
37
67
|
|
38
68
|
# ### title [method]
|
39
|
-
# Returns a string of the title of the document
|
69
|
+
# Returns a string of the title of the document. Often, this is the first
|
70
|
+
# H1, but if that's not available, then it is inferred from the current
|
71
|
+
# directory's name.
|
72
|
+
#
|
73
|
+
# readme.title
|
74
|
+
# #=> "My project"
|
75
|
+
#
|
40
76
|
def title
|
41
77
|
@title ||= begin
|
42
78
|
h1 = (h1 = doc.at_css('h1')) && h1.text
|
@@ -49,7 +85,12 @@ module Reacco
|
|
49
85
|
end
|
50
86
|
|
51
87
|
# ### raw_html [method]
|
52
|
-
#
|
88
|
+
# Returns a string of the raw HTML data built from the markdown source.
|
89
|
+
# This does not have the transformations applied to it yet.
|
90
|
+
#
|
91
|
+
# readme.raw_html
|
92
|
+
# #=> "<h1>My project</h1>..."
|
93
|
+
#
|
53
94
|
def raw_html
|
54
95
|
@raw_html ||= markdown.render(raw)
|
55
96
|
end
|
@@ -60,6 +101,7 @@ module Reacco
|
|
60
101
|
|
61
102
|
# ### inject_api_block [method]
|
62
103
|
# Adds an API block. Takes an `html` argument.
|
104
|
+
#
|
63
105
|
def inject_api_block(html)
|
64
106
|
@api_blocks = "#{api_blocks}\n#{html}\n"
|
65
107
|
end
|
@@ -68,8 +110,12 @@ module Reacco
|
|
68
110
|
@api_blocks ||= ""
|
69
111
|
end
|
70
112
|
|
71
|
-
# ### doc [method]
|
72
|
-
# Returns HTML as a Nokogiri document.
|
113
|
+
# ### doc([options]) [method]
|
114
|
+
# Returns HTML as a Nokogiri document with all the transformations applied.
|
115
|
+
#
|
116
|
+
# readme.doc
|
117
|
+
# #=> #<Nokogiri::HTML ...>
|
118
|
+
#
|
73
119
|
def doc(options={})
|
74
120
|
@doc ||= begin
|
75
121
|
add_api(api_blocks)
|
@@ -88,21 +134,35 @@ module Reacco
|
|
88
134
|
end
|
89
135
|
|
90
136
|
# ### html [method]
|
91
|
-
# Returns body's inner HTML.
|
137
|
+
# Returns body's inner HTML *with* transformatinos.
|
138
|
+
#
|
139
|
+
# readme.raw_html
|
140
|
+
# #=> "<h1>My project</h1>..."
|
141
|
+
#
|
92
142
|
def html
|
93
143
|
doc.at_css('body').inner_html
|
94
144
|
end
|
95
145
|
|
96
146
|
# ### github [method]
|
97
147
|
# Returns the GitHub URL, or nil if not applicable.
|
148
|
+
#
|
149
|
+
# readme.github
|
150
|
+
# #=> "https://github.com/rstacruz/reacco"
|
151
|
+
#
|
98
152
|
def github
|
99
153
|
"https://github.com/#{@options[:github]}" if @options[:github]
|
100
154
|
end
|
101
155
|
|
102
|
-
#
|
156
|
+
# ### locals [method]
|
157
|
+
# Returns a hash with the local variables to be used for the ERB template.
|
158
|
+
#
|
159
|
+
# readme.locals
|
160
|
+
# #=> { :title => 'My project', ... }
|
161
|
+
#
|
103
162
|
def locals
|
104
163
|
{ :title => title,
|
105
164
|
:body_class => switches.join(' '),
|
165
|
+
:analytics => @options[:analytics],
|
106
166
|
:github => github }
|
107
167
|
end
|
108
168
|
|
@@ -118,7 +178,7 @@ module Reacco
|
|
118
178
|
# Puts `blocks` inside `raw_html`.
|
119
179
|
def add_api(blocks)
|
120
180
|
re1 = %r{^.*api reference goes here.*$}i
|
121
|
-
re2 = %r{
|
181
|
+
re2 = %r{^.*href=['"]#api_reference['"].*$}i
|
122
182
|
|
123
183
|
if raw_html =~ re1
|
124
184
|
raw_html.gsub! re1, blocks
|
data/lib/reacco/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: reacco
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-09-
|
12
|
+
date: 2011-09-19 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: redcarpet
|
16
|
-
requirement: &
|
16
|
+
requirement: &2156896460 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 2.0.0b3
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *2156896460
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: nokogiri
|
27
|
-
requirement: &
|
27
|
+
requirement: &2156895880 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '1.5'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *2156895880
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: tilt
|
38
|
-
requirement: &
|
38
|
+
requirement: &2156895460 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,7 +43,7 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *2156895460
|
47
47
|
description: Reacco makes your readme's pretty.
|
48
48
|
email:
|
49
49
|
- rico@sinefunc.com
|