(maint) update table of contents
The table_of_contents template was already too bulky and redundant and recognizing public and private components was only going to make it worse. This refactors the toc template and the toc class to use a generic outline for all components.
This commit is contained in:
parent
09a5d3e4ff
commit
6923d9e18c
|
@ -130,7 +130,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].gsub("\n", ". "),
|
||||||
|
private: private?
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -152,6 +153,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
|
||||||
|
|
||||||
def contains_displayed_tags?
|
def contains_displayed_tags?
|
||||||
result = @registry[:docstring][:text] ? true : false
|
result = @registry[:docstring][:text] ? true : false
|
||||||
@tags.each do |tag|
|
@tags.each do |tag|
|
||||||
|
|
|
@ -5,23 +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|
|
||||||
to_render = PuppetStrings::Markdown::DefinedType.new(type)
|
final << type.render unless type.private?
|
||||||
final << to_render.render if to_render.contains_displayed_tags?
|
|
||||||
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,23 +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|
|
||||||
to_render = PuppetStrings::Markdown::Function.new(func)
|
final << func.render unless func.private?
|
||||||
final << to_render.render if to_render.contains_displayed_tags?
|
|
||||||
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,23 +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|
|
||||||
to_render = PuppetStrings::Markdown::PuppetClass.new(klass)
|
final << klass.render unless klass.private?
|
||||||
final << to_render.render if to_render.contains_displayed_tags?
|
|
||||||
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,23 +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|
|
||||||
to_render = PuppetStrings::Markdown::ResourceType.new(type)
|
final << type.render unless type.private?
|
||||||
final << to_render.render if to_render.contains_displayed_tags?
|
|
||||||
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,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,9 +1,10 @@
|
||||||
# Reference
|
# Reference
|
||||||
|
|
||||||
## Classes
|
## Classes
|
||||||
|
### Public Classes
|
||||||
* [`klass`](#klass): A simple class.
|
* [`klass`](#klass): A simple class.
|
||||||
* [`noparams`](#noparams): Overview for class noparams
|
### Private Classes
|
||||||
* [`noparams_desc`](#noparams_desc):
|
* `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
|
||||||
|
@ -78,16 +79,6 @@ Third param.
|
||||||
Default value: 'hi'
|
Default value: 'hi'
|
||||||
|
|
||||||
|
|
||||||
### noparams
|
|
||||||
|
|
||||||
Overview for class noparams
|
|
||||||
|
|
||||||
|
|
||||||
### noparams_desc
|
|
||||||
|
|
||||||
The noparams_desc class.
|
|
||||||
|
|
||||||
|
|
||||||
## Defined types
|
## Defined types
|
||||||
|
|
||||||
### klass::dt
|
### klass::dt
|
||||||
|
|
|
@ -114,6 +114,12 @@ 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
|
||||||
|
|
|
@ -36,10 +36,9 @@ class klass (
|
||||||
}
|
}
|
||||||
|
|
||||||
# Overview for class noparams
|
# Overview for class noparams
|
||||||
|
# @api private
|
||||||
class noparams () {}
|
class noparams () {}
|
||||||
|
|
||||||
class noparams_desc () {}
|
|
||||||
|
|
||||||
# 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