Merge pull request #157 from eputnam/pdoc-184_2
(maint) do not display name if there is nothing to display
This commit is contained in:
commit
378c01a719
|
@ -127,7 +127,8 @@ module PuppetStrings::Markdown
|
||||||
{
|
{
|
||||||
name: name.to_s,
|
name: name.to_s,
|
||||||
link: link,
|
link: link,
|
||||||
desc: summary || @registry[:docstring][:text].gsub("\n", ". ")
|
desc: summary || @registry[:docstring][:text][0..140].gsub("\n",' '),
|
||||||
|
private: private?
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -149,6 +150,15 @@ module PuppetStrings::Markdown
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def private?
|
||||||
|
result = false
|
||||||
|
api = @tags.find { |tag| tag[:tag_name] == 'api' }
|
||||||
|
unless api.nil?
|
||||||
|
result = api[:text] == 'private' ? true : false
|
||||||
|
end
|
||||||
|
result
|
||||||
|
end
|
||||||
|
|
||||||
# @return [String] full markdown rendering of a component
|
# @return [String] full markdown rendering of a component
|
||||||
def render(template)
|
def render(template)
|
||||||
file = File.join(File.dirname(__FILE__),"templates/#{template}")
|
file = File.join(File.dirname(__FILE__),"templates/#{template}")
|
||||||
|
|
|
@ -5,22 +5,30 @@ module PuppetStrings::Markdown
|
||||||
|
|
||||||
# @return [Array] list of defined types
|
# @return [Array] list of defined types
|
||||||
def self.in_dtypes
|
def self.in_dtypes
|
||||||
YARD::Registry.all(:puppet_defined_type).sort_by!(&:name).map!(&:to_hash)
|
arr = YARD::Registry.all(:puppet_defined_type).sort_by!(&:name).map!(&:to_hash)
|
||||||
|
arr.map! { |a| PuppetStrings::Markdown::DefinedType.new(a) }
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.contains_private?
|
||||||
|
result = false
|
||||||
|
unless in_dtypes.nil?
|
||||||
|
in_dtypes.find { |type| type.private? }.nil? ? false : true
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.render
|
def self.render
|
||||||
final = in_dtypes.length > 0 ? "## Defined types\n\n" : ""
|
final = in_dtypes.length > 0 ? "## Defined types\n\n" : ""
|
||||||
in_dtypes.each do |type|
|
in_dtypes.each do |type|
|
||||||
final << PuppetStrings::Markdown::DefinedType.new(type).render
|
final << type.render unless type.private?
|
||||||
end
|
end
|
||||||
final
|
final
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.toc_info
|
def self.toc_info
|
||||||
final = []
|
final = ["Defined types"]
|
||||||
|
|
||||||
in_dtypes.each do |type|
|
in_dtypes.each do |type|
|
||||||
final.push(PuppetStrings::Markdown::DefinedType.new(type).toc_info)
|
final.push(type.toc_info)
|
||||||
end
|
end
|
||||||
|
|
||||||
final
|
final
|
||||||
|
|
|
@ -5,22 +5,30 @@ module PuppetStrings::Markdown
|
||||||
|
|
||||||
# @return [Array] list of functions
|
# @return [Array] list of functions
|
||||||
def self.in_functions
|
def self.in_functions
|
||||||
YARD::Registry.all(:puppet_function).sort_by!(&:name).map!(&:to_hash)
|
arr = YARD::Registry.all(:puppet_function).sort_by!(&:name).map!(&:to_hash)
|
||||||
|
arr.map! { |a| PuppetStrings::Markdown::Function.new(a) }
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.contains_private?
|
||||||
|
result = false
|
||||||
|
unless in_functions.nil?
|
||||||
|
in_functions.find { |func| func.private? }.nil? ? false : true
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.render
|
def self.render
|
||||||
final = in_functions.length > 0 ? "## Functions\n\n" : ""
|
final = in_functions.length > 0 ? "## Functions\n\n" : ""
|
||||||
in_functions.each do |func|
|
in_functions.each do |func|
|
||||||
final << PuppetStrings::Markdown::Function.new(func).render
|
final << func.render unless func.private?
|
||||||
end
|
end
|
||||||
final
|
final
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.toc_info
|
def self.toc_info
|
||||||
final = []
|
final = ["Functions"]
|
||||||
|
|
||||||
in_functions.each do |func|
|
in_functions.each do |func|
|
||||||
final.push(PuppetStrings::Markdown::Function.new(func).toc_info)
|
final.push(func.toc_info)
|
||||||
end
|
end
|
||||||
|
|
||||||
final
|
final
|
||||||
|
|
|
@ -5,22 +5,30 @@ module PuppetStrings::Markdown
|
||||||
|
|
||||||
# @return [Array] list of classes
|
# @return [Array] list of classes
|
||||||
def self.in_classes
|
def self.in_classes
|
||||||
YARD::Registry.all(:puppet_class).sort_by!(&:name).map!(&:to_hash)
|
arr = YARD::Registry.all(:puppet_class).sort_by!(&:name).map!(&:to_hash)
|
||||||
|
arr.map! { |a| PuppetStrings::Markdown::PuppetClass.new(a) }
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.contains_private?
|
||||||
|
result = false
|
||||||
|
unless in_classes.nil?
|
||||||
|
in_classes.find { |klass| klass.private? }.nil? ? false : true
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.render
|
def self.render
|
||||||
final = in_classes.length > 0 ? "## Classes\n\n" : ""
|
final = in_classes.length > 0 ? "## Classes\n\n" : ""
|
||||||
in_classes.each do |klass|
|
in_classes.each do |klass|
|
||||||
final << PuppetStrings::Markdown::PuppetClass.new(klass).render
|
final << klass.render unless klass.private?
|
||||||
end
|
end
|
||||||
final
|
final
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.toc_info
|
def self.toc_info
|
||||||
final = []
|
final = ["Classes"]
|
||||||
|
|
||||||
in_classes.each do |klass|
|
in_classes.each do |klass|
|
||||||
final.push(PuppetStrings::Markdown::PuppetClass.new(klass).toc_info)
|
final.push(klass.toc_info)
|
||||||
end
|
end
|
||||||
|
|
||||||
final
|
final
|
||||||
|
|
|
@ -5,22 +5,30 @@ module PuppetStrings::Markdown
|
||||||
|
|
||||||
# @return [Array] list of resource types
|
# @return [Array] list of resource types
|
||||||
def self.in_rtypes
|
def self.in_rtypes
|
||||||
YARD::Registry.all(:puppet_type).sort_by!(&:name).map!(&:to_hash)
|
arr = YARD::Registry.all(:puppet_type).sort_by!(&:name).map!(&:to_hash)
|
||||||
|
arr.map! { |a| PuppetStrings::Markdown::ResourceType.new(a) }
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.contains_private?
|
||||||
|
result = false
|
||||||
|
unless in_rtypes.nil?
|
||||||
|
in_rtypes.find { |type| type.private? }.nil? ? false : true
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.render
|
def self.render
|
||||||
final = in_rtypes.length > 0 ? "## Resource types\n\n" : ""
|
final = in_rtypes.length > 0 ? "## Resource types\n\n" : ""
|
||||||
in_rtypes.each do |type|
|
in_rtypes.each do |type|
|
||||||
final << PuppetStrings::Markdown::ResourceType.new(type).render
|
final << type.render unless type.private?
|
||||||
end
|
end
|
||||||
final
|
final
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.toc_info
|
def self.toc_info
|
||||||
final = []
|
final = ["Resource types"]
|
||||||
|
|
||||||
in_rtypes.each do |type|
|
in_rtypes.each do |type|
|
||||||
final.push(PuppetStrings::Markdown::ResourceType.new(type).toc_info)
|
final.push(type.toc_info)
|
||||||
end
|
end
|
||||||
|
|
||||||
final
|
final
|
||||||
|
|
|
@ -1,13 +1,21 @@
|
||||||
module PuppetStrings::Markdown
|
module PuppetStrings::Markdown
|
||||||
module TableOfContents
|
module TableOfContents
|
||||||
def self.render
|
def self.render
|
||||||
puppet_classes = PuppetStrings::Markdown::PuppetClasses.toc_info
|
final = ""
|
||||||
puppet_defined_types = PuppetStrings::Markdown::DefinedTypes.toc_info
|
|
||||||
puppet_resource_types = PuppetStrings::Markdown::ResourceTypes.toc_info
|
|
||||||
puppet_functions = PuppetStrings::Markdown::Functions.toc_info
|
|
||||||
|
|
||||||
template = File.join(File.dirname(__FILE__),"templates/table_of_contents.erb")
|
[PuppetStrings::Markdown::PuppetClasses,
|
||||||
ERB.new(File.read(template), nil, '-').result(binding)
|
PuppetStrings::Markdown::DefinedTypes,
|
||||||
|
PuppetStrings::Markdown::ResourceTypes,
|
||||||
|
PuppetStrings::Markdown::Functions].each do |r|
|
||||||
|
toc = r.toc_info
|
||||||
|
group_name = toc.shift
|
||||||
|
group = toc
|
||||||
|
priv = r.contains_private?
|
||||||
|
|
||||||
|
template = File.join(File.dirname(__FILE__),"templates/table_of_contents.erb")
|
||||||
|
final << ERB.new(File.read(template), nil, '-').result(binding)
|
||||||
|
end
|
||||||
|
final
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,5 +1,15 @@
|
||||||
### <%= name %>
|
### <%= name %>
|
||||||
|
|
||||||
|
<% if text -%>
|
||||||
|
<%= text %>
|
||||||
|
|
||||||
|
<% elsif summary -%>
|
||||||
|
<%= summary %>
|
||||||
|
|
||||||
|
<% else -%>
|
||||||
|
<%= "The #{name} class." %>
|
||||||
|
|
||||||
|
<% end -%>
|
||||||
<% if since -%>
|
<% if since -%>
|
||||||
* **Since** <%= since %>
|
* **Since** <%= since %>
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,16 @@
|
||||||
### <%= name %>
|
### <%= name %>
|
||||||
Type: <%= type %>
|
Type: <%= type %>
|
||||||
|
|
||||||
|
<% if text -%>
|
||||||
|
<%= text %>
|
||||||
|
|
||||||
|
<% elsif summary -%>
|
||||||
|
<%= summary %>
|
||||||
|
|
||||||
|
<% else -%>
|
||||||
|
<%= "The #{name} class." %>
|
||||||
|
|
||||||
|
<% end -%>
|
||||||
<% signatures.each do |sig| -%>
|
<% signatures.each do |sig| -%>
|
||||||
#### `<%= sig.signature %>`
|
#### `<%= sig.signature %>`
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,15 @@
|
||||||
### <%= name %>
|
### <%= name %>
|
||||||
|
|
||||||
|
<% if text -%>
|
||||||
|
<%= text %>
|
||||||
|
|
||||||
|
<% elsif summary -%>
|
||||||
|
<%= summary %>
|
||||||
|
|
||||||
|
<% else -%>
|
||||||
|
<%= "The #{name} type." %>
|
||||||
|
|
||||||
|
<% end -%>
|
||||||
<% if since -%>
|
<% if since -%>
|
||||||
* **Since** <%= since %>
|
* **Since** <%= since %>
|
||||||
|
|
||||||
|
@ -12,9 +22,6 @@
|
||||||
<% end -%>
|
<% end -%>
|
||||||
|
|
||||||
<% end -%>
|
<% end -%>
|
||||||
<% if text -%>
|
|
||||||
<%= text %>
|
|
||||||
<% end %>
|
|
||||||
<% if examples -%>
|
<% if examples -%>
|
||||||
#### Examples
|
#### Examples
|
||||||
<% examples.each do |eg| -%>
|
<% examples.each do |eg| -%>
|
||||||
|
|
|
@ -1,24 +1,21 @@
|
||||||
<% if puppet_classes.length > 0 -%>
|
<% if group.length > 0 -%>
|
||||||
## Classes
|
## <%= group_name %>
|
||||||
<% puppet_classes.each do |klassy| -%>
|
<% if priv -%>
|
||||||
* [`<%= klassy[:name] %>`](#<%= klassy[:link] %>): <%= klassy[:desc] %>
|
### Public <%= group_name %>
|
||||||
|
<% group.each do |item| -%>
|
||||||
|
<% unless item[:private] -%>
|
||||||
|
* [`<%= item[:name] %>`](#<%= item[:link] %>): <%= item[:desc] %>
|
||||||
<% end -%>
|
<% end -%>
|
||||||
<% end -%>
|
<% end -%>
|
||||||
<% if puppet_defined_types.length > 0 -%>
|
### Private <%= group_name %>
|
||||||
## Defined types
|
<% group.each do |item| -%>
|
||||||
<% puppet_defined_types.each do |dtype| -%>
|
<% if item[:private] -%>
|
||||||
* [`<%= dtype[:name] %>`](#<%= dtype[:link] %>): <%= dtype[:desc] %>
|
* `<%= item[:name] %>`: <%= item[:desc] %>
|
||||||
<% end -%>
|
<% end -%>
|
||||||
<% end -%>
|
<% end -%>
|
||||||
<% if puppet_resource_types.length > 0 -%>
|
<% else -%>
|
||||||
## Resource types
|
<% group.each do |item| -%>
|
||||||
<% puppet_resource_types.each do |rtype| -%>
|
* [`<%= item[:name] %>`](#<%= item[:link] %>): <%= item[:desc] %>
|
||||||
* [`<%= rtype[:name] %>`](#<%= rtype[:link] %>): <%= rtype[:desc] %>
|
|
||||||
<% end -%>
|
<% end -%>
|
||||||
<% end -%>
|
<% end -%>
|
||||||
<% if puppet_functions.length > 0 -%>
|
|
||||||
## Functions
|
|
||||||
<% puppet_functions.each do |func| -%>
|
|
||||||
* [`<%= func[:name] %>`](#<%= func[:link] %>): <%= func[:desc] %>
|
|
||||||
<% end -%>
|
|
||||||
<% end -%>
|
<% end -%>
|
||||||
|
|
|
@ -1,7 +1,10 @@
|
||||||
# Reference
|
# Reference
|
||||||
|
|
||||||
## Classes
|
## Classes
|
||||||
|
### Public Classes
|
||||||
* [`klass`](#klass): A simple class.
|
* [`klass`](#klass): A simple class.
|
||||||
|
### Private Classes
|
||||||
|
* `noparams`: Overview for class noparams
|
||||||
## Defined types
|
## Defined types
|
||||||
* [`klass::dt`](#klassdt): A simple defined type.
|
* [`klass::dt`](#klassdt): A simple defined type.
|
||||||
## Resource types
|
## Resource types
|
||||||
|
@ -16,6 +19,8 @@
|
||||||
|
|
||||||
### klass
|
### klass
|
||||||
|
|
||||||
|
An overview for a simple class.
|
||||||
|
|
||||||
* **Since** 1.0.0
|
* **Since** 1.0.0
|
||||||
|
|
||||||
* **See also**
|
* **See also**
|
||||||
|
@ -78,6 +83,8 @@ Default value: 'hi'
|
||||||
|
|
||||||
### klass::dt
|
### klass::dt
|
||||||
|
|
||||||
|
An overview for a simple defined type.
|
||||||
|
|
||||||
* **Since** 1.1.0
|
* **Since** 1.1.0
|
||||||
|
|
||||||
* **See also**
|
* **See also**
|
||||||
|
@ -249,6 +256,8 @@ Default value: `false`
|
||||||
### func
|
### func
|
||||||
Type: Puppet Language
|
Type: Puppet Language
|
||||||
|
|
||||||
|
A simple Puppet function.
|
||||||
|
|
||||||
#### `func(Integer $param1, Any $param2, String $param3 = hi)`
|
#### `func(Integer $param1, Any $param2, String $param3 = hi)`
|
||||||
|
|
||||||
A simple Puppet function.
|
A simple Puppet function.
|
||||||
|
@ -283,6 +292,8 @@ Options:
|
||||||
### func3x
|
### func3x
|
||||||
Type: Ruby 3.x API
|
Type: Ruby 3.x API
|
||||||
|
|
||||||
|
Documentation for an example 3.x function.
|
||||||
|
|
||||||
#### `func3x(String $param1, Integer $param2)`
|
#### `func3x(String $param1, Integer $param2)`
|
||||||
|
|
||||||
Documentation for an example 3.x function.
|
Documentation for an example 3.x function.
|
||||||
|
@ -304,6 +315,8 @@ The second parameter.
|
||||||
### func4x
|
### func4x
|
||||||
Type: Ruby 4.x API
|
Type: Ruby 4.x API
|
||||||
|
|
||||||
|
An example 4.x function.
|
||||||
|
|
||||||
#### `func4x(Integer $param1, Any $param2, Optional[Array[String]] $param3)`
|
#### `func4x(Integer $param1, Any $param2, Optional[Array[String]] $param3)`
|
||||||
|
|
||||||
An overview for the first overload.
|
An overview for the first overload.
|
||||||
|
@ -354,6 +367,8 @@ The block parameter.
|
||||||
### func4x_1
|
### func4x_1
|
||||||
Type: Ruby 4.x API
|
Type: Ruby 4.x API
|
||||||
|
|
||||||
|
An example 4.x function with only one signature.
|
||||||
|
|
||||||
#### `func4x_1(Integer $param1)`
|
#### `func4x_1(Integer $param1)`
|
||||||
|
|
||||||
An example 4.x function with only one signature.
|
An example 4.x function with only one signature.
|
||||||
|
|
|
@ -5,6 +5,7 @@ describe PuppetStrings::Markdown::Base do
|
||||||
before :each do
|
before :each do
|
||||||
YARD::Parser::SourceParser.parse_string(<<-SOURCE, :puppet)
|
YARD::Parser::SourceParser.parse_string(<<-SOURCE, :puppet)
|
||||||
# An overview
|
# An overview
|
||||||
|
# @api private
|
||||||
# @summary A simple class.
|
# @summary A simple class.
|
||||||
# @param param1 First param.
|
# @param param1 First param.
|
||||||
# @param param2 Second param.
|
# @param param2 Second param.
|
||||||
|
@ -36,6 +37,12 @@ SOURCE
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe '#private?' do
|
||||||
|
it do
|
||||||
|
expect(component.private?).to be true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe '#params' do
|
describe '#params' do
|
||||||
it 'returns the expected params' do
|
it 'returns the expected params' do
|
||||||
expect(component.params.size).to eq 3
|
expect(component.params.size).to eq 3
|
||||||
|
@ -114,13 +121,19 @@ SOURCE
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe '#private?' do
|
||||||
|
it do
|
||||||
|
expect(component.private?).to be false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe '#toc_info' do
|
describe '#toc_info' do
|
||||||
let(:toc) { component.toc_info }
|
let(:toc) { component.toc_info }
|
||||||
it 'returns a hash' do
|
it 'returns a hash' do
|
||||||
expect(toc).to be_instance_of Hash
|
expect(toc).to be_instance_of Hash
|
||||||
end
|
end
|
||||||
it 'uses overview for :desc in absence of summary' do
|
it 'uses overview for :desc in absence of summary' do
|
||||||
expect(toc[:desc]).to eq 'An overview. It\'s a longer overview. Ya know?'
|
expect(toc[:desc]).to eq 'An overview It\'s a longer overview Ya know?'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -35,6 +35,10 @@ class klass (
|
||||||
) inherits foo::bar {
|
) inherits foo::bar {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Overview for class noparams
|
||||||
|
# @api private
|
||||||
|
class noparams () {}
|
||||||
|
|
||||||
# An overview for a simple defined type.
|
# An overview for a simple defined type.
|
||||||
# @summary A simple defined type.
|
# @summary A simple defined type.
|
||||||
# @since 1.1.0
|
# @since 1.1.0
|
||||||
|
|
Loading…
Reference in New Issue