Sha256: 0957e80737f72c1424ccc47a7cfc3e1b78b24fc200ef820b7fe4903cf09d369c

Contents?: true

Size: 1.45 KB

Versions: 5

Compression:

Stored size: 1.45 KB

Contents

module YARD
  module Server
    # A module that is mixed into {Templates::Template} in order to customize
    # certain template methods.
    module DocServerHelper
      # Modifies {Templates::Helpers::HtmlHelper#url_for} to return a URL instead
      # of a disk location.
      # @param (see Templates::Helpers::HtmlHelper#url_for)
      # @return (see Templates::Helpers::HtmlHelper#url_for)
      def url_for(obj, anchor = nil, relative = false)
        return '' if obj.nil?
        return "/#{obj}" if String === obj
        super(obj, anchor, false)
      end

      # Modifies {Templates::Helpers::HtmlHelper#url_for_file} to return a URL instead
      # of a disk location.
      # @param (see Templates::Helpers::HtmlHelper#url_for_file)
      # @return (see Templates::Helpers::HtmlHelper#url_for_file)
      def url_for_file(filename, anchor = nil)
        "/#{base_path(router.docs_prefix)}/file/" + filename.sub(%r{^#{@library.source_path.to_s}/}, '') + 
          (anchor ? "##{anchor}" : "")
      end
      
      # @example The base path for a library 'foo'
      #   base_path('docs') # => 'docs/foo'
      # @param [String] path the path prefix for a base path URI
      # @return [String] the base URI for a library with an extra +path+ prefix
      def base_path(path)
        path + (@single_library ? '' : "/#{@library}")
      end
      
      # @return [Router] convenience method for accessing the router
      def router; @adapter.router end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
yard-0.6.8 lib/yard/server/doc_server_helper.rb
yard-0.6.7 lib/yard/server/doc_server_helper.rb
yard-0.6.6 lib/yard/server/doc_server_helper.rb
yard-0.6.5 lib/yard/server/doc_server_helper.rb
yard-0.6.4 lib/yard/server/doc_server_helper.rb