Module: YARD::Server::DocServerHelper

Included in:
Commands::DisplayObjectCommand, Commands::SearchCommand
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



67
68
69
70
# File 'lib/yard/server/doc_server_helper.rb', line 67

def base_path(path)
  libname = router.request.version_supplied ? @library.to_s : @library.name
  path + (@single_library ? '' : "/#{libname}")
end

#routerRouter

Returns convenience method for accessing the router.

Returns:

  • (Router)

    convenience method for accessing the router

Since:

  • 0.6.0



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

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
15
16
17
# File 'lib/yard/server/doc_server_helper.rb', line 10

def url_for(obj, anchor = nil, relative = false)
  return '' if obj.nil?
  return url_for_index if obj == '_index.html'
  return "/#{obj}" if String === obj
  url = super(obj, anchor, false)
  return unless url
  File.join('', base_path(router.docs_prefix), url)
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:

Returns:

  • (String)

    the URL pointing to the file

Since:

  • 0.6.0



23
24
25
26
27
28
29
# File 'lib/yard/server/doc_server_helper.rb', line 23

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

#url_for_framesetString

Returns the frames URL for the page

Returns:

  • (String)

    the URL pointing to the frames page

Since:

  • 0.6.0



41
42
43
44
45
# File 'lib/yard/server/doc_server_helper.rb', line 41

def url_for_frameset
  url = options.file ? url_for_file(options.file) : url_for(object)
  url = url.gsub(%r{^/#{base_path(router.docs_prefix)}/}, '')
  File.join('', base_path(router.docs_prefix), "frames", url)
end

#url_for_indexString

Returns the URL for the alphabetic index page

Returns:

  • (String)

    the URL pointing to the first main page the user should see.

Since:

  • 0.6.0



59
60
61
# File 'lib/yard/server/doc_server_helper.rb', line 59

def url_for_index
  File.join('', base_path(router.docs_prefix), 'index')
end

#url_for_list(type) ⇒ String

Modifies Templates::Helpers::HtmlHelper#url_for_list to return a URL based on the list prefix instead of a HTML filename.

Parameters:

  • type (String, Symbol)

    the list type to generate a URL for

Returns:

  • (String)

    the URL pointing to the list

Since:

  • 0.6.0



35
36
37
# File 'lib/yard/server/doc_server_helper.rb', line 35

def url_for_list(type)
  File.join('', base_path(router.list_prefix), type.to_s)
end

#url_for_mainString

Returns the main URL, first checking a readme and then linking to the index

Returns:

  • (String)

    the URL pointing to the first main page the user should see.

Since:

  • 0.6.0



49
50
51
52
53
54
55
# File 'lib/yard/server/doc_server_helper.rb', line 49

def url_for_main
  if options.frames && !options.command.path.empty?
    File.join('', base_path(router.docs_prefix), options.command.path)
  else
    options.readme ? url_for_file(options.readme) : url_for_index
  end
end