Module: Clickwrap::EngineHelper

Defined in:
app/helpers/clickwrap/engine_helper.rb

Overview

View helpers, available BOTH inside the engine's own views and in the HOST app's views (mixed into ActionView by the hook at the bottom of this file, the same pattern the chats and moderate gems use).

Everything here is prefixed clickwrap_, because these methods land in every view in the host application and a gem has no business claiming a short name in that namespace.

Instance Method Summary collapse

Instance Method Details

#clickwrap_capture_path(policy_key) ⇒ Object

The standalone capture screen for one policy — the remediation route:

<%= link_to "Complete your declaration", clickwrap_capture_path(:contractor_declaration) %>

Any extra options become query parameters, which is how a caller passes return_to: for a flow that should resume where it left off.



18
19
20
# File 'app/helpers/clickwrap/engine_helper.rb', line 18

def clickwrap_capture_path(policy_key, **)
  clickwrap_routes.capture_path(policy_key, **)
end

#clickwrap_document_version_path(version) ⇒ Object

The exact published bytes of one document version — what the presentation links to, and what an auditor reads later.



38
39
40
41
42
# File 'app/helpers/clickwrap/engine_helper.rb', line 38

def clickwrap_document_version_path(version, **)
  identifier = version.respond_to?(:id) ? version.id : version

  clickwrap_routes.document_version_path(identifier, **)
end

#clickwrap_main_routesObject

The host application's own routes, reachable from inside this isolated engine's views — where a bare some_path would be resolved against the engine's route set and explode.



69
70
71
# File 'app/helpers/clickwrap/engine_helper.rb', line 69

def clickwrap_main_routes
  respond_to?(:main_app) ? main_app : Rails.application.routes.url_helpers
end

#clickwrap_receipt_path(receipt) ⇒ Object

A receipt, addressed by the event it belongs to. Takes a receipt, an event, or a bare event id, because all three turn up in host code.



24
25
26
# File 'app/helpers/clickwrap/engine_helper.rb', line 24

def clickwrap_receipt_path(receipt, **)
  clickwrap_routes.receipt_path(clickwrap_event_id_for(receipt), **)
end

#clickwrap_routesObject

Engine URL helpers that work from EVERY render context:

* host views: the mounted proxy (`clickwrap.`) carries the mount prefix
baked in at mount time, so URLs come out right;
* engine views during requests: the engine's controllers inherit from
the host's ApplicationController, so the proxy is available there too;
* no mount at all (bare view tests): fall back to the engine's own
url_helpers — prefix-less, but nothing better exists without a mount.

NOTE: assumes the default mount name (mount Clickwrap::Engine => "/x" auto-names the proxy clickwrap). A host mounting with as: :something overrides this helper.



62
63
64
# File 'app/helpers/clickwrap/engine_helper.rb', line 62

def clickwrap_routes
  respond_to?(:clickwrap) ? clickwrap : Clickwrap::Engine.routes.url_helpers
end

#clickwrap_stylesObject

The gem's bundled stylesheet. Called from the engine's own views; hosts that eject and restyle the views simply stop including it.



46
47
48
# File 'app/helpers/clickwrap/engine_helper.rb', line 46

def clickwrap_styles
  stylesheet_link_tag "clickwrap", "data-turbo-track": "reload"
end

#clickwrap_withdrawal_path(purpose_key) ⇒ Object

Where someone withdraws one consent purpose. Withdrawal is a first-class screen and not a buried mailto: link, because consent that cannot be withdrawn as easily as it was given is not something this gem will keep calling consent.



32
33
34
# File 'app/helpers/clickwrap/engine_helper.rb', line 32

def clickwrap_withdrawal_path(purpose_key, **)
  clickwrap_routes.withdrawal_path(purpose_key, **)
end