Skip to content

Commit 378c01a

Browse files
committed
Merge pull request puppetlabs#157 from eputnam/pdoc-184_2
(maint) do not display name if there is nothing to display
2 parents 0b1a095 + 65bfdaf commit 378c01a

File tree

13 files changed

+150
-44
lines changed

13 files changed

+150
-44
lines changed

lib/puppet-strings/markdown/base.rb

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,8 @@ def toc_info
127127
{
128128
name: name.to_s,
129129
link: link,
130-
desc: summary || @registry[:docstring][:text].gsub("\n", ". ")
130+
desc: summary || @registry[:docstring][:text][0..140].gsub("\n",' '),
131+
private: private?
131132
}
132133
end
133134

@@ -149,6 +150,15 @@ def value_string(value)
149150
end
150151
end
151152

153+
def private?
154+
result = false
155+
api = @tags.find { |tag| tag[:tag_name] == 'api' }
156+
unless api.nil?
157+
result = api[:text] == 'private' ? true : false
158+
end
159+
result
160+
end
161+
152162
# @return [String] full markdown rendering of a component
153163
def render(template)
154164
file = File.join(File.dirname(__FILE__),"templates/#{template}")

lib/puppet-strings/markdown/defined_types.rb

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,30 @@ module DefinedTypes
55

66
# @return [Array] list of defined types
77
def self.in_dtypes
8-
YARD::Registry.all(:puppet_defined_type).sort_by!(&:name).map!(&:to_hash)
8+
arr = YARD::Registry.all(:puppet_defined_type).sort_by!(&:name).map!(&:to_hash)
9+
arr.map! { |a| PuppetStrings::Markdown::DefinedType.new(a) }
10+
end
11+
12+
def self.contains_private?
13+
result = false
14+
unless in_dtypes.nil?
15+
in_dtypes.find { |type| type.private? }.nil? ? false : true
16+
end
917
end
1018

1119
def self.render
1220
final = in_dtypes.length > 0 ? "## Defined types\n\n" : ""
1321
in_dtypes.each do |type|
14-
final << PuppetStrings::Markdown::DefinedType.new(type).render
22+
final << type.render unless type.private?
1523
end
1624
final
1725
end
1826

1927
def self.toc_info
20-
final = []
28+
final = ["Defined types"]
2129

2230
in_dtypes.each do |type|
23-
final.push(PuppetStrings::Markdown::DefinedType.new(type).toc_info)
31+
final.push(type.toc_info)
2432
end
2533

2634
final

lib/puppet-strings/markdown/functions.rb

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,30 @@ module Functions
55

66
# @return [Array] list of functions
77
def self.in_functions
8-
YARD::Registry.all(:puppet_function).sort_by!(&:name).map!(&:to_hash)
8+
arr = YARD::Registry.all(:puppet_function).sort_by!(&:name).map!(&:to_hash)
9+
arr.map! { |a| PuppetStrings::Markdown::Function.new(a) }
10+
end
11+
12+
def self.contains_private?
13+
result = false
14+
unless in_functions.nil?
15+
in_functions.find { |func| func.private? }.nil? ? false : true
16+
end
917
end
1018

1119
def self.render
1220
final = in_functions.length > 0 ? "## Functions\n\n" : ""
1321
in_functions.each do |func|
14-
final << PuppetStrings::Markdown::Function.new(func).render
22+
final << func.render unless func.private?
1523
end
1624
final
1725
end
1826

1927
def self.toc_info
20-
final = []
28+
final = ["Functions"]
2129

2230
in_functions.each do |func|
23-
final.push(PuppetStrings::Markdown::Function.new(func).toc_info)
31+
final.push(func.toc_info)
2432
end
2533

2634
final

lib/puppet-strings/markdown/puppet_classes.rb

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,30 @@ module PuppetClasses
55

66
# @return [Array] list of classes
77
def self.in_classes
8-
YARD::Registry.all(:puppet_class).sort_by!(&:name).map!(&:to_hash)
8+
arr = YARD::Registry.all(:puppet_class).sort_by!(&:name).map!(&:to_hash)
9+
arr.map! { |a| PuppetStrings::Markdown::PuppetClass.new(a) }
10+
end
11+
12+
def self.contains_private?
13+
result = false
14+
unless in_classes.nil?
15+
in_classes.find { |klass| klass.private? }.nil? ? false : true
16+
end
917
end
1018

1119
def self.render
1220
final = in_classes.length > 0 ? "## Classes\n\n" : ""
1321
in_classes.each do |klass|
14-
final << PuppetStrings::Markdown::PuppetClass.new(klass).render
22+
final << klass.render unless klass.private?
1523
end
1624
final
1725
end
1826

1927
def self.toc_info
20-
final = []
28+
final = ["Classes"]
2129

2230
in_classes.each do |klass|
23-
final.push(PuppetStrings::Markdown::PuppetClass.new(klass).toc_info)
31+
final.push(klass.toc_info)
2432
end
2533

2634
final

lib/puppet-strings/markdown/resource_types.rb

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,30 @@ module ResourceTypes
55

66
# @return [Array] list of resource types
77
def self.in_rtypes
8-
YARD::Registry.all(:puppet_type).sort_by!(&:name).map!(&:to_hash)
8+
arr = YARD::Registry.all(:puppet_type).sort_by!(&:name).map!(&:to_hash)
9+
arr.map! { |a| PuppetStrings::Markdown::ResourceType.new(a) }
10+
end
11+
12+
def self.contains_private?
13+
result = false
14+
unless in_rtypes.nil?
15+
in_rtypes.find { |type| type.private? }.nil? ? false : true
16+
end
917
end
1018

1119
def self.render
1220
final = in_rtypes.length > 0 ? "## Resource types\n\n" : ""
1321
in_rtypes.each do |type|
14-
final << PuppetStrings::Markdown::ResourceType.new(type).render
22+
final << type.render unless type.private?
1523
end
1624
final
1725
end
1826

1927
def self.toc_info
20-
final = []
28+
final = ["Resource types"]
2129

2230
in_rtypes.each do |type|
23-
final.push(PuppetStrings::Markdown::ResourceType.new(type).toc_info)
31+
final.push(type.toc_info)
2432
end
2533

2634
final
Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,21 @@
11
module PuppetStrings::Markdown
22
module TableOfContents
33
def self.render
4-
puppet_classes = PuppetStrings::Markdown::PuppetClasses.toc_info
5-
puppet_defined_types = PuppetStrings::Markdown::DefinedTypes.toc_info
6-
puppet_resource_types = PuppetStrings::Markdown::ResourceTypes.toc_info
7-
puppet_functions = PuppetStrings::Markdown::Functions.toc_info
4+
final = ""
85

9-
template = File.join(File.dirname(__FILE__),"templates/table_of_contents.erb")
10-
ERB.new(File.read(template), nil, '-').result(binding)
6+
[PuppetStrings::Markdown::PuppetClasses,
7+
PuppetStrings::Markdown::DefinedTypes,
8+
PuppetStrings::Markdown::ResourceTypes,
9+
PuppetStrings::Markdown::Functions].each do |r|
10+
toc = r.toc_info
11+
group_name = toc.shift
12+
group = toc
13+
priv = r.contains_private?
14+
15+
template = File.join(File.dirname(__FILE__),"templates/table_of_contents.erb")
16+
final << ERB.new(File.read(template), nil, '-').result(binding)
17+
end
18+
final
1119
end
1220
end
1321
end

lib/puppet-strings/markdown/templates/classes_and_defines.erb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
### <%= name %>
22

3+
<% if text -%>
4+
<%= text %>
5+
6+
<% elsif summary -%>
7+
<%= summary %>
8+
9+
<% else -%>
10+
<%= "The #{name} class." %>
11+
12+
<% end -%>
313
<% if since -%>
414
* **Since** <%= since %>
515

lib/puppet-strings/markdown/templates/function.erb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
### <%= name %>
22
Type: <%= type %>
33

4+
<% if text -%>
5+
<%= text %>
6+
7+
<% elsif summary -%>
8+
<%= summary %>
9+
10+
<% else -%>
11+
<%= "The #{name} class." %>
12+
13+
<% end -%>
414
<% signatures.each do |sig| -%>
515
#### `<%= sig.signature %>`
616

lib/puppet-strings/markdown/templates/resource_type.erb

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
### <%= name %>
22

3+
<% if text -%>
4+
<%= text %>
5+
6+
<% elsif summary -%>
7+
<%= summary %>
8+
9+
<% else -%>
10+
<%= "The #{name} type." %>
11+
12+
<% end -%>
313
<% if since -%>
414
* **Since** <%= since %>
515

@@ -12,9 +22,6 @@
1222
<% end -%>
1323

1424
<% end -%>
15-
<% if text -%>
16-
<%= text %>
17-
<% end %>
1825
<% if examples -%>
1926
#### Examples
2027
<% examples.each do |eg| -%>
Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,21 @@
1-
<% if puppet_classes.length > 0 -%>
2-
## Classes
3-
<% puppet_classes.each do |klassy| -%>
4-
* [`<%= klassy[:name] %>`](#<%= klassy[:link] %>): <%= klassy[:desc] %>
1+
<% if group.length > 0 -%>
2+
## <%= group_name %>
3+
<% if priv -%>
4+
### Public <%= group_name %>
5+
<% group.each do |item| -%>
6+
<% unless item[:private] -%>
7+
* [`<%= item[:name] %>`](#<%= item[:link] %>): <%= item[:desc] %>
58
<% end -%>
69
<% end -%>
7-
<% if puppet_defined_types.length > 0 -%>
8-
## Defined types
9-
<% puppet_defined_types.each do |dtype| -%>
10-
* [`<%= dtype[:name] %>`](#<%= dtype[:link] %>): <%= dtype[:desc] %>
10+
### Private <%= group_name %>
11+
<% group.each do |item| -%>
12+
<% if item[:private] -%>
13+
* `<%= item[:name] %>`: <%= item[:desc] %>
1114
<% end -%>
1215
<% end -%>
13-
<% if puppet_resource_types.length > 0 -%>
14-
## Resource types
15-
<% puppet_resource_types.each do |rtype| -%>
16-
* [`<%= rtype[:name] %>`](#<%= rtype[:link] %>): <%= rtype[:desc] %>
16+
<% else -%>
17+
<% group.each do |item| -%>
18+
* [`<%= item[:name] %>`](#<%= item[:link] %>): <%= item[:desc] %>
1719
<% end -%>
1820
<% end -%>
19-
<% if puppet_functions.length > 0 -%>
20-
## Functions
21-
<% puppet_functions.each do |func| -%>
22-
* [`<%= func[:name] %>`](#<%= func[:link] %>): <%= func[:desc] %>
23-
<% end -%>
2421
<% end -%>

0 commit comments

Comments
 (0)