2016-09-09 20:44:05 +00:00
|
|
|
# The root module for Puppet Strings.
|
|
|
|
module PuppetStrings
|
|
|
|
# The glob patterns used to search for files to document.
|
|
|
|
DEFAULT_SEARCH_PATTERNS = %w(
|
|
|
|
manifests/**/*.pp
|
|
|
|
functions/**/*.pp
|
|
|
|
types/**/*.pp
|
|
|
|
lib/**/*.rb
|
2018-02-16 17:27:26 +00:00
|
|
|
tasks/*.json
|
(PDOC-228) puppet plans support
Currently, Puppet Strings only supports Puppet Tasks. Since Plans are
sort of connected to Tasks, it seemed right that Strings should also
support Plans. That and Plans are a thing that needs to be documented.
First, the Puppet[:tasks] setting needs to be set to add the 'plan' keyword to the Puppet Parser's lexicon, so this sets it in the Strings parser if the setting exists. If it does not exist and Puppet.version is less than 5.0.0, Strings will error out.
Second, processing for the Plans themselves is set up. Plans are very
similar to other Puppet objects like defined types and classes, so this
involved some serious copy-pasta.
Third, all the template/to_hash scaffolding for the different outputs is in place (HTML,
JSON, Markdown).
Yey.
2018-03-03 00:15:09 +00:00
|
|
|
plans/*.pp
|
2016-09-09 20:44:05 +00:00
|
|
|
).freeze
|
|
|
|
|
|
|
|
# Generates documentation.
|
|
|
|
# @param [Array<String>] search_patterns The search patterns (e.g. manifests/**/*.pp) to look for files.
|
|
|
|
# @param [Hash] options The options hash.
|
|
|
|
# @option options [Boolean] :debug Enable YARD debug output.
|
|
|
|
# @option options [Boolean] :backtrace Enable YARD backtraces.
|
|
|
|
# @option options [String] :markup The YARD markup format to use (defaults to 'markdown').
|
2018-01-23 00:22:42 +00:00
|
|
|
# @option options [String] :path Write the selected format to a file path
|
2018-02-07 23:20:30 +00:00
|
|
|
# @option options [Boolean] :markdown From the --format option, is the format Markdown?
|
|
|
|
# @option options [Boolean] :json Is the format JSON?
|
2016-09-09 20:44:05 +00:00
|
|
|
# @option options [Array<String>] :yard_args The arguments to pass to yard.
|
|
|
|
# @return [void]
|
|
|
|
def self.generate(search_patterns = DEFAULT_SEARCH_PATTERNS, options = {})
|
2016-09-11 17:58:48 +00:00
|
|
|
require 'puppet-strings/yard'
|
|
|
|
PuppetStrings::Yard.setup!
|
|
|
|
|
2016-09-09 20:44:05 +00:00
|
|
|
# Format the arguments to YARD
|
|
|
|
args = ['doc']
|
|
|
|
args << '--debug' if options[:debug]
|
|
|
|
args << '--backtrace' if options[:backtrace]
|
|
|
|
args << "-m#{options[:markup] || 'markdown'}"
|
|
|
|
|
2018-02-07 23:12:47 +00:00
|
|
|
file = nil
|
2018-01-23 00:22:42 +00:00
|
|
|
if options[:json] || options[:markdown]
|
2018-02-20 20:12:46 +00:00
|
|
|
file = if options[:json]
|
|
|
|
options[:path]
|
|
|
|
elsif options[:markdown]
|
|
|
|
options[:path] || "REFERENCE.md"
|
|
|
|
end
|
2016-09-09 20:44:05 +00:00
|
|
|
# Disable output and prevent stats/progress when writing to STDOUT
|
|
|
|
args << '-n'
|
2018-01-23 00:22:42 +00:00
|
|
|
args << '-q' unless file
|
|
|
|
args << '--no-stats' unless file
|
|
|
|
args << '--no-progress' unless file
|
2016-09-09 20:44:05 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
yard_args = options[:yard_args]
|
|
|
|
args += yard_args if yard_args
|
|
|
|
args += search_patterns
|
|
|
|
|
|
|
|
# Run YARD
|
|
|
|
YARD::CLI::Yardoc.run(*args)
|
|
|
|
|
|
|
|
# If outputting JSON, render the output
|
2018-01-23 00:22:42 +00:00
|
|
|
if options[:json]
|
2018-02-07 23:12:47 +00:00
|
|
|
render_json(file)
|
2016-09-09 20:44:05 +00:00
|
|
|
end
|
2018-01-23 00:22:42 +00:00
|
|
|
|
|
|
|
# If outputting Markdown, render the output
|
|
|
|
if options[:markdown]
|
2018-02-07 23:12:47 +00:00
|
|
|
render_markdown(file)
|
2018-01-23 00:22:42 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
(PDOC-228) puppet plans support
Currently, Puppet Strings only supports Puppet Tasks. Since Plans are
sort of connected to Tasks, it seemed right that Strings should also
support Plans. That and Plans are a thing that needs to be documented.
First, the Puppet[:tasks] setting needs to be set to add the 'plan' keyword to the Puppet Parser's lexicon, so this sets it in the Strings parser if the setting exists. If it does not exist and Puppet.version is less than 5.0.0, Strings will error out.
Second, processing for the Plans themselves is set up. Plans are very
similar to other Puppet objects like defined types and classes, so this
involved some serious copy-pasta.
Third, all the template/to_hash scaffolding for the different outputs is in place (HTML,
JSON, Markdown).
Yey.
2018-03-03 00:15:09 +00:00
|
|
|
def self.puppet_5?
|
|
|
|
Puppet::Util::Package.versioncmp(Puppet.version, "5.0.0") >= 0
|
|
|
|
end
|
|
|
|
|
2018-01-23 00:22:42 +00:00
|
|
|
def self.render_json(path)
|
|
|
|
require 'puppet-strings/json'
|
|
|
|
PuppetStrings::Json.render(path)
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.render_markdown(path)
|
|
|
|
require 'puppet-strings/markdown'
|
|
|
|
PuppetStrings::Markdown.render(path)
|
2016-09-09 20:44:05 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
# Runs the YARD documentation server.
|
|
|
|
# @param [Array<String>] args The arguments to YARD.
|
|
|
|
def self.run_server(*args)
|
2016-09-11 17:58:48 +00:00
|
|
|
require 'puppet-strings/yard'
|
|
|
|
PuppetStrings::Yard.setup!
|
|
|
|
|
2016-09-09 20:44:05 +00:00
|
|
|
YARD::CLI::Server.run(*args)
|
|
|
|
end
|
|
|
|
end
|