Class: SolidObjects::ComponentsController
- Inherits:
-
ActionController::Base
- Object
- ActionController::Base
- SolidObjects::ComponentsController
- Defined in:
- app/controllers/solid_objects/components_controller.rb,
sig/generated/controllers/solid_objects/components_controller.rbs
Instance Method Summary collapse
- #component_frame(registration, snapshot, rendered) ⇒ String
- #component_view_context ⇒ Object
- #newer_than_snapshot?(requested_revision, snapshot) ⇒ Boolean
- #requested_revision_key ⇒ Array[Integer]
- #show ⇒ void
Instance Method Details
#component_frame(registration, snapshot, rendered) ⇒ String
69 70 71 72 73 74 75 76 |
# File 'app/controllers/solid_objects/components_controller.rb', line 69 def component_frame(registration, snapshot, rendered) target = DomIdentity.component( registration.reference, registration.component_name ) revision = "#{snapshot.instance_id}:#{snapshot.revision}" %(<turbo-frame id="#{target}" data-solid-objects-revision="#{revision}">#{rendered}</turbo-frame>).html_safe end |
#component_view_context ⇒ Object
58 59 60 61 62 63 64 65 66 |
# File 'app/controllers/solid_objects/components_controller.rb', line 58 def component_view_context if defined?(Rails) && Rails.application prepend_view_path(*Rails.application.paths["app/views"].existent) end view_context.tap do |context| context.extend(Rails.application.helpers) if defined?(Rails) && Rails.application end end |
#newer_than_snapshot?(requested_revision, snapshot) ⇒ Boolean
53 54 55 |
# File 'app/controllers/solid_objects/components_controller.rb', line 53 def newer_than_snapshot?(requested_revision, snapshot) (requested_revision <=> [ snapshot.instance_id, snapshot.revision ]) == 1 end |
#requested_revision_key ⇒ Array[Integer]
44 45 46 47 48 49 50 |
# File 'app/controllers/solid_objects/components_controller.rb', line 44 def requested_revision_key instance_id = Integer(params.fetch(:instance_id), 10) revision = Integer(params.fetch(:revision), 10) raise ArgumentError if instance_id.negative? || revision.negative? [ instance_id, revision ] end |
#show ⇒ void
This method returns an undefined value.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'app/controllers/solid_objects/components_controller.rb', line 10 def show registration = ComponentRegistration.from_token( params.require(:token) ) requested_revision = requested_revision_key snapshot = ActorSnapshot.new(registration.reference) return head :conflict if newer_than_snapshot?(requested_revision, snapshot) = SolidObjects .configuration . .call(controller: self) rendered = ComponentRenderer.new( snapshot:, component_name: registration.component_name, dependencies: registration.dependencies, view_context: component_view_context, authorization_context: ).call response.headers["Cache-Control"] = "private, no-store" render html: component_frame(registration, snapshot, rendered) rescue Unauthorized head :forbidden rescue UnknownComponent head :not_found rescue ActionController::ParameterMissing, ArgumentError, InvalidComponentToken head :bad_request end |