From e63f1c314228ebadcdb722f75f7dfd6e39a714fe Mon Sep 17 00:00:00 2001 From: Eric Putnam Date: Thu, 12 Apr 2018 11:53:56 +0100 Subject: [PATCH] (PDOC-159) server urls fix When using `puppet strings server`, resources with names containing '::' end up 404ing from the left bar. This is because strings namespaces these objects but YARD does not when building URLs. e.g. foo::bar's url should be /doc/foo/puppet_classes/foo/bar.html but ends up instead being doc/foo/puppet_classes/foo_3A_3A_bar.html because of YARD's url encoding. This is a monkey patch, courtesy @domcleal, that decodes the urls back so that they are namespaced correctly. --- .../monkey_patches/display_object_command.rb | 11 +++++++++++ lib/puppet-strings/yard.rb | 1 + 2 files changed, 12 insertions(+) create mode 100644 lib/puppet-strings/monkey_patches/display_object_command.rb diff --git a/lib/puppet-strings/monkey_patches/display_object_command.rb b/lib/puppet-strings/monkey_patches/display_object_command.rb new file mode 100644 index 0000000..3c6fca6 --- /dev/null +++ b/lib/puppet-strings/monkey_patches/display_object_command.rb @@ -0,0 +1,11 @@ +# Monkey patch URL decoding in object displays. Usually :: is interpreted as a +# namespace, but this is disabled in our base object, and so instead gets +# URL-encoded. +require 'yard/server/commands/display_object_command' +class YARD::Server::Commands::DisplayObjectCommand + private + alias_method :object_path_yard, :object_path + def object_path + object_path_yard.gsub('_3A', ':') + end +end diff --git a/lib/puppet-strings/yard.rb b/lib/puppet-strings/yard.rb index 48cf1c6..155a64a 100644 --- a/lib/puppet-strings/yard.rb +++ b/lib/puppet-strings/yard.rb @@ -6,6 +6,7 @@ module PuppetStrings::Yard require 'puppet-strings/yard/handlers' require 'puppet-strings/yard/tags' require 'puppet-strings/yard/parsers' + require 'puppet-strings/monkey_patches/display_object_command' # Sets up YARD for use with puppet-strings. # @return [void]