Module: Aker::Form::LoginFormAssetProvider

Includes:
Rack::Utils
Included in:
Middleware::LoginRenderer, Middleware::LoginResponder, Middleware::LogoutResponder
Defined in:
lib/aker/form/login_form_asset_provider.rb

Overview

Provides HTML and CSS for login forms.

Author:

Instance Method Summary (collapse)

Instance Method Details

- (String) asset_root

Where to look for HTML and CSS assets.

This is currently hardcoded as (aker gem root)/aker/modes/middleware/form.

Returns:

  • (String)

    a directory path



19
20
21
22
23
# File 'lib/aker/form/login_form_asset_provider.rb', line 19

def asset_root
  File.expand_path(File.join(File.dirname(__FILE__),
                             %w(.. .. ..),
                             %w(assets aker modes middleware form)))
end

- (String) login_css

Provides the CSS for the login form.

Returns:

  • (String)

    CSS data



51
52
53
# File 'lib/aker/form/login_form_asset_provider.rb', line 51

def 
  File.read(File.join(asset_root, 'login.css'))
end

- (String) login_html(env, options = {})

Provides the HTML for the login form.

This method expects to find a login.html.erb ERB template in #asset_root. The ERB template is evaluated in an environment where a local variable named script_name is bound to the value of the SCRIPT_NAME Rack environment variable, which is useful for CSS and form action URL generation.

Parameters:

  • env (Rack environment)

    a Rack environment

  • options (Hash) (defaults to: {})

    rendering options

Options Hash (options):

  • :login_failed (Boolean)

    If true, will render a failure message

  • :logged_out (Boolean)

    If true, will render a logout notification

  • :username (String)

    Text for the username field

  • :url (String)

    A URL to redirect to upon successful login

Returns:

  • (String)

    HTML data



41
42
43
44
45
# File 'lib/aker/form/login_form_asset_provider.rb', line 41

def (env, options = {})
  script_name = env['SCRIPT_NAME']
  template = File.read(File.join(asset_root, 'login.html.erb'))
  ERB.new(template).result(binding)
end