Documentation ¶
Index ¶
- func CssValueToString(palette Palette, value any) (string, error)
- func MergeMaps[M1 ~map[K]V, M2 ~map[K]V, K comparable, V any](dst M1, src M2)
- func RandomString(n int) string
- func RenderCss(styles StyleSheet, palette Palette) string
- func RenderCssOpts(styles StyleSheet, palette Palette, logger *log.Logger) string
- func RenderHtml(node Node) string
- func RenderHtmlOpts(node Node, deterministicAttrs bool, logger *log.Logger) string
- func RenderSitemap(sitemap Sitemap) string
- func RenderSitemapOpts(sitemap Sitemap, logger *log.Logger) string
- func WriteCssValue(builder *Builder, palette Palette, value any)
- func Xform[A any, B any](values []A, xform func(a A) B) []B
- type Attr
- type Attrs
- type Builder
- type CH
- type CM
- type ChangeFreq
- type Children
- type ClassName
- type Classes
- type Color
- type CssProp
- type CssProps
- type DomNode
- func A(args ...any) DomNode
- func AHref(href string, args ...any) DomNode
- func Abbr(args ...any) DomNode
- func Address(args ...any) DomNode
- func Area(args ...any) DomNode
- func Article(args ...any) DomNode
- func Aside(args ...any) DomNode
- func Audio(args ...any) DomNode
- func B(args ...any) DomNode
- func Base(args ...any) DomNode
- func BaseHref(href string) DomNode
- func Bdi(args ...any) DomNode
- func Bdo(args ...any) DomNode
- func Blockquote(args ...any) DomNode
- func Body(args ...any) DomNode
- func Br(args ...any) DomNode
- func Button(args ...any) DomNode
- func Canvas(args ...any) DomNode
- func Caption(args ...any) DomNode
- func Charset(value string) DomNode
- func Cite(args ...any) DomNode
- func Code(args ...any) DomNode
- func Col(args ...any) DomNode
- func Colgroup(args ...any) DomNode
- func Data(args ...any) DomNode
- func Datalist(args ...any) DomNode
- func Dd(args ...any) DomNode
- func Del(args ...any) DomNode
- func Details(args ...any) DomNode
- func Dfn(args ...any) DomNode
- func Dialog(args ...any) DomNode
- func Div(args ...any) DomNode
- func Dl(args ...any) DomNode
- func Dt(args ...any) DomNode
- func Em(args ...any) DomNode
- func Embed(args ...any) DomNode
- func Fieldset(args ...any) DomNode
- func Figcaption(args ...any) DomNode
- func Figure(args ...any) DomNode
- func Footer(args ...any) DomNode
- func Form(args ...any) DomNode
- func H(level int, args ...any) DomNode
- func H1(args ...any) DomNode
- func H2(args ...any) DomNode
- func H3(args ...any) DomNode
- func H4(args ...any) DomNode
- func H5(args ...any) DomNode
- func H6(args ...any) DomNode
- func Head(args ...any) DomNode
- func Header(args ...any) DomNode
- func Hr(args ...any) DomNode
- func I(args ...any) DomNode
- func Iframe(args ...any) DomNode
- func Img(args ...any) DomNode
- func Input(args ...any) DomNode
- func Ins(args ...any) DomNode
- func Kbd(args ...any) DomNode
- func Label(args ...any) DomNode
- func Legend(args ...any) DomNode
- func Li(args ...any) DomNode
- func Link(args ...any) DomNode
- func LinkHref(rel string, href string) DomNode
- func LinkStylesheet(href string) DomNode
- func LinkStylesheetMedia(href string, media string) DomNode
- func Main(args ...any) DomNode
- func Map(args ...any) DomNode
- func Mark(args ...any) DomNode
- func Meter(args ...any) DomNode
- func Nav(args ...any) DomNode
- func NewDomNode(tag Tag, args []any) DomNode
- func Noscript(args ...any) DomNode
- func Object(args ...any) DomNode
- func Ol(args ...any) DomNode
- func Optgroup(args ...any) DomNode
- func Option(args ...any) DomNode
- func Output(args ...any) DomNode
- func P(args ...any) DomNode
- func Param(args ...any) DomNode
- func Picture(args ...any) DomNode
- func Pre(args ...any) DomNode
- func Progress(args ...any) DomNode
- func Q(args ...any) DomNode
- func Rp(args ...any) DomNode
- func Rt(args ...any) DomNode
- func Ruby(args ...any) DomNode
- func S(args ...any) DomNode
- func Samp(args ...any) DomNode
- func Script(args ...any) DomNode
- func ScriptSrc(src string) DomNode
- func Section(args ...any) DomNode
- func Select(args ...any) DomNode
- func Small(args ...any) DomNode
- func Source(args ...any) DomNode
- func Span(args ...any) DomNode
- func Strong(args ...any) DomNode
- func Style(args ...any) DomNode
- func Sub(args ...any) DomNode
- func Summary(args ...any) DomNode
- func Sup(args ...any) DomNode
- func Svg(args ...any) DomNode
- func Table(args ...any) DomNode
- func Tbody(args ...any) DomNode
- func Td(args ...any) DomNode
- func Template(args ...any) DomNode
- func Textarea(args ...any) DomNode
- func Tfoot(args ...any) DomNode
- func Th(args ...any) DomNode
- func Thead(args ...any) DomNode
- func Time(args ...any) DomNode
- func Title(args ...any) DomNode
- func Tr(args ...any) DomNode
- func Track(args ...any) DomNode
- func U(args ...any) DomNode
- func Ul(args ...any) DomNode
- func Var(args ...any) DomNode
- func Video(args ...any) DomNode
- func Wbr(args ...any) DomNode
- type EM
- type EX
- type EquivNode
- type FragmentNode
- type HSL
- type HSLA
- type HtmlNode
- type IN
- type MM
- type MetaNode
- type Node
- type PC
- type PT
- type PX
- type Palette
- type PalettePrintfData
- type PaletteValue
- type Palettes
- type Perc
- type REM
- type RGB
- type RGBA
- type Sitemap
- type SitemapLocation
- type Smetana
- type StyleSheet
- func (styles *StyleSheet) AddAnonClass(props CssProps) ClassName
- func (styles *StyleSheet) AddBlock(selector string, props CssProps)
- func (styles *StyleSheet) AddClass(name ClassName, props CssProps) ClassName
- func (styles *StyleSheet) AddCss(css StyleSheetCss)
- func (styles *StyleSheet) AddFont(family string, srcs ...string) string
- func (styles *StyleSheet) AddPaletteCss(css StyleSheetPaletteCss)
- func (styles StyleSheet) ToCss(builder *Builder, palette Palette)
- type StyleSheetBlock
- type StyleSheetCss
- type StyleSheetElement
- type StyleSheetFontFace
- type StyleSheetPaletteCss
- type Tag
- type TextNode
- type VH
- type VMax
- type VMin
- type VW
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CssValueToString ¶ added in v0.2.1
Convert the given CSS value into a string using the given Palette if applicable.
The value argument may be any of the following types: PaletteValue, string, fmt.Stringer (which includes all of the Smetana unit types), or an int (which will be interpreted as a quantity in pixels).
func MergeMaps ¶ added in v0.2.0
func MergeMaps[M1 ~map[K]V, M2 ~map[K]V, K comparable, V any](dst M1, src M2)
Merge the `src` map into the `dst` map in place, replacing any duplicate keys. `src` is unchanged.
func RandomString ¶
Generate a string of random letters with length `n`. This is used for programatically generating class names. Based on the algorithm at https://stackoverflow.com/a/31832326
func RenderCss ¶
func RenderCss(styles StyleSheet, palette Palette) string
Render a StyleSheet into a CSS string with the default settings. See RenderCssOpts for more fine-grained control.
func RenderCssOpts ¶
func RenderCssOpts( styles StyleSheet, palette Palette, logger *log.Logger, ) string
Render a StyleSheet into a CSS string specifying particular settings for the internal Builder. See the Builder struct for the available configuration values. See RenderCss for a simpler interface with default values.
func RenderHtml ¶
Render a Node to an HTML string with the default settings. See RenderHtmlOpts for more fine-grained control.
func RenderHtmlOpts ¶
Render a Node to an HTML string specifying particular settings for the internal Builder. See the Builder struct for the available configuration values. See RenderHtml for a simpler interface with default values.
func RenderSitemap ¶ added in v0.2.0
Render a Sitemap into an XML string with the default settings. See RenderSitemapOpts for more fine-grained control.
func RenderSitemapOpts ¶ added in v0.2.0
Render a Sitemap into an XML string specifying particular settings for the internal Builder. See the Builder struct for the available configuration values. See RenderSitemap for a simpler interface with default values.
func WriteCssValue ¶ added in v0.2.0
Write the given value as a string to the Builder, using the given Palette is applicable. This is a low-level function that should rarely be needed to be called directly by library consumers, but it's included in the public API for flexibility.
The value argument may be any type supported by CssValueToString.
Types ¶
type Builder ¶
Struct for tracking internal state during HTML and CSS compilation.
- `Buf` is the string buffer being written to.
- By default, the order of HTML tag attributes is undefined and non-deterministic. It can be changed to be deterministic by setting `deterministicAttributes` to true. Note that this has a significant performance cost.
- `logger` is used for reporting warnings and errors during compilation.
type ChangeFreq ¶ added in v0.2.0
type ChangeFreq int
A valid Sitemap "change frequency"
const ( // A [Sitemap] entry with no specified change frequency ChangeFreqNone ChangeFreq = iota // A [Sitemap] entry with change frequency "always" ChangeFreqAlways // A [Sitemap] entry with change frequency "hourly" ChangeFreqHourly // A [Sitemap] entry with change frequency "daily" ChangeFreqDaily // A [Sitemap] entry with change frequency "weekly" ChangeFreqWeekly // A [Sitemap] entry with change frequency "monthly" ChangeFreqMonthly // A [Sitemap] entry with change frequency "yearly" ChangeFreqYearly // A [Sitemap] entry with change frequency "never" ChangeFreqNever )
func (ChangeFreq) String ¶ added in v0.2.0
func (freq ChangeFreq) String() string
Convert a Sitemap change frequency to a string
type Classes ¶
A map of conditional classes to be passed to ClassNames. The keys are class names and the values are booleans indicating whether or not to include that class name. For instance,
{"foo": true, "bar" false}
will evaluate to "foo".
type CssProp ¶ added in v0.2.0
A single CSS property. For instance,
CssProp{Key: "cursor", Value: "pointer"}
The value may be any type supported by CssValueToString.
For properties that take size values it is recommended to use a unit helper rather than setting the value with a string. For example, instead of
CssProp{"padding", "4px"}
you can use
CssProp{"padding", PX(4)}
type CssProps ¶
type CssProps []CssProp
An array of CSS values of type CssProp.
Note that strict ordering is preserved, which is important in cases such as:
CssProps{ {"margin", "none"}, {"margin-top", PX(5)}, }
type DomNode ¶
type DomNode struct { Tag Tag Attrs Attrs Children Children // contains filtered or unexported fields }
DomNode is a basic Node that renders into a particular HTML tag with optional attributes and/or children.
func A ¶
Create an `a` DOM node. Arguments follow the semantics of NewDomNode.
func AHref ¶
Create an `a` DOM node with the given href value. Arguments follow the semantics of NewDomNode.
func Abbr ¶
Create an `abbr` DOM node. Arguments follow the semantics of NewDomNode.
func Address ¶
Create an `address` DOM node. Arguments follow the semantics of NewDomNode.
func Area ¶
Create an `area` DOM node. Arguments follow the semantics of NewDomNode.
func Article ¶
Create an `article` DOM node. Arguments follow the semantics of NewDomNode.
func Aside ¶
Create an `aside` DOM node. Arguments follow the semantics of NewDomNode.
func Audio ¶
Create an `audio` DOM node. Arguments follow the semantics of NewDomNode.
func B ¶
Create a `b` DOM node. Arguments follow the semantics of NewDomNode.
func Base ¶
Create a `base` DOM node. Arguments follow the semantics of NewDomNode.
func Bdi ¶
Create a `bdi` DOM node. Arguments follow the semantics of NewDomNode.
func Bdo ¶
Create a `bdo` DOM node. Arguments follow the semantics of NewDomNode.
func Blockquote ¶
Create a `blockquote` DOM node. Arguments follow the semantics of NewDomNode.
func Body ¶
Create a `body` DOM node. Arguments follow the semantics of NewDomNode.
func Br ¶
Create a `br` DOM node. Arguments follow the semantics of NewDomNode.
func Button ¶
Create a `button` DOM node. Arguments follow the semantics of NewDomNode.
func Canvas ¶
Create a `canvas` DOM node. Arguments follow the semantics of NewDomNode.
func Caption ¶
Create a `caption` DOM node. Arguments follow the semantics of NewDomNode.
func Charset ¶
Create a `charset` DOM node. If value is the empty string then the default value of "UTF-8" is used.
func Cite ¶
Create a `cite` DOM node. Arguments follow the semantics of NewDomNode.
func Code ¶
Create a `code` DOM node. Arguments follow the semantics of NewDomNode.
func Col ¶
Create a `col` DOM node. Arguments follow the semantics of NewDomNode.
func Colgroup ¶
Create a `colgroup` DOM node. Arguments follow the semantics of NewDomNode.
func Data ¶
Create a `data` DOM node. Arguments follow the semantics of NewDomNode.
func Datalist ¶
Create a `datalist` DOM node. Arguments follow the semantics of NewDomNode.
func Dd ¶
Create a `dd` DOM node. Arguments follow the semantics of NewDomNode.
func Del ¶
Create a `del` DOM node. Arguments follow the semantics of NewDomNode.
func Details ¶
Create a `details` DOM node. Arguments follow the semantics of NewDomNode.
func Dfn ¶
Create a `dfn` DOM node. Arguments follow the semantics of NewDomNode.
func Dialog ¶
Create a `dialog` DOM node. Arguments follow the semantics of NewDomNode.
func Div ¶
Create a `div` DOM node. Arguments follow the semantics of NewDomNode.
func Dl ¶
Create a `dl` DOM node. Arguments follow the semantics of NewDomNode.
func Dt ¶
Create a `dt` DOM node. Arguments follow the semantics of NewDomNode.
func Em ¶
Create a `em` DOM node. Arguments follow the semantics of NewDomNode.
func Embed ¶
Create a `embed` DOM node. Arguments follow the semantics of NewDomNode.
func Fieldset ¶
Create a `fieldset` DOM node. Arguments follow the semantics of NewDomNode.
func Figcaption ¶
Create a `figcaption` DOM node. Arguments follow the semantics of NewDomNode.
func Figure ¶
Create a `figure` DOM node. Arguments follow the semantics of NewDomNode.
func Footer ¶
Create a `footer` DOM node. Arguments follow the semantics of NewDomNode.
func Form ¶
Create a `form` DOM node. Arguments follow the semantics of NewDomNode.
func H ¶
Create a heading DOM node (ie; `h1`-`h6`). The given `level` should be an an integer between 1-6 inclusive. Arguments follow the semantics of NewDomNode.
func H1 ¶
Create a `h1` DOM node. Arguments follow the semantics of NewDomNode.
func H2 ¶
Create a `h2` DOM node. Arguments follow the semantics of NewDomNode.
func H3 ¶
Create a `h3` DOM node. Arguments follow the semantics of NewDomNode.
func H4 ¶
Create a `h4` DOM node. Arguments follow the semantics of NewDomNode.
func H5 ¶
Create a `h5` DOM node. Arguments follow the semantics of NewDomNode.
func H6 ¶
Create a `h6` DOM node. Arguments follow the semantics of NewDomNode.
func Head ¶
Create a `head` DOM node. Arguments follow the semantics of NewDomNode.
func Header ¶
Create a `header` DOM node. Arguments follow the semantics of NewDomNode.
func Hr ¶
Create a `hr` DOM node. Arguments follow the semantics of NewDomNode.
func I ¶
Create an `i` DOM node. Arguments follow the semantics of NewDomNode.
func Iframe ¶
Create an `iframe` DOM node. Arguments follow the semantics of NewDomNode.
func Img ¶
Create an `img` DOM node. Arguments follow the semantics of NewDomNode.
func Input ¶
Create an `input` DOM node. Arguments follow the semantics of NewDomNode.
func Ins ¶
Create an `ins` DOM node. Arguments follow the semantics of NewDomNode.
func Kbd ¶
Create a `kbd` DOM node. Arguments follow the semantics of NewDomNode.
func Label ¶
Create a `level` DOM node. Arguments follow the semantics of NewDomNode.
func Legend ¶
Create a `legend` DOM node. Arguments follow the semantics of NewDomNode.
func Li ¶
Create a `li` DOM node. Arguments follow the semantics of NewDomNode.
func Link ¶
Create a `link` DOM node. Arguments follow the semantics of NewDomNode.
func LinkStylesheet ¶ added in v0.2.0
Create a `link` DOM node for a CSS stylesheet with the given `href` attribute.
func LinkStylesheetMedia ¶ added in v0.2.0
Create a `link` DOM node for a CSS stylesheet with the given `href` and `media` attributes.
func Main ¶
Create a `main` DOM node. Arguments follow the semantics of NewDomNode.
func Map ¶
Create a `map` DOM node. Arguments follow the semantics of NewDomNode.
func Mark ¶
Create a `mark` DOM node. Arguments follow the semantics of NewDomNode.
func Meter ¶
Create a `meter` DOM node. Arguments follow the semantics of NewDomNode.
func Nav ¶
Create a `nav` DOM node. Arguments follow the semantics of NewDomNode.
func NewDomNode ¶
This is the base constructor for building a new DomNode. "tag" is the name of the HTML tag to use. "args" is a variadic array of arguments, each of which can be of several different types:
- Attrs defines node attributes (multiple instances are merged together)
- Children appends children to the end of the node
- Attr sets a single attribute value
- Node appends a single child
- ClassName adds a single class
- ClassNames adds multiple classes at once
- `string` appends a Text child with the given content
Passing multiple instances of each of the above is supported. Any other type is ignored and logs an error message when compiled.
func Noscript ¶
Create a `noscript` DOM node. Arguments follow the semantics of NewDomNode.
func Object ¶
Create an `object` DOM node. Arguments follow the semantics of NewDomNode.
func Ol ¶
Create an `ol` DOM node. Arguments follow the semantics of NewDomNode.
func Optgroup ¶
Create an `optgroup` DOM node. Arguments follow the semantics of NewDomNode.
func Option ¶
Create an `option` DOM node. Arguments follow the semantics of NewDomNode.
func Output ¶
Create an `output` DOM node. Arguments follow the semantics of NewDomNode.
func P ¶
Create a `p` DOM node. Arguments follow the semantics of NewDomNode.
func Param ¶
Create a `param` DOM node. Arguments follow the semantics of NewDomNode.
func Picture ¶
Create a `picture` DOM node. Arguments follow the semantics of NewDomNode.
func Pre ¶
Create a `pre` DOM node. Arguments follow the semantics of NewDomNode.
func Progress ¶
Create a `progress` DOM node. Arguments follow the semantics of NewDomNode.
func Q ¶
Create a `q` DOM node. Arguments follow the semantics of NewDomNode.
func Rp ¶
Create an `rp` DOM node. Arguments follow the semantics of NewDomNode.
func Rt ¶
Create an `rt` DOM node. Arguments follow the semantics of NewDomNode.
func Ruby ¶
Create a `ruby` DOM node. Arguments follow the semantics of NewDomNode.
func S ¶
Create an `s` DOM node. Arguments follow the semantics of NewDomNode.
func Samp ¶
Create a `samp` DOM node. Arguments follow the semantics of NewDomNode.
func Script ¶
Create a `script` DOM node. Arguments follow the semantics of NewDomNode.
func Section ¶
Create a `section` DOM node. Arguments follow the semantics of NewDomNode.
func Select ¶
Create a `select` DOM node. Arguments follow the semantics of NewDomNode.
func Small ¶
Create a `small` DOM node. Arguments follow the semantics of NewDomNode.
func Source ¶
Create a `source` DOM node. Arguments follow the semantics of NewDomNode.
func Span ¶
Create a `span` DOM node. Arguments follow the semantics of NewDomNode.
func Strong ¶
Create a `strong` DOM node. Arguments follow the semantics of NewDomNode.
func Style ¶
Create a `style` DOM node. Arguments follow the semantics of NewDomNode.
func Sub ¶
Create a `sub` DOM node. Arguments follow the semantics of NewDomNode.
func Summary ¶
Create a `summary` DOM node. Arguments follow the semantics of NewDomNode.
func Sup ¶
Create a `sup` DOM node. Arguments follow the semantics of NewDomNode.
func Svg ¶
Create a `svg` DOM node. Arguments follow the semantics of NewDomNode.
func Table ¶
Create a `table` DOM node. Arguments follow the semantics of NewDomNode.
func Tbody ¶
Create a `tbody` DOM node. Arguments follow the semantics of NewDomNode.
func Td ¶
Create a `td` DOM node. Arguments follow the semantics of NewDomNode.
func Template ¶
Create a `template` DOM node. Arguments follow the semantics of NewDomNode.
func Textarea ¶
Create a `textarea` DOM node. Arguments follow the semantics of NewDomNode.
func Tfoot ¶
Create a `tfoot` DOM node. Arguments follow the semantics of NewDomNode.
func Th ¶
Create a `th` DOM node. Arguments follow the semantics of NewDomNode.
func Thead ¶
Create a `thead` DOM node. Arguments follow the semantics of NewDomNode.
func Time ¶
Create a `time` DOM node. Arguments follow the semantics of NewDomNode.
func Title ¶
Create a `title` DOM node. Arguments follow the semantics of NewDomNode.
func Tr ¶
Create a `tr` DOM node. Arguments follow the semantics of NewDomNode.
func Track ¶
Create a `track` DOM node. Arguments follow the semantics of NewDomNode.
func U ¶
Create a `u` DOM node. Arguments follow the semantics of NewDomNode.
func Ul ¶
Create a `ul` DOM node. Arguments follow the semantics of NewDomNode.
func Var ¶
Create a `var` DOM node. Arguments follow the semantics of NewDomNode.
func Video ¶
Create a `video` DOM node. Arguments follow the semantics of NewDomNode.
func Wbr ¶
Create a `wbr` DOM node. Arguments follow the semantics of NewDomNode.
func (*DomNode) AssignAttrs ¶
Assign new attributes to a DomNode. These values are merged together with any existing attributes. If a value exists in both the old attributes map and the new attributes map then the new value is used.
func (*DomNode) AssignChildren ¶
Append more children to the end of a DomNode.
type EquivNode ¶
A "meta" Node in an HTML document to associate some "content" value to a particular "http-equiv" (see MetaNode for a more generic node using "name" instead of "http-equiv").
func Refresh ¶
Create an EquivNode with "http-equiv" set to "refresh" and "content" set to the provided value in seconds.
func XUaCompatible ¶
Create an EquivNode with "http-equiv" set to "x-ua-compatible" and "content" set to the given value
type FragmentNode ¶
type FragmentNode struct {
Children Children
}
Sometimes we want to combine multiple nodes at the same level of a document to treat them as a single unit. In some cases it may be acceptable to wrap them in another node such as a "div" or "span" but this is often undesirable as it alters the generated markup. In these cases, the children nodes can instead be wrapped in a FragmentNode to treat them as a single entity but without adding an extra layer to the generated markup.
func Fragment ¶
func Fragment(children ...Node) FragmentNode
Create a FragmentNode with the given children.
func (*FragmentNode) AssignChildren ¶
func (node *FragmentNode) AssignChildren(children Children)
Append more children to the end of a FragmentNode.
func (FragmentNode) ToHtml ¶
func (node FragmentNode) ToHtml(builder *Builder)
Convert a FragmentNode to HTML.
type HSL ¶
Structure representing an HSL Color. "H" is an unsigned value between 0-360 inclusive representing a position on the color wheel. 0 is red, 120 is green, 240 is blue, and other colors are interpolated between. S is saturation and must be a float between 0.0-1.0 inclusive. L is the lightness and must also be a float between 0.0-1.0 inclusive. Also see Hsl.
type HSLA ¶
Structure representing an HSL Color plus as alpha channel. See HSL for more info. The alpha is stored as a float between 0.0-1.0 inclusive. Also see Hsla.
func Darken ¶
Darken a Color by the given amount, which should be a float32 between 0.0 and 1.0, inclusive. Passing a value between 0.0 and -1.0 is equivalent to calling Lighten with a positive value.
func Lighten ¶
Lighten a Color by the given amount, which should be a float32 between 0.0 and 1.0, inclusive. Passing a value between 0.0 and -1.0 is equivalent to calling Darken with a positive value.
type HtmlNode ¶
type HtmlNode struct {
// contains filtered or unexported fields
}
HtmlNode is the top level DomNode of an HTML document. For almost all intents and purposes it functions identically to a DomNode, but it needs some special handling internally to render the initial `DOCTYPE` specifier.
func Html ¶
Create an `html` DOM node. Arguments follow the semantics of NewDomNode.
type MetaNode ¶
A "meta" Node in an HTML document to associate some "content" value to a particular "name".
func Description ¶
Create a "description" MetaNode with the given value
type Node ¶
type Node interface {
ToHtml(b *Builder)
}
All structural elements of an HTML document are implementers of the Node interface for converting to HTML. This is primarily different types of HTML tags and text.
type Palette ¶ added in v0.2.0
A palette for rendering a [Stylesheet] multiple times with different values. This can be used, for instance, to create separate styles for light-mode and dark-mode.
type PalettePrintfData ¶ added in v0.2.1
A helper that allows you to format text including values from a Palette. This can be used fo cases such as:
CssProps{"border", PalettePrintf( "1px solid %s", PaletteValue("border-color"), )}
func PalettePrintf ¶ added in v0.2.1
func PalettePrintf( format string, args ...any, ) PalettePrintfData
Create a PalettePrintfData.
func (PalettePrintfData) Render ¶ added in v0.2.1
func (data PalettePrintfData) Render(palette Palette) string
Convert a PalettePrintfData into a CSS string.
type PaletteValue ¶ added in v0.2.0
type PaletteValue string
Use PaletteValue when creating a [Stylesheet] to mark a value as needing to be fetched from a Palette.
styles := NewStyleSheet() styles.AddClass("container", CssProps{ "background": PaletteValue("background-color"), }) palette := Palette{"background-color", Hex("#f0f")} css := RenderCss(styles, palette)
func (PaletteValue) String ¶ added in v0.2.1
func (value PaletteValue) String() string
Convert a PaletteValue into a string.
type Perc ¶
type Perc float32
Utility type for marking CSS values as a percentage (adds a "%" suffix).
type RGB ¶
Structure representing an RGB Color. All values are unsigned from 0-255 inclusive. Also see Rgb.
type RGBA ¶
Structure representing an RGB Color plus an alpha channel. All values are unsigned from 0-255 inclusive. Also see Rgba.
type Sitemap ¶ added in v0.2.0
type Sitemap []SitemapLocation
Sitemap represents an XML sitemap according to the schema at https://www.sitemaps.org/protocol.html Convert to an XML string with the [ToXml] method.
type SitemapLocation ¶ added in v0.2.0
type SitemapLocation struct {
// contains filtered or unexported fields
}
Represents a single entry in a Sitemap with a URL string and an optional last modified date. The date can be any type implementing fmt.Stringer, but is most commonly a string or a time.Time.
func NewSitemapLocation ¶ added in v0.2.0
func NewSitemapLocation( url string, lastmod time.Time, changefreq ChangeFreq, priority float64, ) SitemapLocation
Create a SitemapLocation with all available parameters: url, lastmod, changefreq and priority.
func SitemapLocationMod ¶ added in v0.2.0
func SitemapLocationMod(url string, lastmod time.Time) SitemapLocation
Create a SitemapLocation with just a URL and last modified date.
func SitemapLocationUrl ¶ added in v0.2.0
func SitemapLocationUrl(url string) SitemapLocation
Create a SitemapLocation with just a URL.
type Smetana ¶ added in v0.2.0
type Smetana struct { Palettes Palettes Styles StyleSheet }
The Smetana struct is an overarching compilation context for tying together different parts of the application.
func NewSmetana ¶ added in v0.2.0
func NewSmetana() Smetana
Create a new Smetana instance with default values.
func NewSmetanaWithPalettes ¶ added in v0.2.0
func (*Smetana) AddPalette ¶ added in v0.2.0
func (Smetana) RenderStyles ¶ added in v0.2.0
Render the styles from the Smetana context into CSS strings. One CSS stylesheet will be created for each palette added with [AddPalette]. The return value is a map from palette names to rendered CSS strings. See [RenderStylesOpts] for more fine-grained control.
func (Smetana) RenderStylesOpts ¶ added in v0.2.0
Render the styles from the Smetana context into CSS strings. One CSS stylesheet will be created for each palette added with [AddPalette]. The return value is a map from palette names to rendered CSS strings. See [RenderStyles] for a simple interface with default values.
type StyleSheet ¶
type StyleSheet struct {
Elements []StyleSheetElement
}
StyleSheet aggregates the CSS styles for a page and compiles them from the in-code representation into a CSS string for the browser. Note that StyleSheet is itself a StyleSheetElement, so they can be nested.
func NewStyleSheet ¶
func NewStyleSheet(elements ...StyleSheetElement) StyleSheet
Create a new empty StyleSheet.
func (*StyleSheet) AddAnonClass ¶
func (styles *StyleSheet) AddAnonClass(props CssProps) ClassName
Add a new class to a StyleSheet with a random name.
func (*StyleSheet) AddBlock ¶
func (styles *StyleSheet) AddBlock(selector string, props CssProps)
Add a new block to a StyleSheet.
func (*StyleSheet) AddClass ¶
func (styles *StyleSheet) AddClass(name ClassName, props CssProps) ClassName
Add a new class to a StyleSheet.
func (*StyleSheet) AddCss ¶
func (styles *StyleSheet) AddCss(css StyleSheetCss)
Add a raw CSS string to the StyleSheet.
func (*StyleSheet) AddFont ¶
func (styles *StyleSheet) AddFont(family string, srcs ...string) string
Add a new @font-face to the StyleSheet. `family` is the name to give to the CSS "font-family". `srcs` is an array of strings containing the URLs of the font files. The type of each src is automatically determined based on the file extension which should be one of "ttf", "woff", "woff2" or "otf".
func (*StyleSheet) AddPaletteCss ¶ added in v0.2.1
func (styles *StyleSheet) AddPaletteCss(css StyleSheetPaletteCss)
Add StyleSheetPaletteCss generator function to the StyleSheet.
func (StyleSheet) ToCss ¶ added in v0.2.1
func (styles StyleSheet) ToCss(builder *Builder, palette Palette)
Compile a StyleSheet into a CSS String.
type StyleSheetBlock ¶
CSS block type implementing StyleSheetElement.
func StylesBlock ¶
func StylesBlock(selector string, props CssProps) StyleSheetBlock
Create a StyleSheetBlock StyleSheetElement.
func (StyleSheetBlock) ToCss ¶
func (block StyleSheetBlock) ToCss(builder *Builder, palette Palette)
Convert a [StyleSheetClass] into a CSS string.
type StyleSheetCss ¶
type StyleSheetCss string
Raw CSS type implementing StyleSheetElement.
func (StyleSheetCss) ToCss ¶
func (css StyleSheetCss) ToCss(builder *Builder, palette Palette)
Convert [StyleSheetCSS] into a CSS string.
type StyleSheetElement ¶
Interface representing an abstract element to be inserted into a CSS StyleSheet.
type StyleSheetFontFace ¶
@font-face type implementing StyleSheetElement.
func StylesFontFace ¶
func StylesFontFace(family string, srcs ...string) StyleSheetFontFace
Create a StyleSheetFontFace StyleSheetElement.
func (StyleSheetFontFace) ToCss ¶
func (font StyleSheetFontFace) ToCss(builder *Builder, palette Palette)
Convert a StyleSheetFontFace into a CSS string.
type StyleSheetPaletteCss ¶ added in v0.2.1
Instead of using a raw CSS string with StyleSheetCss you can instead use StyleSheetPaletteCss to provide a function that takes a palette which is used to build a CSS string.
func (StyleSheetPaletteCss) ToCss ¶ added in v0.2.1
func (css StyleSheetPaletteCss) ToCss(builder *Builder, palette Palette)
Convert [StyleSheetPaletteCSS] into a CSS string.
type TextNode ¶
type TextNode struct {
Text string
}
A Node representing raw text without any surrounding tag.