From afb053c03b1e3b97efe7f5bd497f55025a0849d8 Mon Sep 17 00:00:00 2001 From: Charlie Sharpsteen Date: Sun, 1 Jun 2014 17:37:18 -0700 Subject: [PATCH] Add a server action to the yardoc face This commit adds the `puppet yardoc server` action which is designed to mimic `yard server --gems`. This action generates YARD indicies by invoking `puppet yardoc modules` and then configures `YARD::CLI::Server` to serve the resulting documentation. --- lib/puppet/face/yardoc.rb | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/lib/puppet/face/yardoc.rb b/lib/puppet/face/yardoc.rb index fe372b4..dc5684b 100644 --- a/lib/puppet/face/yardoc.rb +++ b/lib/puppet/face/yardoc.rb @@ -85,4 +85,28 @@ Puppet::Face.define(:yardoc, '0.0.1') do end end end + + action(:server) do + summary "Serve YARD documentation for modules." + + when_invoked do |*args| + check_required_features + require 'puppetx/yardoc/yard/plugin' + opts = args.pop + + # 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. + module_list = Puppet::Face[:yardoc, :current].modules + + module_tuples = module_list.map do |mod| + name = (mod.forge_name || mod.name).gsub('/', '-') + yard_index = File.join(mod.path, '.yardoc') + + [name, yard_index] + end + + YARD::CLI::Server.run('-m', *module_tuples.flatten) + end + end end