restache

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: May 4, 2025 License: MIT Imports: 12 Imported by: 0

README

restache

Mustache-like extension to HTML syntax, designed for use with React and transpiled into JSX.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrErrorNode       = errors.New("cannot render an ErrorNode node")
	ErrUnknownNode     = errors.New("unknown node type")
	ErrVoidChildren    = errors.New("void element has child nodes")
	ErrTooManyChildren = errors.New("element must have a single child")
)

Functions

func Plugin

func Plugin() api.Plugin

func Render

func Render(w io.Writer, n *Node) (int, error)

Types

type Attribute

type Attribute struct {
	Key     string
	KeyAtom atom.Atom
	Val     string
	IsExpr  bool
}

type Node

type Node struct {
	Parent, FirstChild, LastChild, PrevSibling, NextSibling *Node

	Type     NodeType
	DataAtom atom.Atom
	Data     string
	Attr     []Attribute
	Path     []PathComponent
}

func Parse

func Parse(r io.Reader) (node *Node, err error)

func (*Node) AppendChild

func (n *Node) AppendChild(c *Node)

AppendChild adds a node c as a child of n.

It will panic if c already has a parent or siblings.

func (*Node) InsertBefore

func (n *Node) InsertBefore(newChild, oldChild *Node)

InsertBefore inserts newChild as a child of n, immediately before oldChild in the sequence of n's children. oldChild may be nil, in which case newChild is appended to the end of n's children.

It will panic if newChild already has a parent or siblings.

func (*Node) RemoveChild

func (n *Node) RemoveChild(c *Node)

RemoveChild removes a node c that is a child of n. Afterwards, c will have no parent and no siblings.

It will panic if c's parent is not n.

func (*Node) TagName

func (n *Node) TagName() string

type NodeType

type NodeType uint32
const (
	ErrorNode NodeType = iota
	TextNode
	ComponentNode
	ElementNode
	CommentNode
	VariableNode
	RangeNode
	WhenNode
	UnlessNode
)

type PathComponent

type PathComponent struct {
	Key     string
	IsRange bool
}

type TokenType

type TokenType uint32

TokenType represents the type of token.

const (
	ErrorToken TokenType = iota
	StartTagToken
	EndTagToken
	SelfClosingTagToken
	TextToken
	CommentToken
	VariableToken
	WhenToken
	UnlessToken
	RangeToken
	EndControlToken
)

type Tokenizer

type Tokenizer struct {
	// contains filtered or unexported fields
}

Tokenizer holds state for parsing.

func NewTokenizer

func NewTokenizer(r io.Reader) *Tokenizer

func (*Tokenizer) Comment

func (t *Tokenizer) Comment() []byte

Comment extracts the content of a comment.

func (*Tokenizer) ControlName

func (t *Tokenizer) ControlName() []byte

ControlName extracts the name of a section, inverted section, or end section.

func (*Tokenizer) Err

func (t *Tokenizer) Err() error

Err returns the last error encountered by the tokenizer.

func (*Tokenizer) Next

func (t *Tokenizer) Next() TokenType

Next advances the tokenizer to the next token and returns its type.

func (*Tokenizer) Raw

func (t *Tokenizer) Raw() []byte

Raw returns the raw byte slice of the current token.

func (*Tokenizer) TagAttr

func (t *Tokenizer) TagAttr() (key []byte, val []byte, isExpr bool, moreAttr bool)

TagAttr retrieves the next attribute key and value from an HTML start tag.

func (*Tokenizer) TagName

func (t *Tokenizer) TagName() ([]byte, bool)

TagName returns the name of the current HTML tag, if applicable.

Directories

Path Synopsis
internal/static
Package static builds static assets for the frontend.
Package static builds static assets for the frontend.

Jump to

Keyboard shortcuts

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