123456789_123456789_123456789_123456789_123456789_

Module: YARD::Server::Commands::StaticFileHelpers

Relationships & Source Files
Extension / Inclusion / Inheritance Descendants
Included In:
Super Chains via Extension / Inclusion / Inheritance
Instance Chain:
Defined in: lib/yard/server/commands/static_file_helpers.rb

Overview

Include this module to get access to #static_template_file? and #favicon? helpers.

Since:

  • 0.6.0

Constant Summary

::YARD::Server::HTTPUtils - Included

DefaultMimeTypes, ESCAPED, NONASCII, UNESCAPED, UNESCAPED_FORM, UNESCAPED_PCHAR

Class Method Summary

Instance Attribute Summary

Instance Method Summary

::YARD::Server::HTTPUtils - Included

#_escape, #_make_regex, #_make_regex!, #_unescape,
#dequote

Removes quotes and escapes from str.

#escape

Escapes HTTP reserved and unwise characters in str.

#escape8bit

Escapes 8 bit characters in str.

#escape_form

Escapes form reserved characters in str.

#escape_path

Escapes path str.

#load_mime_types

Loads Apache-compatible mime.types in file.

#mime_type

Returns the mime type of filename from the list in mime_tab.

#normalize_path

Normalizes a request path.

#parse_form_data

Parses form data in io with the given boundary.

#parse_header

Parses an HTTP header raw into a hash of header fields with an ::Array of values.

#parse_query

Parses the query component of a URI in str.

#parse_qvalues

Parses q values in value as used in Accept headers.

#parse_range_header

Parses a Range header value ranges_specifier.

#quote

Quotes and escapes quotes in str.

#split_header_value

Splits a header value str according to HTTP specification.

#unescape

Unescapes HTTP reserved and unwise characters in str.

#unescape_form

Unescapes form reserved characters in str.

Class Method Details

.find_file(adapter, url) (mod_func)

Since:

  • 0.6.0

[ GitHub ]

  
# File 'lib/yard/server/commands/static_file_helpers.rb', line 42

def find_file(adapter, url)
  # this const was defined in StaticFileCommand originally
  static_paths = StaticFileCommand::STATIC_PATHS

  file = nil
  ([adapter.document_root] + static_paths.reverse).compact.each do |path_prefix|
    file = File.join(path_prefix, url)
    break if File.exist?(file)
    file = nil
  end

  # Search in default/fulldoc/html template if nothing in static asset paths
  assets_template = Templates::Engine.template(:default, :fulldoc, :html)
  file || assets_template.find_file(url)
end

Instance Attribute Details

#favicon?Boolean (readonly)

Serves an empty favicon.

Raises:

  • (FinishRequest)

    finalizes an empty body if the path matches /favicon.ico so browsers don't complain.

Since:

  • 0.6.0

[ GitHub ]

  
# File 'lib/yard/server/commands/static_file_helpers.rb', line 14

def favicon?
  return unless request.path == '/favicon.ico'
  headers['Content-Type'] = 'image/png'
  self.status = 200
  self.body = ''
  raise FinishRequest
end

#static_template_file?void (readonly)

This method returns an undefined value.

Attempts to route a path to a static template file.

Raises:

Since:

  • 0.6.0

[ GitHub ]

  
# File 'lib/yard/server/commands/static_file_helpers.rb', line 26

def static_template_file?
  # this const was defined in StaticFileCommand originally
  default_mime_types = StaticFileCommand::DefaultMimeTypes

  file = find_file(adapter, path)

  if file
    ext = "." + (path[/\.(\w+)$/, 1] || "html")
    headers['Content-Type'] = mime_type(ext, default_mime_types)
    self.body = File.read(file)
    raise FinishRequest
  end
end