forked from puppetlabs/puppet-strings
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(PDOC-226) Add Puppet Data Type Alias documentation
Previously Puppet-Strings could not document Data Type Aliases. This commit: * Updates the puppet parser to interpret TypeAlias statements. * Adds a DataTypeAlias code object and handler to document the Type Alias statement correctly. * Adds tests for puppet parsing to ensure the Yard Code Object is populated correctly * Adds support for JSON, Markdown and HTML rendering. Note that JSON separates Data Types from Data Type Aliases whereas Markdown and HTML rendering lump them together. This is because from a human documentation point of view (i.e Mardown or HTML) they are very similar things. Much like Puppet V3 vs V4 functions. However the JSON output can be used by other systems so it is important to diffentiate them as they are different from a code inspection point of view. * Adds tests for JSON and Markdown rendering
- Loading branch information
1 parent
7493d88
commit 8a802f2
Showing
29 changed files
with
373 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
require 'puppet-strings/yard/code_objects/group' | ||
require 'puppet-strings/yard/util' | ||
|
||
# Implements the group for Puppet DataTypeAliases. | ||
class PuppetStrings::Yard::CodeObjects::DataTypeAliases < PuppetStrings::Yard::CodeObjects::Group | ||
# Gets the singleton instance of the group. | ||
# @return Returns the singleton instance of the group. | ||
def self.instance | ||
super(:puppet_data_type_aliases) | ||
end | ||
|
||
# Gets the display name of the group. | ||
# @param [Boolean] prefix whether to show a prefix. Ignored for Puppet group namespaces. | ||
# @return [String] Returns the display name of the group. | ||
def name(prefix = false) | ||
'Puppet Data Type Aliases' | ||
end | ||
end | ||
|
||
# Implements the Puppet DataTypeAlias code object. | ||
class PuppetStrings::Yard::CodeObjects::DataTypeAlias < PuppetStrings::Yard::CodeObjects::Base | ||
attr_reader :statement | ||
attr_accessor :alias_of | ||
|
||
# Initializes a Puppet data type alias code object. | ||
# @param [PuppetStrings::Parsers::DataTypeAliasStatement] statement The data type alias statement that was parsed. | ||
# @return [void] | ||
def initialize(statement) | ||
@statement = statement | ||
@alias_of = statement.alias_of | ||
super(PuppetStrings::Yard::CodeObjects::DataTypeAliases.instance, statement.name) | ||
end | ||
|
||
# Gets the type of the code object. | ||
# @return Returns the type of the code object. | ||
def type | ||
:puppet_data_type_alias | ||
end | ||
|
||
# Gets the source of the code object. | ||
# @return Returns the source of the code object. | ||
def source | ||
# Not implemented, but would be nice! | ||
nil | ||
end | ||
|
||
# Converts the code object to a hash representation. | ||
# @return [Hash] Returns a hash representation of the code object. | ||
def to_hash | ||
hash = {} | ||
hash[:name] = name | ||
hash[:file] = file | ||
hash[:line] = line | ||
hash[:docstring] = PuppetStrings::Yard::Util.docstring_to_hash(docstring) | ||
hash[:alias_of] = alias_of | ||
hash | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
lib/puppet-strings/yard/handlers/puppet/data_type_alias_handler.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
require 'puppet-strings/yard/handlers/helpers' | ||
require 'puppet-strings/yard/handlers/puppet/base' | ||
require 'puppet-strings/yard/parsers' | ||
require 'puppet-strings/yard/code_objects' | ||
|
||
# Implements the handler for Puppet Data Type Alias. | ||
class PuppetStrings::Yard::Handlers::Puppet::DataTypeAliasHandler < PuppetStrings::Yard::Handlers::Puppet::Base | ||
handles PuppetStrings::Yard::Parsers::Puppet::DataTypeAliasStatement | ||
|
||
process do | ||
# Register the object | ||
object = PuppetStrings::Yard::CodeObjects::DataTypeAlias.new(statement) | ||
register object | ||
|
||
# Log a warning if missing documentation | ||
log.warn "Missing documentation for Puppet type alias '#{object.name}' at #{statement.file}:#{statement.line}." if object.docstring.empty? && object.tags.empty? | ||
|
||
# Mark the class as public if it doesn't already have an api tag | ||
object.add_tag YARD::Tags::Tag.new(:api, 'public') unless object.has_tag? :api | ||
|
||
# Warn if a summary longer than 140 characters was provided | ||
PuppetStrings::Yard::Handlers::Helpers.validate_summary_tag(object) if object.has_tag? :summary | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
lib/puppet-strings/yard/templates/default/puppet_data_type_alias/html/alias_of.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<% if @alias_of && !@alias_of.empty? %> | ||
<div class="tags"> | ||
<p class="tag_title"><%= @tag_title %></p> | ||
<div class="docstring"> | ||
<div class="discussion"> | ||
<pre class="code"><span class="info"><%= @alias_of %></span></pre> | ||
</div> | ||
</div> | ||
</div> | ||
<% end %> |
10 changes: 10 additions & 0 deletions
10
lib/puppet-strings/yard/templates/default/puppet_data_type_alias/html/box_info.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<div class="box_info"> | ||
<dl> | ||
<dt>Defined in:</dt> | ||
<dd> | ||
<%= object.file %><% if object.files.size > 1 %><span class="defines">,<br /> | ||
<%= object.files[1..-1].map {|f| f.first }.join(",<br /> ") %></div> | ||
<% end %> | ||
</dd> | ||
</dl> | ||
</div> |
1 change: 1 addition & 0 deletions
1
lib/puppet-strings/yard/templates/default/puppet_data_type_alias/html/header.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<h1>Puppet Data Type Alias: <%= object.name %></h1> |
6 changes: 6 additions & 0 deletions
6
lib/puppet-strings/yard/templates/default/puppet_data_type_alias/html/note.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<% object.tags(:note).each do |tag| %> | ||
<div class="note notetag"> | ||
<strong>Note:</strong> | ||
<%= htmlify_line tag.text %> | ||
</div> | ||
<% end %> |
6 changes: 6 additions & 0 deletions
6
lib/puppet-strings/yard/templates/default/puppet_data_type_alias/html/overview.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<h2>Overview</h2> | ||
<div class="docstring"> | ||
<div class="discussion"> | ||
<%= htmlify(object.docstring) %> | ||
</div> | ||
</div> |
17 changes: 17 additions & 0 deletions
17
lib/puppet-strings/yard/templates/default/puppet_data_type_alias/html/setup.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Initializes the template. | ||
# @return [void] | ||
def init | ||
sections :header, :box_info, :summary, :overview, :alias_of, :note, :todo, T('tags'), :source | ||
end | ||
|
||
# Renders the alias_of section. | ||
# @return [String] Returns the rendered section. | ||
def alias_of | ||
# Properties are the same thing as parameters (from the documentation standpoint), | ||
# so reuse the same template but with a different title and data source. | ||
#@parameters = object.properties || [] | ||
#@parameters.sort_by! { |p| p.name } | ||
@tag_title = 'Alias of' | ||
@alias_of = object.alias_of | ||
erb(:alias_of) | ||
end |
12 changes: 12 additions & 0 deletions
12
lib/puppet-strings/yard/templates/default/puppet_data_type_alias/html/source.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<div class="method_details_list"> | ||
<table class="source_code"> | ||
<tr> | ||
<td> | ||
<pre class="lines"><%= "\n\n\n" %><%= h format_lines(object) %></pre> | ||
</td> | ||
<td> | ||
<pre class="code"><span class="info file"># File '<%= h object.file %>'<% if object.line %>, line <%= object.line %><% end %></span><%= "\n\n" %><%= html_syntax_highlight object.source %></pre> | ||
</td> | ||
</tr> | ||
</table> | ||
</div> |
4 changes: 4 additions & 0 deletions
4
lib/puppet-strings/yard/templates/default/puppet_data_type_alias/html/summary.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<% if object.docstring.has_tag?(:summary) %> | ||
<h2>Summary</h2> | ||
<%= object.docstring.tag(:summary).text %> | ||
<% end %> |
6 changes: 6 additions & 0 deletions
6
lib/puppet-strings/yard/templates/default/puppet_data_type_alias/html/todo.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<% object.tags(:todo).each do |tag| %> | ||
<div class="note todo"> | ||
<strong>TODO:</strong> | ||
<%= htmlify_line tag.text %> | ||
</div> | ||
<% end %> |
Oops, something went wrong.