Module: Useless::Rack::Doc

Defined in:
lib/useless/rack/doc.rb

Overview

‘Useless::Doc` is a module that handles serving documentation

Constant Summary collapse

TEMPLATE =
<<-BLOCK
<!DOCTYPE html>
<html>
<head>
  <title>useless.io</title>
  <link href="/application.css" media="screen" rel="stylesheet" type="text/css" />
</head>
<body>
  <div id="container">
    <%= body %>
  </div>
</body>
</html>
BLOCK

Class Method Summary collapse

Class Method Details

.serve(file_or_path) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/useless/rack/doc.rb', line 22

def self.serve(file_or_path)
  # Read the contents of the file or the file at the specified path.
  body = file_or_path.is_a?(File) ?
    file_or_path.read : File.read(file_or_path)

  # Render the template,
  response = ERB.new(TEMPLATE).result(binding)

  # and return it as a Rack response.
  [200, {'Content-Type' => 'text/html'}, [response]]
end