Module: Aker::Form::LoginFormAssetProvider

Includes:
Rack::ConfigurationHelper, 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:

  • David Yip

Instance Method Summary collapse

Methods included from Rack::ConfigurationHelper

#login_path, #logout_path

Methods included from Rack::EnvironmentHelper

#authority, #configuration, #interactive?

Instance Method Details

#asset_rootString

Where to look for HTML and CSS assets.

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



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

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

#login_cssString

Provides the CSS for the login form.



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

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

#login_html(env, options = {}) ⇒ String

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.

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



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

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