Class: Wurk::Web::Extension::Renderer

Inherits:
Object
  • Object
show all
Defined in:
lib/wurk/web/extension.rb

Overview

Ties it together: finds a registered extension by name, captures its routes once (‘registered(app)`), matches the request, and renders.

Class Method Summary collapse

Class Method Details

.asset_file(name, file) ⇒ Object

‘[absolute_path, cache_for_seconds]` of an asset under the extension’s asset_paths, or nil if the extension/file isn’t found. The expand_path prefix check rejects ‘../` traversal out of the dir.



244
245
246
247
248
249
250
251
252
253
254
255
# File 'lib/wurk/web/extension.rb', line 244

def asset_file(name, file)
  ext = registered_extension(name)
  return nil unless ext

  Array(ext[:asset_paths]).each do |dir|
    path = ::File.expand_path(::File.join(dir, file.to_s))
    next unless path.start_with?("#{::File.expand_path(dir)}/") && ::File.file?(path)

    return [path, ext[:cache_for] || 86_400]
  end
  nil
end

.call(name:, method:, subpath:, env:, mount:, embed: true) ⇒ Array(Integer, Hash, String)

‘embed: true` (the engine’s ext/:name/* endpoint) rewrites links and redirects into the embed URL space; ‘embed: false` (the standalone `run Sidekiq::Web` Rack app, #204) leaves the extension’s own route paths as the URL space, like upstream. rubocop:disable Metrics/ParameterLists – request facts (name/verb/path/env) + URL-space (mount/embed); bundling them would just rename the list

Returns:

  • (Array(Integer, Hash, String))

    Rack-ish [status, headers, body] — 200 HTML, 302 redirect, or 404 — or nil when no extension with ‘name` is registered (so the engine can fall through).



228
229
230
231
232
233
234
235
236
237
238
# File 'lib/wurk/web/extension.rb', line 228

def call(name:, method:, subpath:, env:, mount:, embed: true)
  ext = registered_extension(name)
  return nil unless ext

  verb = method.to_s.upcase
  route, block, route_params = match_route(ext, verb, subpath)
  return [404, html_headers, "No #{verb} route #{subpath} in extension #{name}"] unless route

  env['wurk.ext.subpath'] = subpath
  render(ext, route_params, block, env, { mount: mount, embed: embed })
end