Sha256: 995ed6f77e15f40f66f373ab18990afff59c5ba28a8049e7e9e95d992a5dd39e

Contents?: true

Size: 1.61 KB

Versions: 3

Compression:

Stored size: 1.61 KB

Contents

module YARD
  module Server
    module Commands
      # Displays documentation for a specific object identified by the path
      class DisplayObjectCommand < LibraryCommand
        include DocServerHelper

        def run
          if path.empty?
            if options.readme
              filename = options.readme.filename
              opts = adapter.options.merge(
                :index => true, :library => library,
                :path => filename.sub(%r{^#{library.source_path.to_s}/}, ''))
              self.status, self.headers, self.body =
                *DisplayFileCommand.new(opts).call(request)
              cache(self.body)
              return
            else
              self.path = 'index'
            end
          end
          return index if path == 'index'

          if object = Registry.at(object_path)
            options.update(:type => :layout)
            render(object)
          else
            not_found
          end
        end

        def index
          Registry.load_all

          options.update(
            :object => '_index.html',
            :objects => Registry.all(:module, :class),
            :type => :layout
          )
          render
        end

        def not_found
          super
          self.body = "Could not find object: #{object_path}"
        end

        private

        def object_path
          return @object_path if @object_path
          if path == "toplevel"
            @object_path = :root
          else
            @object_path = path.sub(':', '#').gsub('/', '::').sub(/^toplevel\b/, '').sub(/\.html$/, '')
          end
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
yard-0.9.5 lib/yard/server/commands/display_object_command.rb
yard-0.9.4 lib/yard/server/commands/display_object_command.rb
yard-0.9.3 lib/yard/server/commands/display_object_command.rb