Module: Authtown::ViewMixin
- Defined in:
- lib/authtown/view_mixin.rb
Instance Method Summary collapse
- #current_user ⇒ Object
- #find_template(opts) ⇒ Object
- #locals ⇒ Object
- #login_failed_reset_password_request_form ⇒ Object
-
#parse_template_opts(template, opts) ⇒ Object
Return a single hash combining the template and opts arguments.
- #template_path(opts) ⇒ Object
-
#view(*args, view_class: Bridgetown::ERBView, **kwargs) ⇒ Object
rubocop:disable Metrics.
Instance Method Details
#current_user ⇒ Object
6 |
# File 'lib/authtown/view_mixin.rb', line 6 def current_user = Authtown::Current.user |
#find_template(opts) ⇒ Object
21 |
# File 'lib/authtown/view_mixin.rb', line 21 def find_template(opts) = opts |
#locals ⇒ Object
4 |
# File 'lib/authtown/view_mixin.rb', line 4 def locals = @_route_locals |
#login_failed_reset_password_request_form ⇒ Object
25 26 27 |
# File 'lib/authtown/view_mixin.rb', line 25 def login_failed_reset_password_request_form # 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.
11 12 13 14 15 16 17 18 19 |
# File 'lib/authtown/view_mixin.rb', line 11 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
23 |
# File 'lib/authtown/view_mixin.rb', line 23 def template_path(opts) = opts[:template] |
#view(*args, view_class: Bridgetown::ERBView, **kwargs) ⇒ Object
rubocop:disable Metrics
29 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 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/authtown/view_mixin.rb', line 29 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 # TODO: this should really be some sort of exposed method from the routes plugin response["X-Bridgetown-SSR"] = "1" Bridgetown::Routes::Manifest.generate_manifest(bridgetown_site).each do |route| file, localized_file_slugs = route file_slug = localized_file_slugs.first next unless file_slug == kwargs[:template] Bridgetown::Routes::CodeBlocks.eval_route_file file, file_slug, self route_block = Bridgetown::Routes::CodeBlocks.route_block(file_slug) response.instance_variable_set( :@_route_file_code, route_block.instance_variable_get(:@_route_file_code) ) # could be nil @_route_locals = kwargs[:locals] return instance_exec(request, &route_block) end Bridgetown.logger.warn("Rodauth template not found: #{kwargs[:template]}") nil # couldn't find template, 404 end |