Module: Aspera::WebPage

Defined in:
lib/aspera/web_page.rb

Overview

HTML pages of embedded web servers, sharing a layout: style and branding. The ERB template of each page is the content of the card of the layout, with its own variables.

Class Method Summary collapse

Class Method Details

.render(template_path, title:, **variables) ⇒ String

Returns HTML page.

Parameters:

  • template_path (String) —

    Path of the ERB template of the content of the page

  • title (String) —

    Title of the page

  • variables (Hash) —

    Variables of the template of the content

Returns:



60
61
62
63
# File 'lib/aspera/web_page.rb', line 60

def render(template_path, title:, **variables)
  content = Context.new(variables).render(template_path)
  Context.new(title: title, content: content).render(LAYOUT_PATH)
end

.secure_headers(response, content_security_policy: nil) ⇒ nil

Set the headers of an HTML page: type and security headers

Parameters:

  • response (WEBrick::HTTPResponse)
  • content_security_policy (String, nil) (defaults to: nil) —

    Policy that replaces the default one, e.g. to allow a script of the page

Returns:

  • (nil)


50
51
52
53
54
# File 'lib/aspera/web_page.rb', line 50

def secure_headers(response, content_security_policy: nil)
  HEADERS.each { |name, value| response[name] = value }
  response['Content-Security-Policy'] = content_security_policy unless content_security_policy.nil?
  nil
end