core

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Jun 21, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultSkeleton

func DefaultSkeleton(headRaw string, content string, ctx *MJMLContext) (string, error)

Types

type Attribute

type Attribute = orderedmap.Element[string, string]

type Attributes

type Attributes = orderedmap.OrderedMap[string, string]

type BaseComponent

type BaseComponent struct {
	Node    *parser.MJMLNode
	Spec    *ComponentSpec
	Props   *ComponentProps
	Context *MJMLContext

	Attributes *Attributes
	Children   []Component
}

func NewBaseComponent

func NewBaseComponent(node *parser.MJMLNode, spec *ComponentSpec, props *ComponentProps, context *MJMLContext) *BaseComponent

func (*BaseComponent) GetAttribute

func (c *BaseComponent) GetAttribute(name string) *string

func (*BaseComponent) GetAttributeOr

func (c *BaseComponent) GetAttributeOr(name string, orValue string) string

func (*BaseComponent) GetChildren

func (c *BaseComponent) GetChildren() []Component

func (*BaseComponent) GetContent

func (c *BaseComponent) GetContent() string

func (*BaseComponent) IsRawElement

func (c *BaseComponent) IsRawElement() bool

func (*BaseComponent) RenderMJML

func (c *BaseComponent) RenderMJML(w MJMLWriter, xml string) error

type BodyComponent

type BodyComponent struct {
	*BaseComponent
	Component Component
}

func NewBodyComponent

func NewBodyComponent(node *parser.MJMLNode, spec *ComponentSpec, props *ComponentProps, context *MJMLContext) *BodyComponent

func (*BodyComponent) CreateChildren

func (c *BodyComponent) CreateChildren(children []*parser.MJMLNode, options *CreateChildrenOptions) ([]Component, error)

func (*BodyComponent) GetBoxWidths

func (c *BodyComponent) GetBoxWidths() BoxWidths

func (*BodyComponent) GetShorthandAttrValue

func (c *BodyComponent) GetShorthandAttrValue(attribute string, direction string) int

func (*BodyComponent) GetShorthandBorderValue

func (c *BodyComponent) GetShorthandBorderValue(attribute string, direction string) int

type BoxWidths

type BoxWidths struct {
	TotalWidth int
	Borders    int
	Paddings   int
	Box        int
}

type Component

type Component interface {
	GetStyles(element string) []*Style
	GetAttribute(name string) *string
	GetAttributeOr(name string, orValue string) string
	GetChildContext() *MJMLContext
	IsRawElement() bool
	Render(w MJMLWriter) error
}

func InitComponent

func InitComponent(node *parser.MJMLNode, props *ComponentProps, context *MJMLContext) (Component, error)

type ComponentProps

type ComponentProps struct {
	Index          int
	First          bool
	Last           bool
	Sibling        int
	NonRawSiblings int
	Attributes     []*Attribute
}

type ComponentSpec

type ComponentSpec struct {
	TagName           string
	EndingTag         bool
	AllowedAttributes map[string]string
	DefaultAttributes []*Attribute
	Dependencies      map[string][]string
	IsRawElement      bool
	Create            func(node *parser.MJMLNode, spec *ComponentSpec, props *ComponentProps, context *MJMLContext) (Component, error)
}

type CreateChildrenOptions

type CreateChildrenOptions struct {
	Attributes []*Attribute
}

type GlobalData

type GlobalData struct {
	BackgroundColor      *string
	BeforeDoctype        string
	Breakpoint           string
	Classes              map[string]*Attributes
	DefaultAttributes    map[string]*Attributes
	HtmlAttributes       []*HtmlAttributes
	Fonts                []*helpers.FontDeclaration
	InlineStyles         []string
	HeadStyles           map[string]func(breakpoint string) string
	ComponentsHeadStyles []func(breakpoint string) string
	MediaQueries         *Attributes
	Preview              *string
	Styles               []string
	Title                *string
	ForceOWADesktop      bool
	Lang                 string
	Dir                  string
	Data                 map[string]any
}

type HeadComponent

type HeadComponent struct {
	*BaseComponent
	Component Component
}

func NewHeadComponent

func NewHeadComponent(node *parser.MJMLNode, spec *ComponentSpec, props *ComponentProps, context *MJMLContext) *HeadComponent

func (*HeadComponent) CreateChildren

func (c *HeadComponent) CreateChildren() ([]Component, error)

type HtmlAttribute

type HtmlAttribute struct {
	Name  string
	Value string
}

type HtmlAttributes

type HtmlAttributes struct {
	Path       string
	Attributes []HtmlAttribute
}

type MJMLBuilder

type MJMLBuilder struct {
	strings.Builder
}

func (*MJMLBuilder) WriteConditionalTag

func (b *MJMLBuilder) WriteConditionalTag(s string, negation bool) (int, error)

func (*MJMLBuilder) WriteMsoConditionalTag

func (b *MJMLBuilder) WriteMsoConditionalTag(s string, negation bool) (int, error)

type MJMLContext

type MJMLContext struct {
	Components     map[string]*ComponentSpec
	RawComponents  []string
	ContainerWidth int
	PrinterSupport bool
	GlobalData     *GlobalData
	Processing     func(w MJMLWriter, xml string, context *MJMLContext) error
}

func (*MJMLContext) AddComponentHeadSyle

func (c *MJMLContext) AddComponentHeadSyle(styleFunc func(breakpoint string) string)

func (*MJMLContext) AddFont

func (c *MJMLContext) AddFont(name string, href string)

func (*MJMLContext) AddHeadStyle

func (c *MJMLContext) AddHeadStyle(name string, styleFunc func(breakpoint string) string)

func (*MJMLContext) AddHtmlAttributes

func (c *MJMLContext) AddHtmlAttributes(path string, attributes []HtmlAttribute)

func (*MJMLContext) AddMediaQuery

func (c *MJMLContext) AddMediaQuery(className string, value float64, unit string)

func (*MJMLContext) AddPreview

func (c *MJMLContext) AddPreview(preview string)

func (*MJMLContext) AddStyle

func (c *MJMLContext) AddStyle(css string, inline bool)

func (*MJMLContext) GetAttributes

func (c *MJMLContext) GetAttributes(node *parser.MJMLNode) *Attributes

type MJMLOptions

type MJMLOptions struct {
	Components        map[string]*ComponentSpec
	Dependencies      map[string][]string
	SkipElements      []string
	DefaultAttributes map[string][]*Attribute
	InlineStyles      []string
	KeepComments      bool
	IgnoreIncludes    bool
	ValidationLevel   ValidationLevel
	Data              map[string]any
}

type MJMLWriter

type MJMLWriter interface {
	io.StringWriter
	WriteConditionalTag(s string, negation bool) (int, error)
	WriteMsoConditionalTag(s string, negation bool) (int, error)
}

type Style

type Style struct {
	Name  string
	Value string
}

type ValidationLevel

type ValidationLevel string
const (
	ValidationLevelStrict ValidationLevel = "strict"
	ValidationLevelSoft   ValidationLevel = "soft"
	ValidationLevelSkip   ValidationLevel = "skip"
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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