Module: Authtown::ViewMixin

Defined in:
lib/authtown/view_mixin.rb

Overview

This gets prepended into the RodaApp class

Instance Method Summary collapse

Instance Method Details

#current_userObject



7
# File 'lib/authtown/view_mixin.rb', line 7

def current_user = Authtown::Current.user

#find_template(opts) ⇒ Object



22
# File 'lib/authtown/view_mixin.rb', line 22

def find_template(opts) = opts

#localsObject



5
# File 'lib/authtown/view_mixin.rb', line 5

def locals = @_route_locals

#login_failed_reset_password_request_formObject



26
27
28
# File 'lib/authtown/view_mixin.rb', line 26

def 
  # part of reset_password internals…no-op since we're rendering our own forms
end

#parse_template_opts(template, opts) ⇒ Object

Return a single hash combining the template and opts arguments.



12
13
14
15
16
17
18
19
20
# File 'lib/authtown/view_mixin.rb', line 12

def parse_template_opts(template, opts)
  opts = opts.to_h
  if template.is_a?(Hash)
    opts.merge!(template)
  else
    opts[:template] = template
    opts
  end
end

#template_path(opts) ⇒ Object



24
# File 'lib/authtown/view_mixin.rb', line 24

def template_path(opts) = opts[:template]

#view(*args, view_class: Bridgetown::ERBView, **kwargs) ⇒ Object

rubocop:disable Metrics



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/authtown/view_mixin.rb', line 30

def view(*args, view_class: Bridgetown::ERBView, **kwargs) # rubocop:disable Metrics
  kwargs = args.first if args.first.is_a?(Hash)

  return super if kwargs.empty? # regular Bridgetown behavior

  unless kwargs.dig(:locals, :rodauth)
    raise "The `view' method with keyword arguments should only be used by Rodauth internally. " \
          "It is not supported by Bridgetown's view layer."
  end

  if kwargs.dig(:locals, :rodauth)&.prefix
    kwargs[:template] =
      "#{kwargs.dig(:locals, :rodauth).prefix.delete_prefix("/")}/#{kwargs[:template]}"
  end

  routes_manifest.routes.each do |route|
    file, localized_slugs = route
    next unless localized_slugs.first == kwargs[:template]

    return run_file_route(file, slug: localized_slugs.first)
  end

  Bridgetown.logger.warn("Rodauth template not found: #{kwargs[:template]}")
  nil # couldn't find template, 404
end