Module: YARD::Server::DocServerHelper

Included in:
Commands::FramesCommand
Defined in:
lib/yard/server/doc_server_helper.rb

Overview

A module that is mixed into Templates::Template in order to customize certain template methods.

Since:

  • 0.6.0

Instance Method Summary collapse

Instance Method Details

#base_path(path) ⇒ String

Returns the base URI for a library with an extra path prefix.

Examples:

The base path for a library ‘foo’

base_path('docs') # => 'docs/foo'

Parameters:

  • path (String)

    the path prefix for a base path URI

Returns:

  • (String)

    the base URI for a library with an extra path prefix

Since:

  • 0.6.0



29
30
31
# File 'lib/yard/server/doc_server_helper.rb', line 29

def base_path(path)
  path + (@single_library ? '' : "/#{@library}")
end

#routerRouter

Returns convenience method for accessing the router.

Returns:

  • (Router)

    convenience method for accessing the router

Since:

  • 0.6.0



34
# File 'lib/yard/server/doc_server_helper.rb', line 34

def router; @adapter.router end

#url_for(obj, anchor = nil, relative = false) ⇒ String

Modifies Templates::Helpers::HtmlHelper#url_for to return a URL instead of a disk location.

Parameters:

  • obj (String, CodeObjects::Base)

    the object (or object path) to link to

  • anchor (String) (defaults to: nil)

    the anchor to link to

  • relative (Boolean) (defaults to: false)

    use a relative or absolute link

Returns:

  • (String)

    the URL location of the object

Since:

  • 0.6.0



10
11
12
13
14
# File 'lib/yard/server/doc_server_helper.rb', line 10

def url_for(obj, anchor = nil, relative = false)
  return '' if obj.nil?
  return "/#{obj}" if String === obj
  super(obj, anchor, false)
end

#url_for_file(filename, anchor = nil) ⇒ String

Modifies Templates::Helpers::HtmlHelper#url_for_file to return a URL instead of a disk location.

Parameters:

  • filename (String)

    the filename to link to

  • anchor (String) (defaults to: nil)

    optional anchor

Returns:

  • (String)

    the URL pointing to the file

Since:

  • 0.6.0



20
21
22
23
# File 'lib/yard/server/doc_server_helper.rb', line 20

def url_for_file(filename, anchor = nil)
  "/#{base_path(router.docs_prefix)}/file/" + filename.sub(%r{^#{@library.source_path.to_s}/}, '') + 
    (anchor ? "##{anchor}" : "")
end