yardbird 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c462a82143467e59909e2bb11fd44140f059fe78
4
- data.tar.gz: e56a4d6754f264b887dd544b9d2d447b48375796
3
+ metadata.gz: 68304b7d6a0c9879c7aa5ed3026679874899f9f7
4
+ data.tar.gz: 35ab902484d2c65999e35c0ceed295626b6d4513
5
5
  SHA512:
6
- metadata.gz: 9dcf3f085302c37755dea9461ef4ff6f6839c2e3bbc0a0fda15ea0b706f7d47f9bced024dabefe8935a85165142e7de668d01055a995650edf19b339e4d10c1f
7
- data.tar.gz: 71349277759eec01bf424df58bf4b19aaf6dfae1f736c1ccebc8e206a126a2848ac41ad3dada9c4892600dcc802a22c1103a1c9bb81953cc5fda953e2823e75e
6
+ metadata.gz: 3579091f35233db6ccbd1d94f7680056c8543e8c941d3c2f8682b934bab9da212d247ffa7695a4b7e003676d08b85336df99b6b0365db666ff094a064c3abd26
7
+ data.tar.gz: 33d69dc586b51fa992e29ba50a53856456b39ccd623632f212b0e3a8fb82d2482f56b95da7ff529846b075450df19ffbdc809f9e6fa971bec5935d0eecd6d95a
@@ -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
@@ -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
- writer = Writer.new(stream, section_level: @section_level)
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.line "<section id='toc'>"
28
- writer.section "Table of Contents" do
29
- categories = grouped_by_category.keys.uniq.sort_by { |s| s.downcase }
30
- categories.each do |category|
31
- writer.bullet "[#{category}](##{category_anchor_name(category)})"
32
- writer.indent(2) do
33
- eps = grouped_by_category[category]
34
- eps.each do |ep|
35
- writer.bullet "[`#{ep.method} #{ep.path}`](##{endpoint_anchor_name(ep)})"
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
- end
40
- writer.line "</section>"
41
-
42
- grouped_by_category.each do |category, eps|
43
- writer.heading category, anchor: category_anchor_name(category)
44
- writer.section do
45
- eps.each do |ep|
46
- writer.heading "`#{ep.method} #{ep.path}`", anchor: endpoint_anchor_name(ep)
47
- writer.section do
48
- writer.line ep.docstring
49
- if ep.params.any?
50
- writer.heading "Parameters"
51
- writer.section do
52
- ep.params.each do |param|
53
- writer.line "`#{param[:name]}` (",
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
- end
61
- if ep.status.present?
62
- writer.heading "Status Codes"
63
- writer.section do
64
- ep.status.each do |s|
65
- writer.line "**#{s[:code]}** — #{s[:doc]}"
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
- end
70
- if ep.example.present?
71
- writer.heading "Example"
72
- writer.code_block do
73
- writer.line "#{ep.method} #{ep.example} HTTP/1.1"
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
- category.downcase
100
+ if @table_of_contents
101
+ category.downcase
102
+ end
89
103
  end
90
104
 
91
105
  def endpoint_anchor_name(endpoint)
92
- [endpoint.category, endpoint.method, endpoint.path.gsub(/[\/:]/, '-')].
93
- join('-').
94
- gsub(/-+/, '-').
95
- downcase
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
@@ -1,3 +1,3 @@
1
1
  module Yardbird
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -21,12 +21,15 @@ module Yardbird
21
21
  @stream.write("\n")
22
22
  end
23
23
 
24
- def section(title = nil, &block)
25
- heading(title) if title
26
-
27
- @section_level += 1
28
- yield
29
- @section_level -= 1
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.2
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-14 00:00:00.000000000 Z
11
+ date: 2014-05-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: yard