2014-05-16 17:54:34 +00:00
|
|
|
require 'puppet/face'
|
2014-09-19 17:59:37 +00:00
|
|
|
|
2014-09-11 00:07:33 +00:00
|
|
|
Puppet::Face.define(:strings, '0.0.1') do
|
2014-06-01 06:24:27 +00:00
|
|
|
summary "Generate Puppet documentation with YARD."
|
2014-05-16 17:54:34 +00:00
|
|
|
|
2014-09-22 20:41:08 +00:00
|
|
|
# Ensures that the user has the needed features to use puppet strings
|
|
|
|
def check_required_features
|
|
|
|
unless Puppet.features.yard?
|
|
|
|
raise RuntimeError, "The 'yard' gem must be installed in order to use this face."
|
|
|
|
end
|
|
|
|
|
|
|
|
unless Puppet.features.rgen?
|
|
|
|
raise RuntimeError, "The 'rgen' gem must be installed in order to use this face."
|
|
|
|
end
|
|
|
|
|
|
|
|
if RUBY_VERSION.match(/^1\.8/)
|
|
|
|
raise RuntimeError, "This face requires Ruby 1.9 or greater."
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# A list of globs that generates the default list of module files from which
|
|
|
|
# documentation can be extracted.
|
|
|
|
#
|
|
|
|
# TODO: It would be awesome if we could somehow override/append to the
|
|
|
|
# default file list that YARD uses. Consider an upstream PR for this.
|
|
|
|
MODULE_SOURCEFILES = ['manifests/**/*.pp', 'lib/**/*.rb']
|
|
|
|
|
2014-05-16 17:54:34 +00:00
|
|
|
action(:yardoc) do
|
|
|
|
default
|
|
|
|
|
2014-06-01 19:33:34 +00:00
|
|
|
summary "Generate YARD documentation from files."
|
2014-06-01 06:24:27 +00:00
|
|
|
arguments "[manifest_file.pp ...]"
|
|
|
|
|
2014-05-26 19:02:59 +00:00
|
|
|
when_invoked do |*args|
|
2014-06-01 19:33:34 +00:00
|
|
|
check_required_features
|
2015-02-03 23:06:30 +00:00
|
|
|
require 'puppet_x/puppetlabs/strings/actions'
|
2014-09-22 20:41:08 +00:00
|
|
|
|
2015-02-03 23:06:30 +00:00
|
|
|
yardoc_actions = PuppetX::PuppetLabs::Strings::Actions.new(Puppet[:debug], Puppet[:trace])
|
2014-05-30 16:59:55 +00:00
|
|
|
|
2014-05-26 19:02:59 +00:00
|
|
|
# The last element of the argument array should be the options hash.
|
2014-10-08 18:36:21 +00:00
|
|
|
# We don't have any options yet, so for now just pop the hash off and
|
|
|
|
# toss it.
|
2014-05-26 19:02:59 +00:00
|
|
|
#
|
|
|
|
# NOTE: The Puppet Face will throw 'unrecognized option' errors if any
|
|
|
|
# YARD options are passed to it. The best way to approach this problem is
|
|
|
|
# by using the `.yardopts` file. YARD will autoload any options placed in
|
|
|
|
# that file.
|
2014-10-08 18:36:21 +00:00
|
|
|
args.pop
|
2014-05-26 19:02:59 +00:00
|
|
|
|
|
|
|
# For now, assume the remaining positional args are a list of manifest
|
2014-06-03 04:55:27 +00:00
|
|
|
# and ruby files to parse.
|
2014-06-03 02:38:19 +00:00
|
|
|
yard_args = (args.empty? ? MODULE_SOURCEFILES : args)
|
2015-07-02 01:47:54 +00:00
|
|
|
|
|
|
|
# This line monkeypatches yard's progress indicator so it doesn't write
|
|
|
|
# all over the terminal. This should definitely not be in real code, but
|
|
|
|
# it's very handy for debugging with pry
|
|
|
|
#class YARD::Logger; def progress(*args); end; end
|
2014-05-24 19:54:22 +00:00
|
|
|
|
2014-09-22 20:41:08 +00:00
|
|
|
yardoc_actions.generate_documentation(*yard_args)
|
2014-05-16 17:54:34 +00:00
|
|
|
end
|
|
|
|
end
|
2014-06-01 19:33:34 +00:00
|
|
|
|
|
|
|
# NOTE: Modeled after the `yard gems` command which builds doc indicies
|
|
|
|
# (.yardoc directories) for Ruby Gems. Currently lacks the fine-grained
|
|
|
|
# control over where these indicies are created and just dumps them in the
|
|
|
|
# module roots.
|
2014-06-02 00:37:18 +00:00
|
|
|
|
|
|
|
action(:server) do
|
|
|
|
summary "Serve YARD documentation for modules."
|
|
|
|
|
|
|
|
when_invoked do |*args|
|
|
|
|
check_required_features
|
2015-02-03 23:06:30 +00:00
|
|
|
require 'puppet_x/puppetlabs/strings/actions'
|
2014-09-22 20:41:08 +00:00
|
|
|
|
2015-02-03 23:06:30 +00:00
|
|
|
server_actions = PuppetX::PuppetLabs::Strings::Actions.new(Puppet[:debug], Puppet[:trace])
|
2014-09-19 21:44:22 +00:00
|
|
|
|
2014-10-08 18:36:21 +00:00
|
|
|
args.pop
|
2014-06-02 00:37:18 +00:00
|
|
|
|
2014-09-19 17:59:37 +00:00
|
|
|
module_names = args
|
|
|
|
|
2014-06-02 00:37:18 +00:00
|
|
|
# FIXME: This is pretty inefficient as it forcibly re-generates the YARD
|
|
|
|
# indicies each time the server is started. However, it ensures things are
|
|
|
|
# generated properly.
|
2014-09-22 20:41:08 +00:00
|
|
|
module_list = server_actions.index_documentation_for_modules(module_names, MODULE_SOURCEFILES)
|
2014-06-02 00:37:18 +00:00
|
|
|
|
2014-09-22 20:41:08 +00:00
|
|
|
module_tuples = server_actions.generate_module_tuples(module_list)
|
2014-06-02 00:37:18 +00:00
|
|
|
|
2014-09-19 17:59:37 +00:00
|
|
|
module_tuples.map! do |mod|
|
|
|
|
[mod[:name], mod[:index_path]]
|
2014-06-02 00:37:18 +00:00
|
|
|
end
|
|
|
|
|
2014-06-03 02:38:19 +00:00
|
|
|
# The `-m` flag means a list of name/path pairs will follow. The name is
|
|
|
|
# used as the module name and the path indicates which `.yardoc` index to
|
|
|
|
# generate documentation from.
|
2014-09-22 23:54:28 +00:00
|
|
|
yard_args = %w[-m -q] + module_tuples.flatten
|
2014-06-03 02:38:19 +00:00
|
|
|
|
2014-09-22 20:41:08 +00:00
|
|
|
server_actions.serve_documentation(*yard_args)
|
2014-06-02 00:37:18 +00:00
|
|
|
end
|
|
|
|
end
|
2014-05-16 17:54:34 +00:00
|
|
|
end
|
2014-09-19 17:59:37 +00:00
|
|
|
|