yardbird 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.
- checksums.yaml +4 -4
- data/bin/yardbird +10 -1
- data/lib/yardbird/generator.rb +65 -48
- data/lib/yardbird/version.rb +1 -1
- data/lib/yardbird/writer.rb +9 -6
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 68304b7d6a0c9879c7aa5ed3026679874899f9f7
|
4
|
+
data.tar.gz: 35ab902484d2c65999e35c0ceed295626b6d4513
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3579091f35233db6ccbd1d94f7680056c8543e8c941d3c2f8682b934bab9da212d247ffa7695a4b7e003676d08b85336df99b6b0365db666ff094a064c3abd26
|
7
|
+
data.tar.gz: 33d69dc586b51fa992e29ba50a53856456b39ccd623632f212b0e3a8fb82d2482f56b95da7ff529846b075450df19ffbdc809f9e6fa971bec5935d0eecd6d95a
|
data/bin/yardbird
CHANGED
@@ -14,7 +14,9 @@ Mercenary.program(:yardbird) do |p|
|
|
14
14
|
c.description "Generates from PATH"
|
15
15
|
c.option :outfile, '-o TARGET', '--out TARGET', 'Write to TARGET. Defaults to standard output.'
|
16
16
|
c.option :section_level, '--start-section LEVEL', 'Begin sections at level LEVEL. Default is 0.', Integer
|
17
|
-
|
17
|
+
c.option :toc, '--toc', 'Include table of contents.', TrueClass
|
18
|
+
c.option :title, '--title TITLE', 'Set a title'
|
19
|
+
c.option :yaml, '--yaml KEY=VALUE[,KEY=VALUE...]', 'Add YAML headers (for use with Jekyll)', Array
|
18
20
|
c.action do |args, options|
|
19
21
|
abort "Specify a path." if args.empty?
|
20
22
|
if (file = options[:outfile])
|
@@ -23,7 +25,14 @@ Mercenary.program(:yardbird) do |p|
|
|
23
25
|
stream = $stdout
|
24
26
|
end
|
25
27
|
generator = Yardbird::Generator.new
|
28
|
+
generator.title = options[:title]
|
26
29
|
generator.section_level = options[:section_level]
|
30
|
+
generator.table_of_contents = options[:toc]
|
31
|
+
[options[:yaml]].flatten.each do |s|
|
32
|
+
if s =~ /\A(.*)=(.*)\z/
|
33
|
+
generator.yaml_headers[$1] = $2
|
34
|
+
end
|
35
|
+
end
|
27
36
|
generator.paths |= args
|
28
37
|
generator.generate(stream)
|
29
38
|
end
|
data/lib/yardbird/generator.rb
CHANGED
@@ -10,11 +10,14 @@ module Yardbird
|
|
10
10
|
class Generator
|
11
11
|
|
12
12
|
attr_accessor :paths
|
13
|
-
attr_accessor :options
|
14
13
|
attr_accessor :section_level
|
14
|
+
attr_accessor :table_of_contents
|
15
|
+
attr_accessor :title
|
16
|
+
attr_reader :yaml_headers
|
15
17
|
|
16
18
|
def initialize(options = {})
|
17
19
|
@paths = []
|
20
|
+
@yaml_headers = {}
|
18
21
|
end
|
19
22
|
|
20
23
|
def generate(stream)
|
@@ -22,77 +25,91 @@ module Yardbird
|
|
22
25
|
|
23
26
|
grouped_by_category = endpoints.group_by { |e| e.category }
|
24
27
|
|
25
|
-
|
28
|
+
if @yaml_headers.any?
|
29
|
+
stream.puts "---"
|
30
|
+
@yaml_headers.each do |k, v|
|
31
|
+
stream.puts "#{k}: #{v}"
|
32
|
+
end
|
33
|
+
if @title and not @yaml_headers['title']
|
34
|
+
stream.puts "title: #{@title}"
|
35
|
+
end
|
36
|
+
stream.puts "---"
|
37
|
+
end
|
26
38
|
|
27
|
-
writer.
|
28
|
-
writer.section
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
39
|
+
writer = Writer.new(stream, section_level: @section_level)
|
40
|
+
writer.section @title do
|
41
|
+
if @table_of_contents
|
42
|
+
writer.section "Table of Contents" do
|
43
|
+
categories = grouped_by_category.keys.uniq.sort_by { |s| s.downcase }
|
44
|
+
categories.each do |category|
|
45
|
+
writer.bullet "[#{category}](##{category_anchor_name(category)})"
|
46
|
+
writer.indent(2) do
|
47
|
+
eps = grouped_by_category[category]
|
48
|
+
eps.each do |ep|
|
49
|
+
writer.bullet "[`#{ep.method} #{ep.path}`](##{endpoint_anchor_name(ep)})"
|
50
|
+
end
|
51
|
+
end
|
36
52
|
end
|
37
53
|
end
|
38
54
|
end
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
[param[:types]].flatten.join(', '),
|
55
|
-
param[:type] == 'required' ? ", **required**" : '',
|
56
|
-
")<br/>#{param[:doc]}"
|
57
|
-
writer.blank
|
55
|
+
|
56
|
+
grouped_by_category.each do |category, eps|
|
57
|
+
writer.section category, anchor: category_anchor_name(category) do
|
58
|
+
eps.each do |ep|
|
59
|
+
writer.section "`#{ep.method} #{ep.path}`", anchor: endpoint_anchor_name(ep) do
|
60
|
+
writer.line ep.docstring
|
61
|
+
if ep.params.any?
|
62
|
+
writer.section "Parameters" do
|
63
|
+
ep.params.each do |param|
|
64
|
+
writer.line "`#{param[:name]}` (",
|
65
|
+
[param[:types]].flatten.join(', '),
|
66
|
+
param[:type] == 'required' ? ", **required**" : '',
|
67
|
+
")<br/>#{param[:doc]}"
|
68
|
+
writer.blank
|
69
|
+
end
|
58
70
|
end
|
59
71
|
end
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
writer.blank
|
72
|
+
if ep.status.present?
|
73
|
+
writer.section "Status Codes" do
|
74
|
+
ep.status.each do |s|
|
75
|
+
writer.line "**#{s[:code]}** — #{s[:doc]}"
|
76
|
+
writer.blank
|
77
|
+
end
|
67
78
|
end
|
68
79
|
end
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
80
|
+
if ep.example.present?
|
81
|
+
writer.section "Example" do
|
82
|
+
writer.code_block do
|
83
|
+
writer.line "#{ep.method} #{ep.example} HTTP/1.1"
|
84
|
+
end
|
85
|
+
end
|
74
86
|
end
|
75
87
|
end
|
76
88
|
end
|
77
89
|
end
|
78
90
|
end
|
79
91
|
end
|
80
|
-
|
81
92
|
writer.flush
|
93
|
+
|
82
94
|
stream
|
83
95
|
end
|
84
96
|
|
85
97
|
private
|
86
98
|
|
87
99
|
def category_anchor_name(category)
|
88
|
-
|
100
|
+
if @table_of_contents
|
101
|
+
category.downcase
|
102
|
+
end
|
89
103
|
end
|
90
104
|
|
91
105
|
def endpoint_anchor_name(endpoint)
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
106
|
+
if @endpoint_anchor_name
|
107
|
+
[endpoint.category, endpoint.method, endpoint.path.gsub(/[\/:]/, '-')].
|
108
|
+
join('-').
|
109
|
+
gsub(/-+/, '-').
|
110
|
+
downcase
|
111
|
+
|
112
|
+
end
|
96
113
|
end
|
97
114
|
|
98
115
|
end
|
data/lib/yardbird/version.rb
CHANGED
data/lib/yardbird/writer.rb
CHANGED
@@ -21,12 +21,15 @@ module Yardbird
|
|
21
21
|
@stream.write("\n")
|
22
22
|
end
|
23
23
|
|
24
|
-
def section(title =
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
24
|
+
def section(title, options = {}, &block)
|
25
|
+
if title
|
26
|
+
heading(title, options)
|
27
|
+
@section_level += 1
|
28
|
+
yield
|
29
|
+
@section_level -= 1
|
30
|
+
else
|
31
|
+
yield
|
32
|
+
end
|
30
33
|
end
|
31
34
|
|
32
35
|
def blank
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yardbird
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexander Staubo
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-05-
|
11
|
+
date: 2014-05-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: yard
|