templates

package
v1.5.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 10, 2026 License: AGPL-3.0 Imports: 24 Imported by: 0

Documentation

Overview

Package templates holds the composer's template gallery: the starter templates that ship with ReputeCast (MJML files embedded in the binary, their placeholder images served at /media/starters/), the workspace's saved templates and its saved sections (reusable blocks).

Index

Constants

View Source
const AddressPlaceholder = "%%ADDRESS%%"

AddressPlaceholder is replaced by the workspace's postal address.

View Source
const BlogDigestStarter = "blog-digest"

BlogDigestStarter is the key of the recurring digest's starter.

View Source
const DefaultAddress = "Your company · Street and number · City, postcode"

DefaultAddress is shown when the workspace has no postal address yet; the content check flags it until it is replaced.

View Source
const StarterPrefix = "starter:"

StarterPrefix marks the ids of built-in templates ("starter:weekly-digest").

Variables

This section is empty.

Functions

func DefaultAddressIn

func DefaultAddressIn(l i18n.Lang) string

DefaultAddressIn is DefaultAddress in a reader's language: the line a starter's footer shows until the workspace sets its postal address.

func Picture

func Picture(src string) string

Picture turns an email's HTML into a picture of it: personalization shows its fallbacks (a reader without a first name), and links, scripts, frames, form controls, event handlers and focus order are taken out.

func Register

func Register(h huma.API, s *Service)

Register adds the template operations.

func StarterAssets

func StarterAssets() fs.FS

StarterAssets are the placeholder images of the starter templates.

func StarterMJML

func StarterMJML(key, address string) (string, bool)

StarterMJML returns a starter's MJML with the workspace address filled in and image URLs pointing at /media/starters/, its sample content in English.

func StarterMJMLIn

func StarterMJMLIn(l i18n.Lang, key, address string) (string, bool)

StarterMJMLIn is StarterMJML with the sample content written in l, for the readers of the email someone starts from it.

func WorkspaceAddress

func WorkspaceAddress(ws *store.Workspace) string

WorkspaceAddress reads the postal address from the workspace branding ({"address": "…"}), used to fill footers.

Types

type Brand

type Brand interface {
	Starter(ctx context.Context, ws *store.Workspace, src string) string
}

Brand puts the workspace's brand kit on a starter: its colours, fonts, button style and logo, and its synced Header and Footer (internal/brandkit, CO-11).

type EmailTemplateDetail

type EmailTemplateDetail struct {
	EmailTemplateSummary
	MJML string `json:"mjml"`
	HTML string `json:"html"`
}

EmailTemplateDetail adds the content.

type EmailTemplateGallery

type EmailTemplateGallery struct {
	Starters     []EmailTemplateSummary     `json:"starters"`
	Templates    []EmailTemplateSummary     `json:"templates"`
	Sections     []EmailTemplateSummary     `json:"sections"`
	LastCampaign *EmailTemplateLastCampaign `json:"lastCampaign,omitempty"`
}

EmailTemplateGallery is the empty-canvas gallery and the Templates tab.

type EmailTemplateInput

type EmailTemplateInput struct {
	Kind             string `json:"kind,omitempty" enum:"template,section" default:"template"`
	Name             string `json:"name" minLength:"1" maxLength:"120"`
	Description      string `json:"description,omitempty" maxLength:"300"`
	MJML             string `json:"mjml" minLength:"1" maxLength:"2000000"`
	HTML             string `json:"html,omitempty" maxLength:"2000000"`
	SourceCampaignID string `json:"sourceCampaignId,omitempty" format:"uuid"`
}

EmailTemplateInput is a new or changed template or saved section.

type EmailTemplateLastCampaign

type EmailTemplateLastCampaign struct {
	ID     string               `json:"id"`
	Name   string               `json:"name"`
	SentAt time.Time            `json:"sentAt"`
	Thumb  []mjml.MJMLThumbItem `json:"thumb"`
}

EmailTemplateLastCampaign is the most recent sent campaign, offered as "Copy of …".

type EmailTemplatePreview

type EmailTemplatePreview struct {
	HTML string `` /* 155-byte string literal not displayed */
}

EmailTemplatePreview is a template as its email reads, for the gallery.

type EmailTemplateSummary

type EmailTemplateSummary struct {
	ID          string               `json:"id" example:"starter:weekly-digest"`
	Kind        string               `json:"kind" enum:"template,section"`
	Name        string               `json:"name"`
	Description string               `json:"description"`
	Thumb       []mjml.MJMLThumbItem `json:"thumb"`
	Builtin     bool                 `json:"builtin"`
	UpdatedAt   *time.Time           `json:"updatedAt,omitempty"`
	UpdatedBy   string               `json:"updatedBy,omitempty"`
	SizeBytes   int                  `json:"sizeBytes"`
	// SourceCampaignID is the campaign a template was saved from.
	SourceCampaignID string `json:"sourceCampaignId,omitempty"`
}

EmailTemplateSummary is one tile of the gallery.

type Service

type Service struct {
	// Brand, when set, starts starters from the brand kit.
	Brand Brand
	Pool  *pgxpool.Pool
	Q     *store.Queries
	Audit *audit.Logger
	Now   func() time.Time
}

Service holds the templates domain dependencies.

func (*Service) Create

Create saves a template or a section.

func (*Service) Delete

func (s *Service) Delete(ctx context.Context, ws *store.Workspace, actor *uuid.UUID, id string) error

Delete removes a template or saved section.

func (*Service) Gallery

Gallery lists starters, the workspace's templates and saved sections, and the last sent campaign.

func (*Service) GalleryFor

func (s *Service) GalleryFor(ctx context.Context, ws *store.Workspace, digest bool) (EmailTemplateGallery, error)

GalleryFor is the gallery of the composer's regular mode, or of its digest mode (digest true), which adds the digest starters.

func (*Service) Get

func (s *Service) Get(ctx context.Context, ws *store.Workspace, id, address string) (EmailTemplateDetail, error)

Get returns a template (starter or saved) with its content. address fills a starter's footer.

func (*Service) Preview

func (s *Service) Preview(ctx context.Context, ws *store.Workspace, id, address string) (EmailTemplatePreview, error)

Preview compiles a template for the gallery's picture of it.

func (*Service) Update

Update renames a template or replaces its content.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL