-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #161 from eputnam/_pdoc206
(PDOC-206) support for tasks
- Loading branch information
Showing
35 changed files
with
883 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
require 'puppet-strings/markdown/base' | ||
|
||
module PuppetStrings::Markdown | ||
class PuppetTask < Base | ||
def initialize(registry) | ||
@template = 'puppet_task.erb' | ||
@registry = registry | ||
super(registry, 'task') | ||
end | ||
|
||
def render | ||
super(@template) | ||
end | ||
|
||
def supports_noop | ||
@registry[:supports_noop] | ||
end | ||
|
||
def input_method | ||
@registry[:input_method] | ||
end | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
require_relative 'puppet_task' | ||
|
||
module PuppetStrings::Markdown | ||
module PuppetTasks | ||
|
||
# @return [Array] list of classes | ||
def self.in_tasks | ||
arr = YARD::Registry.all(:puppet_task).sort_by!(&:name).map!(&:to_hash) | ||
arr.map! { |a| PuppetStrings::Markdown::PuppetTask.new(a) } | ||
end | ||
|
||
def self.contains_private? | ||
false | ||
end | ||
|
||
def self.render | ||
final = in_tasks.length > 0 ? "## Tasks\n\n" : "" | ||
in_tasks.each do |task| | ||
final << task.render unless task.private? | ||
end | ||
final | ||
end | ||
|
||
def self.toc_info | ||
final = ["Tasks"] | ||
|
||
in_tasks.each do |task| | ||
final.push(task.toc_info) | ||
end | ||
|
||
final | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
### <%= name %> | ||
<% if text -%> | ||
<%= text %> | ||
<% elsif summary -%> | ||
<%= summary %> | ||
<% else -%> | ||
<%= "The #{name} task." %> | ||
<% end -%> | ||
**Supports noop?** <%= supports_noop %> | ||
<% if params -%> | ||
#### Parameters | ||
|
||
<% params.each do |param| -%> | ||
##### `<%= param[:name] %>` | ||
|
||
<% if param[:types] -%> | ||
Data type: `<%= param[:types].join(', ') -%>` | ||
|
||
<% end -%> | ||
<%= param[:text] %> | ||
<% 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
require 'puppet-strings/yard/code_objects/group' | ||
|
||
# Implements the group for Puppet tasks. | ||
class PuppetStrings::Yard::CodeObjects::Tasks < PuppetStrings::Yard::CodeObjects::Group | ||
# Gets the singleton instance of the group. | ||
# @return Returns the singleton instance of the group. | ||
def self.instance | ||
super(:puppet_tasks) | ||
end | ||
|
||
# Gets the display name of the group. | ||
# @param [Boolean] prefix whether to show a prefix. | ||
# @return [String] Returns the display name of the group. | ||
def name(prefix = false) | ||
'Puppet Tasks' | ||
end | ||
end | ||
|
||
# Implements the Puppet task code object. | ||
class PuppetStrings::Yard::CodeObjects::Task < PuppetStrings::Yard::CodeObjects::Base | ||
attr_reader :statement | ||
|
||
# Initializes a JSON task code object. | ||
# @param statement TaskStatement object | ||
# @return [void] | ||
def initialize(statement) | ||
@name = statement.name | ||
@statement = statement | ||
super(PuppetStrings::Yard::CodeObjects::Tasks.instance, name) | ||
end | ||
|
||
# Gets the type of the code object. | ||
# @return Returns the type of the code object. | ||
def type | ||
:puppet_task | ||
end | ||
|
||
# Gets the source of the code object. | ||
# @return Returns the source of the code object. | ||
def source | ||
@statement.source | ||
end | ||
|
||
def parameters | ||
parameters = [] | ||
statement.json['parameters'].each do |name,props| | ||
parameters.push({ name: name.to_s, | ||
tag_name: 'param', | ||
text: props['description'] || "", | ||
types: [props['type']] || "" }) | ||
end | ||
parameters | ||
end | ||
|
||
# Converts the code object to a hash representation. | ||
# @return [Hash] Returns a hash representation of the code object. | ||
def to_hash | ||
{ name: name.to_s, | ||
file: statement.file, | ||
line: statement.line, | ||
docstring: { | ||
text: statement.docstring, | ||
tags: parameters | ||
}, | ||
source: statement.source, | ||
supports_noop: statement.json['supports_noop'] || false, | ||
input_method: statement.json['input_method'] | ||
} | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class PuppetStrings::Yard::Handlers::JSON::Base < YARD::Handlers::Base | ||
def self.handles?(statement) | ||
handlers.any? {|handler| statement.is_a?(handler)} | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
require 'puppet-strings/yard/handlers/json/base' | ||
require 'puppet-strings/yard/parsers' | ||
require 'puppet-strings/yard/parsers/json/parser' | ||
|
||
class PuppetStrings::Yard::Handlers::JSON::TaskHandler < PuppetStrings::Yard::Handlers::JSON::Base | ||
handles PuppetStrings::Yard::Parsers::JSON::TaskStatement | ||
namespace_only | ||
|
||
process do | ||
object = PuppetStrings::Yard::CodeObjects::Task.new(statement) | ||
register object | ||
|
||
@kind = "Puppet Task #{object.name}." | ||
@statement = statement | ||
|
||
validate_description | ||
validate_params | ||
end | ||
|
||
def validate_description | ||
log.warn "Missing a description for #{@kind}." if @statement.docstring.empty? | ||
end | ||
|
||
def validate_params | ||
unless @statement.parameters.empty? | ||
@statement.parameters.each do |param, val| | ||
log.warn "Missing description for param '#{param}' in #{@kind}" if val['description'].nil? | ||
end | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
require 'puppet-strings/yard/parsers/json/task_statement' | ||
|
||
class PuppetStrings::Yard::Parsers::JSON::Parser < YARD::Parser::Base | ||
attr_reader :file, :source | ||
|
||
# Initializes the parser. | ||
# @param [String] source The source being parsed. | ||
# @param [String] filename The file name of the file being parsed. | ||
# @return [void] | ||
def initialize(source, filename) | ||
@file = filename | ||
@source = source | ||
@statements = [] | ||
end | ||
|
||
def enumerator | ||
@statements | ||
end | ||
|
||
# Parses the source | ||
# @return [void] | ||
def parse | ||
begin | ||
json = JSON.parse(source) | ||
@statements.push(PuppetStrings::Yard::Parsers::JSON::TaskStatement.new(json, @source, @file)) | ||
rescue | ||
log.error "Failed to parse #{@file}: " | ||
@statements = [] | ||
end | ||
@statements.freeze | ||
self | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
module PuppetStrings::Yard::Parsers::JSON | ||
# Represents the Puppet Task statement. | ||
class TaskStatement | ||
attr_reader :line, :comments, :comments_range, :json, :file, :source, :docstring | ||
|
||
def initialize(json, source, file) | ||
@file = file | ||
@source = source | ||
@json = json | ||
@line = 0 | ||
@comments_range = nil | ||
@docstring = YARD::Docstring.new(@json['description']) | ||
end | ||
|
||
def parameters | ||
json['parameters'] || {} | ||
end | ||
|
||
def comments_hash_flag | ||
false | ||
end | ||
|
||
def show | ||
"" | ||
end | ||
|
||
def comments | ||
docstring.all | ||
end | ||
|
||
def name | ||
File.basename(@file).gsub('.json','') || "" | ||
end | ||
end | ||
end |
9 changes: 9 additions & 0 deletions
9
lib/puppet-strings/yard/templates/default/fulldoc/html/full_list_puppet_task.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,9 @@ | ||
<% even = false %> | ||
<% @items.each do |item| %> | ||
<li id="object_<%=item.path%>" class="<%= even ? 'even' : 'odd' %>"> | ||
<div class="item"> | ||
<%= linkify item, h(item.name(true)) %> | ||
</div> | ||
</li> | ||
<% even = !even %> | ||
<% 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
Oops, something went wrong.