Action Text¶
Action Text adds rich-text content to a model. Content is stored as sanitized HTML against an allowlist, edited through a Trix editor, rendered with safe-buffer output, and can embed Active Storage attachments.
Rich-text content¶
A MVC::Keayl::ActionText::Content wraps a fragment of rich-text HTML.
Content.from-html sanitizes the input, keeping the rich-text allowlist of tags
and attributes and dropping everything else (scripts, event handlers, unknown
tags):
1 2 3 4 5 6 7 8 9 10 | |
sanitize-rich-text($html) runs the same allowlist on its own.
Attaching rich text to a record¶
A model includes MVC::Keayl::ActionText::RichTextable and declares its
rich-text fields with has-rich-text:
1 2 3 4 5 6 | |
Each declared name returns a proxy backed by a rich-text record:
1 2 3 4 | |
Records persist through a repository.
MVC::Keayl::ActionText::Repository defines the interface and
MemoryRepository is the in-process implementation. Configure an ORM-backed
repository at boot:
1 | |
Editing¶
rich-text-area on the form builder emits the Trix editor markup: a hidden
input that carries the value plus a <trix-editor> bound to it.
1 2 3 | |
1 2 | |
rich-text-area-tag(name, value?, %options) renders the same markup without a
form builder.
Rendering¶
The rich-text helper renders content for a view with safe-buffer output. It
accepts a Content, a rich-text proxy, or a raw HTML string (which it
sanitizes):
1 2 | |
Embedded attachments¶
An Active Storage blob can be embedded in the document as an
<action-text-attachment> element carrying a signed blob id. embed-tag($blob)
builds one:
1 2 | |
When the content renders, each attachment resolves its signed id to a blob and
expands into a <figure>. An image becomes a preview pointing at the proxy
serving path; any other file becomes a download link. An attachment whose signed
id no longer resolves is dropped.
1 2 3 | |
content.attachment-sgids lists the signed ids embedded in a document.