Search code examples
rubyyard

Change yardoc serialized_path


Right now Yardoc will generate docs like: doc/ModuleName.html, doc/ModuleName/ClassName.html and doc/ModuleName/ClassName/method_name.html I was wondering how I can adjust serialized_path (without monkey patching everything) to do something like: doc/ModuleName/index.html doc/ModuleName/ClassName/index.html and doc/ModuleName/ClassName/method_name/index.html


Solution

  • You'll need to monkey patch (from what I've noticed, after 2 days of searching I found no other way) So...Create a file named yardoc_pretty-uris.rb and when you run yardoc do -e yardo_pretty-print.rb.

    yardoc_pretty-uris.rb contents:

    module YARD
      module Serializers
        class FileSystemSerializer
          def serialized_path(object)
            return object if object.is_a?(String)
    
            if object.is_a?(CodeObjects::ExtraFileObject)
              fspath = ["file.#{object.name}.#{@extension}"]
            else
              objname = "top-level-namespace"
              objname = object.name.to_s if object != YARD::Registry.root
    
              # Make this shit pretty URL's prease.....
              fspath = [objname, "index.#{@extension}"]
    
              if object.namespace && object.namespace.path != ""
                fspath.unshift(*object.namespace.path.split(CodeObjects::NSEP))
              end
            end
    
            fspath.map! do |part|
              part.downcase!
              part.gsub(/[^0-9a-zA-Z\-_\.]/, '')
            end
    
            File.join(fspath)
          end
        end
      end
    end