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.
Instance Method Summary collapse
-
#base_path(path) ⇒ String
The base URI for a library with an extra
path
prefix. -
#router ⇒ Router
Convenience method for accessing the router.
-
#url_for(obj, anchor = nil, relative = false) ⇒ String
Modifies Templates::Helpers::HtmlHelper#url_for to return a URL instead of a disk location.
-
#url_for_file(filename, anchor = nil) ⇒ String
Modifies Templates::Helpers::HtmlHelper#url_for_file to return a URL instead of a disk location.
-
#url_for_frameset ⇒ String
Returns the frames URL for the page.
-
#url_for_index ⇒ String
Returns the URL for the alphabetic index page.
-
#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.
-
#url_for_main ⇒ String
Returns the main URL, first checking a readme and then linking to the index.
Instance Method Details
#base_path(path) ⇒ String
Returns the base URI for a library with an extra path
prefix.
65 66 67 68 |
# File 'lib/yard/server/doc_server_helper.rb', line 65 def base_path(path) libname = router.request.version_supplied ? @library.to_s : @library.name path + (@single_library ? '' : "/#{libname}") end |
#router ⇒ Router
Returns convenience method for accessing the router.
71 |
# File 'lib/yard/server/doc_server_helper.rb', line 71 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.
10 11 12 13 14 15 |
# 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 File.join('', base_path(router.docs_prefix), 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.
21 22 23 24 25 26 27 |
# File 'lib/yard/server/doc_server_helper.rb', line 21 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_frameset ⇒ String
Returns the frames URL for the page
39 40 41 42 43 |
# File 'lib/yard/server/doc_server_helper.rb', line 39 def url_for_frameset url = .file ? url_for_file(.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_index ⇒ String
Returns the URL for the alphabetic index page
57 58 59 |
# File 'lib/yard/server/doc_server_helper.rb', line 57 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.
33 34 35 |
# File 'lib/yard/server/doc_server_helper.rb', line 33 def url_for_list(type) File.join('', base_path(router.list_prefix), type.to_s) end |
#url_for_main ⇒ String
Returns the main URL, first checking a readme and then linking to the index
47 48 49 50 51 52 53 |
# File 'lib/yard/server/doc_server_helper.rb', line 47 def url_for_main if .frames && !.command.path.empty? File.join('', base_path(router.docs_prefix), .command.path) else .readme ? url_for_file(.readme) : url_for_index end end |