module RailsToolViews::SurfacesHelper
Rails view helpers for authorized rendering and action forms.
Constants
- TEXT
-
Engine-owned copy. Translate or reword any of it under rails_tool_views.surface.<key>.
Public Instance Methods
# File app/helpers/rails_tool_views/surfaces_helper.rb, line 48 def rails_tool_views_action_fields(surface, action) key = action.to_s unless RailsToolViews.registry.fetch(surface.component_key).actions.key?(key) raise ArgumentError, "#{surface.component_key} does not register the action #{key.inspect}" end safe_join({ action_name: key, base_revision: surface.revision, idempotency_key: SecureRandom.uuid, source_component: surface.component_key } .map { |name, value| hidden_field_tag(name, value, id: nil) }) end
The routing fields alone, for a form the host builds itself.
# File app/helpers/rails_tool_views/surfaces_helper.rb, line 33 def rails_tool_views_action_form(surface, action, **options, &block) fields = rails_tool_views_action_fields(surface, action) form_with(url: rails_tool_views_routes.surface_actions_path(surface), method: :post, scope: :arguments, namespace: surface.dom_id, **options) do |form| safe_join([fields, (capture(form, &block) if block)]) end end
# File app/helpers/rails_tool_views/surfaces_helper.rb, line 26 def rails_tool_views_component_name(key) t(key.to_s, scope: %i[rails_tool_views components], default: RailsToolViews.registry.fetch(key).description) end
The accessible name of a registered component: the translation under rails_tool_views.components.<key>, or its registered description. Looked up per render, so it follows the requestโs locale.
# File app/helpers/rails_tool_views/surfaces_helper.rb, line 15 def rails_tool_views_surface(surface, scope:, error: nil) RailsToolViews.render(surface, view_context: self, scope: scope, error: error) end
Renders the Surface with a fresh scope and optional field feedback.
# File app/helpers/rails_tool_views/surfaces_helper.rb, line 19 def rails_tool_views_text(key, **values) t(key, scope: %i[rails_tool_views surface], default: TEXT.fetch(key), **values) end