Sha256: d36b20afa21cb13e26f140898688e8f493d92310bcb846bf12c1e9d4707f04a7

Contents?: true

Size: 1.25 KB

Versions: 8

Compression:

Stored size: 1.25 KB

Contents

require 'cgi'

module YARD
  module Server
    # A custom {Serializers::Base serializer} which returns resource URLs instead of
    # static relative paths to files on disk.
    class DocServerSerializer < Serializers::FileSystemSerializer
      def initialize(command = nil)
        super(:basepath => '', :extension => '')
      end

      def serialized_path(object)
        case object
        when CodeObjects::RootObject
          "toplevel"
        when CodeObjects::ExtendedMethodObject
          name = object.name.to_s
          serialized_path(object.namespace) + ':' + urlencode(object.name.to_s)
        when CodeObjects::MethodObject
          serialized_path(object.namespace) +
            (object.scope == :instance ? ":" : ".") + urlencode(object.name.to_s)
        when CodeObjects::ConstantObject, CodeObjects::ClassVariableObject
          serialized_path(object.namespace) + "##{object.name}-#{object.type}"
        when CodeObjects::ExtraFileObject
          super(object).gsub(/^file\./, 'file/')
        else
          super(object)
        end
      end

      private

      def urlencode(name)
        if name.respond_to?(:force_encoding)
          name = name.dup.force_encoding('binary')
        end
        CGI.escape(name)
      end
    end
  end
end

Version data entries

8 entries across 7 versions & 2 rubygems

Version Path
abaci-0.3.0 vendor/bundle/gems/yard-0.9.2/lib/yard/server/doc_server_serializer.rb
abaci-0.3.0 vendor/bundle/gems/yard-0.9.1/lib/yard/server/doc_server_serializer.rb
yard-0.9.5 lib/yard/server/doc_server_serializer.rb
yard-0.9.4 lib/yard/server/doc_server_serializer.rb
yard-0.9.3 lib/yard/server/doc_server_serializer.rb
yard-0.9.2 lib/yard/server/doc_server_serializer.rb
yard-0.9.1 lib/yard/server/doc_server_serializer.rb
yard-0.9.0 lib/yard/server/doc_server_serializer.rb