Documentation
¶
Overview ¶
Package snippets manages the pre-written HTML blocks editors can insert into rich regions from the in-place editor's palette. Snippets come from two places: the host application's config (per-customer components, versioned with the code) and the database (created by admins in the admin UI). Once inserted, a snippet is ordinary region content — edited in place, sanitized on save, and styled entirely by the host site's CSS.
Index ¶
- Variables
- type Snippet
- type Store
- func (s *Store) All(ctx context.Context) ([]Snippet, error)
- func (s *Store) Count(ctx context.Context) (int, error)
- func (s *Store) Delete(ctx context.Context, id int64) error
- func (s *Store) GetByID(ctx context.Context, id int64) (*Snippet, error)
- func (s *Store) Insert(ctx context.Context, sn *Snippet) (int64, error)
- func (s *Store) Update(ctx context.Context, sn *Snippet) error
Constants ¶
This section is empty.
Variables ¶
var ErrNotFound = errors.New("snippets: not found")
ErrNotFound is returned when no snippet matches the query.
Functions ¶
This section is empty.
Types ¶
type Snippet ¶
type Snippet struct {
ID int64
Name string
HTML string
Settings map[string]string
CreatedAt time.Time
UpdatedAt time.Time
}
Snippet is one insertable block. ID is set only for database-stored snippets; config-registered ones have ID zero.
A snippet with a non-nil Settings map is a *section preset*: instead of a block dropped into existing content, it is a starting point for a whole section — the editor offers it only in the "Add a section" chooser, and applies the settings (background, width, height, vertical alignment) to the new section along with the HTML. Keys and values are the section-settings vocabulary: "bg" and "width" name curated SectionStyles option keys, "height" is "50"/"75"/"100", "valign" is "center"/"bottom", "bgcolor" is #rrggbb, "bgimage" is a URL, and "bgposition" anchors that image as a pair of percentages across and down, e.g. "50% 20%" ("50% 50%" is centered, and is the default). Unknown keys or invalid values fall back to the defaults, same as the section settings dialog. Presets come from config or from the admin snippets UI (which offers the curated settings; the free-form bgcolor/bgimage/bgposition are config-only).
func DefaultSectionPresets ¶
func DefaultSectionPresets() []Snippet
DefaultSectionPresets is the Tailwind-first default library of section presets — snippets with Settings, offered as one-click starting points in the "Add a section" chooser. Two markup strategies, chosen per preset: markup that should adapt when the editor later changes the section background skips not-prose and leans on prose/prose-invert for its colors (Hero, CTA, FAQ); grid layouts that Typography would restyle use not-prose with explicit slate colors and suit light backgrounds (Feature grid, Stats, Testimonials). Like DefaultSnippets, every class must be safelisted in the site's Tailwind build (see the README).
func DefaultSnippets ¶
func DefaultSnippets() []Snippet
DefaultSnippets is the Tailwind-first default library, used when the host does not configure its own. The markup avoids elements the editor sanitizer strips (no SVG, no scripts) and uses `not-prose` so Tailwind Typography doesn't restyle component internals. Like the editor styles, every class here must be safelisted in the site's Tailwind build (see the README). The cms-snippet marker class on each snippet's root makes the block manageable in the in-place editor: a dotted outline while editing, and a floating drag-handle/trash chrome when clicked. Like cms-btn (which marks a link as an editable button), it carries no CSS of its own.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store reads and writes admin-created snippets in Postgres.
func (*Store) Count ¶
Count returns how many stored snippets exist — the admin adds the host-registered ones and shows the total beside its Snippets nav entry.
func (*Store) Delete ¶
Delete removes a stored snippet. Content already inserted into pages is unaffected — inserted snippets are plain region HTML.