Module: YARD::Server::Commands::StaticFileHelpers
- Includes:
- HTTPUtils
- Included in:
- RootRequestCommand, StaticFileCommand
- Defined in:
- lib/yard/server/commands/static_file_helpers.rb
Overview
Include this module to get access to #static_template_file? and #favicon? helpers.
Constant Summary
Constants included from HTTPUtils
HTTPUtils::DefaultMimeTypes, HTTPUtils::ESCAPED, HTTPUtils::NONASCII, HTTPUtils::UNESCAPED, HTTPUtils::UNESCAPED_FORM, HTTPUtils::UNESCAPED_PCHAR
Class Method Summary collapse
Instance Method Summary collapse
- 
  
    
      #favicon?  ⇒ Boolean 
    
    
  
  
  
  
  
  
  
  
  
    Serves an empty favicon. 
- 
  
    
      #static_template_file?  ⇒ void 
    
    
  
  
  
  
  
  
  
  
  
    Attempts to route a path to a static template file. 
Methods included from HTTPUtils
_escape, _make_regex, _make_regex!, _unescape, dequote, escape, escape8bit, escape_form, escape_path, load_mime_types, mime_type, normalize_path, parse_form_data, parse_header, parse_query, parse_qvalues, parse_range_header, quote, split_header_value, unescape, unescape_form
Class Method Details
.find_file(adapter, url) ⇒ Object
| 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | # 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 Method Details
#favicon? ⇒ Boolean
Serves an empty favicon.
| 14 15 16 17 18 19 20 | # 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
This method returns an undefined value.
Attempts to route a path to a static template file.
| 26 27 28 29 30 31 32 33 34 35 36 37 38 | # 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 |