smetana

package module
v0.2.4 Latest Latest
Warning

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

Go to latest
Published: Mar 24, 2023 License: MIT Imports: 10 Imported by: 1

README

Smetana

Coverage Status

Smetana is an HTML and CSS generator for Go, designed for server-side webpage rendering.

Features

  • Simple component-like API
  • Built-in support for all HTML5 tags, and easily extensible for web components
  • Strongly-typed CSS units and colors
  • Robust with 100% test coverage
  • Zero dependencies outside the Go standard library

Installation

$ go get github.com/oetherington/smetana

Usage

Import the library with:

import (
	s "github.com/oetherington/smetana"
)

Aliasing to s (or even .) is optional but advised.

Typical usage

Here is an example of typical usage with separate styles for light and dark mode, making use of the Smetana context:

smetana := NewSmetanaWithPalettes(Palettes{
	"light": {
		"bg": Hex("#eee"),
		"fg": Hex("#222"),
	},
	"dark": {
		"bg": Hex("#363636"),
		"fg": Hex("#ddd"),
	},
})

font := smetana.Styles.AddFont("OpenSans", "/OpenSans.woff2")
container := smetana.Styles.AddAnonClass(CssProps{
	{"font-family", font},
	{"padding",     EM(2)},
	{"background",  PaletteValue("bg")},
	{"color",       PaletteValue("fg")},
})

css := smetana.RenderStyles()
lightCss = css["light"]
darkCss = css["dark"]

node := Html(
	Head(
		Title("My HTML Document"),
		LinkHref("stylesheet", "/styles/index.css"),
	),
	Body(
		container,
		H1("Hello world")
		P("foobar"),
	),
)

html := RenderHtml(node)
Building HTML

To build an HTML tag we simply need to call the function with the name of that tag. For instance, this:

html := Html(
	Head(
		Title("My HTML Document"),
		Charset("UTF-8"),
		LinkHref("stylesheet", "/styles/index.css"),
	),
	Body(
		Div(
			ClassName("container"),
			H1("Hello world"),
		),
	),
)

can be rendered with RenderHtml(html) to produce the following HTML string:

<!DOCTYPE html>
<html>
	<head>
		<title>My HTML Document</title>
		<meta charset="UTF-8">
		<link rel="stylesheet" href="/styles/index.css">
	</head>
	<body>
		<div class="container">
			<h1>Hello world</h1>
		</div>
	</body>
</html>

Note that the actual output will be automatically minified.

You may notice in the example above that we used Charset and LinkHref which aren't the names of HTML tags. We could have instead directly used created a <meta> DOM node (or the MetaNode helper), but a number of special helpers are also included to avoid boilerplate code for the most common use cases.

We also used ClassName to apply a CSS class.

By default, all of the DOM nodes take a variadic list of arguments which are passed onto the NewDomNode function. This function accepts a variety of different types of arguments to make generating your HTML as ergonomic as possible. See the NewDomNode documentation for the full list.

Special-case helpers

Several frequently used tags have extra helper functions for their most common use-cases:

  • func AHref(href string, args ...any) DomNode builds an <a> tag with the given URL.
  • func BaseHref(href string) DomNode builds a <base> tag with the given URL.
  • func Charset(value string) DomNode builds a charset <meta> node with the given value. If the empty string is passed in then it defaults to "UTF-8".
  • func H(level int, args ...any) DomNode builds a header tag from <h1> to <h6> with the given level.
  • func LinkHref(rel string, href string) builds a <link> tag with the given rel and URL attributes.
  • func LinkStylesheet(href string) builds a <link> tag with rel="stylesheet" and the given URL attribute.
  • func LinkStylesheetMedia(href string, media string) builds a <link> tag with rel="stylesheet" and the given URL and media attributes.
  • func ScriptSrc(src string) DomNode builds a <script> tag with the given src.
Meta tags

It is simple to create a <meta> tag using NewDomNode, but in most cases we only want to set the "name" and "content" attributes, so there's a helper function to do just that: func Meta(name string, content string) MetaNode.

There are several higher-level helpers that automatically set the "name" property and so only take a single "value" string:

  • Keywords
  • Description
  • Author
  • Viewport (pass the empty string for the default value of "width=device-width, initial-scale=1.0")

as well as the Charset function mentioned above.

Smetana also supports natively "http-equiv" meta tags:

  • func Equiv(equiv string, content string) EquivNode builds a <meta> tag with "http-equiv" set to equiv and "content" set to content.
  • func Refresh(value uint) DomNode builds a <meta> tag with "http-equiv" set to "refresh"` and "content" set to the given integer value.
  • func XUaCompatible(value string) EquivNode builds a <meta> tag with "http-equiv" set to "x-ua-compatible" and "content" set to value.
Fragment nodes

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.

node := Fragment(
	Div(
		H(1, "Foo"),
		P("Bar"),
	),
	Span("Hello world"),
);
Transforming arrays

It's common to need to apply some operation to an array of data to turn it into an array of DOM nodes. For this purpose, Smetana has a utility function called Xform that functions similarly to map in Haskell or Javascript.

titles := []string{"Foo", "Bar", "Baz"}
node := Div(
	Xform(titles, func (title string) Node {
		return H1(title)
	}),
)
Text nodes

Raw text inside of a tag is implemented by the TextNode struct. You should rarely need to use TextNode explicitly as Span("Hello world") is automatically converted into Span(Text("Hello world")), but it's mentioned here for completeness.

Creating custom nodes

To create your own Node types, you simply need to implement the interface:

type Node interface {
	ToHtml(b *Builder)
}

Builder contains a strings.Builder called Buf which you can write your HTML into. For instance:

type CustomNode struct {
	Value string
}

func (node CustomNode) ToHtml(b *Builder) {
	b.Buf.WriteString(node.Value)
}
CSS and StyleSheets

Smetana also supports generating CSS stylesheets along with your HTML.

Create a stylesheet with styles := NewStyleSheet(). This can later be compiled into a CSS string with RenderCss(styles, Palette{}).

You can then add classes to the stylesheet with

container := styles.AddClass("container", CssProps{
	{"cursor", "pointer"},
})

container is now a class name that can be passed directly into a DOM node:

Div(
	container,
	"Hello world",
)

which will render to

<div class="container">Hello world</div>

and

.container{cursor:pointer}

If you don't require class names to be stable between builds then you can generate a random class name with addAnonClass:

container := styles.addAnonClass(CssProps{
	{"cursor", "pointer"},
})

CssProps is an array of items each of type CssProp, which is a struct containing 2 fields: Key which is the name of the CSS property as a string, and Value which can be any CSS value (see the documentation and source for WriteCssValue for details). Note that the style shown in the documentation without field names (ie; {"cursor", "pointer"} instead of {Key: "cursor", Value: "pointer"}) will cause a lint error from go vet, but is often still preferable when writing large amounts of styles. This error can be silenced by instead using go vet -composites=false, but note that this is a compromise and, if possible, should be limited to as little code as possible rather than to your entire code base. Alternatively, you can use golangci-lint with // nolint comments (see examples/main.go).

To use arbitrary CSS selectors you can instead use AddBlock:

styles.AddBlock("body", CssProps{{"background", "red"}})
styles.AddBlock(".container > div", CssProps{{"display", "flex"}})

NewStyleSheet is also a variadic function which can take an arbitrary number of StyleSheetElements (the building blocks that make up a stylesheet). This can be useful for cleanly adding global styles without using AddBlock:

styles := NewStyleSheet(
	StylesCss(`
		body {
			padding: 3em;
		}
		p {
			font-family: sans-serif;
		}
	`),
	StylesBlock("div", CssProps{
		{"border-radius", PX(5)},
	}),
)
Using palettes

Stylesheets can be parameterized by using Palettes. This can be used, for example, to use a single StyleSheet to generate separate CSS files for a light mode and a dark mode. For instance:

styles := NewStyleSheet(StylesBlock("body", CssProps{
	{"background", PaletteValue("bg")},
	{"color",      PaletteValue("fg")},
}))
darkStyles := RenderCss(styles, Palette{
	"bg": Hex("#000"),
	"fg": Hex("#fff"),
})
lightStyles := RenderCss(styles, Palette{
	"bg": Hex("#fff"),
	"fg": Hex("#000"),
})

The values in a Palette are not limited to Colors, but can actually be any valid CSS value, such as Units, numbers, or strings.

Using colors

Instead of entering CSS color strings by hand, Smetana provides several helper types and function to make color handling easier and more programmatic. For instance, we can add an RGB background color property with:

CssProps{{"background", Rgb(255, 255, 0)}}

which will compile to background: #FFFF00 in CSS.

Aside from RGB, there are also helpers for RGBA, HSL and HSLA.

The Hex function will create an RGB color from a 4-digit or 7-digit CSS hex color string, such as #ab4 or #FF00FF.

For easier manipulation, all colors have ToHsla() and ToRgba() methods.

Colors can also be lightened or darkened by a certain amount with the Lighten and Darken functions:

red := Rgb(255, 0, 0)
darkerRed := Darken(red, 0.4)
lighterRed := Lighten(red, 0.4)
Adding units

Helpers are also provided to strongly type CSS units. For example,

CssProps{{"margin", PX(10)}}

will compile to margin: 10px;

The following unit functions are provided: PX, EM, REM, CM, MM, IN, PT, PC, EX, CH, VW, VH, VMin, VMax and Perc (for percentages).

Applying classes to HTML

Class names can be passed directly to any DOM node by being typed as a ClassName or Classes type. When passing multiple of these to the same node they will be combined together with the ClassNames function:

ClassNames("foo", "bar")

compiles to "foo bar".

ClassNames takes a variadic list of arguments that may be strings (as above) to combine together, or instances of the Classes type to conditionally apply classnames:

ClassNames("foo", "bar", Classes{"baz": false, "bop": true, "boz": 2 > 1})

compiles to "foo bar bop boz";

Custom fonts

Smetana can also generate @font-face directives to load custom fonts like so:

styles := NewStyleSheet()
font := styles.AddFont("OpenSans", "OpenSans.ttf", "OpenSans.woff2")
class := styles.AddClass(CssProps{
	{"font-family", font},
})

The AddFont function takes the name of the font family as the first argument (which is also returned for convenience), followed by a variadic list of URLs to the font sources. The type of each source is detected from its extension which should be one of "ttf", "woff", "woff2" or "otf".

Inserting raw CSS

For more complex or obscure features it may be desirabe to add some manually written CSS. This can be done with the AddCss function:

styles := NewStyleSheet()
styles.AddCss("@media only screen and (max-width:600px) {body{width:100%;}}")
Sitemaps

Smetana can also generate XML sitemaps.

Simply construct an array of SitemapLocation structs using the provided constructors then call RenderSitemap to get an XML string:

sitemap := Sitemap{
	SitemapLocationUrl("https://duckduckgo.com"),
	SitemapLocationMod("https://lobste.rs", time.Now()),
	NewSitemapLocation(
		"https://news.ycombinator.com",
		time.Now(),
		ChangeFreqAlways,
		0.9,
	),
}
resultXml := RenderSitemap(sitemap)

The constructors are as follows:

  • SitemapLocationUrl takes only a URL.
  • SitemapLocationMod takes a URL and a last modified date.
  • NewSitemapLocation takes a URL, a last modified date, a change frequency and a priority.

The URL is a string, the modified date is a time.Time, the change frequency is one of ChangeFreqNone, ChangeFreqAlways, ChangeFreqHourly, ChangeFreqDaily, ChangeFreqWeekly, ChangeFreqMonthly, ChangeFreqYearly or ChangeFreqNever, and the priority is a float64 between 0 and 1 inclusive.

License

Smetana is free software under the MIT license.

Copyright © 2023 Ollie Etherington.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CssValueToString added in v0.2.1

func CssValueToString(palette Palette, value any) (string, error)

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

func RandomString(n int) string

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

func RenderHtml(node Node) string

Render a Node to an HTML string with the default settings. See RenderHtmlOpts for more fine-grained control.

func RenderHtmlOpts

func RenderHtmlOpts(
	node Node,
	deterministicAttrs bool,
	logger *log.Logger,
) string

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

func RenderSitemap(sitemap Sitemap) string

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

func RenderSitemapOpts(sitemap Sitemap, logger *log.Logger) string

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

func WriteCssValue(builder *Builder, palette Palette, value any)

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.

func Xform added in v0.2.0

func Xform[A any, B any](values []A, xform func(a A) B) []B

Transform an array using a given function. This is equivalent to `map` in Haskell or Javascript. For example:

Xform([]int32{1, -2, 3}, func(a int32) uint32 {
	if a < 0 {
		a = -a
 	}
 	return uint32(a)
 })

will return []uint32{1, 2, 3}.

Types

type Attr

type Attr struct {
	Key   string
	Value string
}

A single HTML attribute. For example,

{Key: "href", Value: "https://duckduckgo.com"}

func Id

func Id(id string) Attr

A helper function to create an "id" attribute.

type Attrs

type Attrs map[string]string

A map of multiple HTML attributes.

type Builder

type Builder struct {
	Buf                     strings.Builder
	DeterministicAttributes bool
	Logger                  *log.Logger
}

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 CH

type CH float32

Utility type for marking CSS values as ch (adds a "ch" suffix).

func (CH) String

func (value CH) String() string

type CM

type CM float32

Utility type for marking CSS values as centimeters (adds a "cm" suffix).

func (CM) String

func (value CM) String() string

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 Children

type Children []Node

Many types of Node have children to create a tree.

type ClassName

type ClassName string

The name of a CSS class.

func ClassNames

func ClassNames(args ...any) ClassName

A utility function for concatenating multiple class names into a single string suitable for embedding in HTML. Arguments may be of several different types:

Arguments of other types are ignored.

type Classes

type Classes map[ClassName]bool

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 Color

type Color interface {
	String() string
	ToHsla() HSLA
	ToRgba() RGBA
}

A color value, suitable for use in CSS.

type CssProp added in v0.2.0

type CssProp struct {
	Key   string
	Value any
}

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

func A(args ...any) DomNode

Create an `a` DOM node. Arguments follow the semantics of NewDomNode.

func AHref

func AHref(href string, args ...any) DomNode

Create an `a` DOM node with the given href value. Arguments follow the semantics of NewDomNode.

func Abbr

func Abbr(args ...any) DomNode

Create an `abbr` DOM node. Arguments follow the semantics of NewDomNode.

func Address

func Address(args ...any) DomNode

Create an `address` DOM node. Arguments follow the semantics of NewDomNode.

func Area

func Area(args ...any) DomNode

Create an `area` DOM node. Arguments follow the semantics of NewDomNode.

func Article

func Article(args ...any) DomNode

Create an `article` DOM node. Arguments follow the semantics of NewDomNode.

func Aside

func Aside(args ...any) DomNode

Create an `aside` DOM node. Arguments follow the semantics of NewDomNode.

func Audio

func Audio(args ...any) DomNode

Create an `audio` DOM node. Arguments follow the semantics of NewDomNode.

func B

func B(args ...any) DomNode

Create a `b` DOM node. Arguments follow the semantics of NewDomNode.

func Base

func Base(args ...any) DomNode

Create a `base` DOM node. Arguments follow the semantics of NewDomNode.

func BaseHref

func BaseHref(href string) DomNode

Create a `base` DOM node with the given href value.

func Bdi

func Bdi(args ...any) DomNode

Create a `bdi` DOM node. Arguments follow the semantics of NewDomNode.

func Bdo

func Bdo(args ...any) DomNode

Create a `bdo` DOM node. Arguments follow the semantics of NewDomNode.

func Blockquote

func Blockquote(args ...any) DomNode

Create a `blockquote` DOM node. Arguments follow the semantics of NewDomNode.

func Body

func Body(args ...any) DomNode

Create a `body` DOM node. Arguments follow the semantics of NewDomNode.

func Br

func Br(args ...any) DomNode

Create a `br` DOM node. Arguments follow the semantics of NewDomNode.

func Button

func Button(args ...any) DomNode

Create a `button` DOM node. Arguments follow the semantics of NewDomNode.

func Canvas

func Canvas(args ...any) DomNode

Create a `canvas` DOM node. Arguments follow the semantics of NewDomNode.

func Caption

func Caption(args ...any) DomNode

Create a `caption` DOM node. Arguments follow the semantics of NewDomNode.

func Charset

func Charset(value string) DomNode

Create a `charset` DOM node. If value is the empty string then the default value of "UTF-8" is used.

func Cite

func Cite(args ...any) DomNode

Create a `cite` DOM node. Arguments follow the semantics of NewDomNode.

func Code

func Code(args ...any) DomNode

Create a `code` DOM node. Arguments follow the semantics of NewDomNode.

func Col

func Col(args ...any) DomNode

Create a `col` DOM node. Arguments follow the semantics of NewDomNode.

func Colgroup

func Colgroup(args ...any) DomNode

Create a `colgroup` DOM node. Arguments follow the semantics of NewDomNode.

func Data

func Data(args ...any) DomNode

Create a `data` DOM node. Arguments follow the semantics of NewDomNode.

func Datalist

func Datalist(args ...any) DomNode

Create a `datalist` DOM node. Arguments follow the semantics of NewDomNode.

func Dd

func Dd(args ...any) DomNode

Create a `dd` DOM node. Arguments follow the semantics of NewDomNode.

func Del

func Del(args ...any) DomNode

Create a `del` DOM node. Arguments follow the semantics of NewDomNode.

func Details

func Details(args ...any) DomNode

Create a `details` DOM node. Arguments follow the semantics of NewDomNode.

func Dfn

func Dfn(args ...any) DomNode

Create a `dfn` DOM node. Arguments follow the semantics of NewDomNode.

func Dialog

func Dialog(args ...any) DomNode

Create a `dialog` DOM node. Arguments follow the semantics of NewDomNode.

func Div

func Div(args ...any) DomNode

Create a `div` DOM node. Arguments follow the semantics of NewDomNode.

func Dl

func Dl(args ...any) DomNode

Create a `dl` DOM node. Arguments follow the semantics of NewDomNode.

func Dt

func Dt(args ...any) DomNode

Create a `dt` DOM node. Arguments follow the semantics of NewDomNode.

func Em

func Em(args ...any) DomNode

Create a `em` DOM node. Arguments follow the semantics of NewDomNode.

func Embed

func Embed(args ...any) DomNode

Create a `embed` DOM node. Arguments follow the semantics of NewDomNode.

func Fieldset

func Fieldset(args ...any) DomNode

Create a `fieldset` DOM node. Arguments follow the semantics of NewDomNode.

func Figcaption

func Figcaption(args ...any) DomNode

Create a `figcaption` DOM node. Arguments follow the semantics of NewDomNode.

func Figure

func Figure(args ...any) DomNode

Create a `figure` DOM node. Arguments follow the semantics of NewDomNode.

func Footer(args ...any) DomNode

Create a `footer` DOM node. Arguments follow the semantics of NewDomNode.

func Form

func Form(args ...any) DomNode

Create a `form` DOM node. Arguments follow the semantics of NewDomNode.

func H

func H(level int, args ...any) DomNode

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

func H1(args ...any) DomNode

Create a `h1` DOM node. Arguments follow the semantics of NewDomNode.

func H2

func H2(args ...any) DomNode

Create a `h2` DOM node. Arguments follow the semantics of NewDomNode.

func H3

func H3(args ...any) DomNode

Create a `h3` DOM node. Arguments follow the semantics of NewDomNode.

func H4

func H4(args ...any) DomNode

Create a `h4` DOM node. Arguments follow the semantics of NewDomNode.

func H5

func H5(args ...any) DomNode

Create a `h5` DOM node. Arguments follow the semantics of NewDomNode.

func H6

func H6(args ...any) DomNode

Create a `h6` DOM node. Arguments follow the semantics of NewDomNode.

func Head(args ...any) DomNode

Create a `head` DOM node. Arguments follow the semantics of NewDomNode.

func Header(args ...any) DomNode

Create a `header` DOM node. Arguments follow the semantics of NewDomNode.

func Hr

func Hr(args ...any) DomNode

Create a `hr` DOM node. Arguments follow the semantics of NewDomNode.

func I

func I(args ...any) DomNode

Create an `i` DOM node. Arguments follow the semantics of NewDomNode.

func Iframe

func Iframe(args ...any) DomNode

Create an `iframe` DOM node. Arguments follow the semantics of NewDomNode.

func Img

func Img(args ...any) DomNode

Create an `img` DOM node. Arguments follow the semantics of NewDomNode.

func Input

func Input(args ...any) DomNode

Create an `input` DOM node. Arguments follow the semantics of NewDomNode.

func Ins

func Ins(args ...any) DomNode

Create an `ins` DOM node. Arguments follow the semantics of NewDomNode.

func Kbd

func Kbd(args ...any) DomNode

Create a `kbd` DOM node. Arguments follow the semantics of NewDomNode.

func Label

func Label(args ...any) DomNode

Create a `level` DOM node. Arguments follow the semantics of NewDomNode.

func Legend

func Legend(args ...any) DomNode

Create a `legend` DOM node. Arguments follow the semantics of NewDomNode.

func Li

func Li(args ...any) DomNode

Create a `li` DOM node. Arguments follow the semantics of NewDomNode.

func Link(args ...any) DomNode

Create a `link` DOM node. Arguments follow the semantics of NewDomNode.

func LinkHref

func LinkHref(rel string, href string) DomNode

Create a `link` DOM node with the given values for the `rel` and `href` attributes.

func LinkStylesheet added in v0.2.0

func LinkStylesheet(href string) DomNode

Create a `link` DOM node for a CSS stylesheet with the given `href` attribute.

func LinkStylesheetMedia added in v0.2.0

func LinkStylesheetMedia(href string, media string) DomNode

Create a `link` DOM node for a CSS stylesheet with the given `href` and `media` attributes.

func Main

func Main(args ...any) DomNode

Create a `main` DOM node. Arguments follow the semantics of NewDomNode.

func Map

func Map(args ...any) DomNode

Create a `map` DOM node. Arguments follow the semantics of NewDomNode.

func Mark

func Mark(args ...any) DomNode

Create a `mark` DOM node. Arguments follow the semantics of NewDomNode.

func Meter

func Meter(args ...any) DomNode

Create a `meter` DOM node. Arguments follow the semantics of NewDomNode.

func Nav(args ...any) DomNode

Create a `nav` DOM node. Arguments follow the semantics of NewDomNode.

func NewDomNode

func NewDomNode(tag Tag, args []any) DomNode

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

func Noscript(args ...any) DomNode

Create a `noscript` DOM node. Arguments follow the semantics of NewDomNode.

func Object

func Object(args ...any) DomNode

Create an `object` DOM node. Arguments follow the semantics of NewDomNode.

func Ol

func Ol(args ...any) DomNode

Create an `ol` DOM node. Arguments follow the semantics of NewDomNode.

func Optgroup

func Optgroup(args ...any) DomNode

Create an `optgroup` DOM node. Arguments follow the semantics of NewDomNode.

func Option

func Option(args ...any) DomNode

Create an `option` DOM node. Arguments follow the semantics of NewDomNode.

func Output

func Output(args ...any) DomNode

Create an `output` DOM node. Arguments follow the semantics of NewDomNode.

func P

func P(args ...any) DomNode

Create a `p` DOM node. Arguments follow the semantics of NewDomNode.

func Param

func Param(args ...any) DomNode

Create a `param` DOM node. Arguments follow the semantics of NewDomNode.

func Picture

func Picture(args ...any) DomNode

Create a `picture` DOM node. Arguments follow the semantics of NewDomNode.

func Pre

func Pre(args ...any) DomNode

Create a `pre` DOM node. Arguments follow the semantics of NewDomNode.

func Progress

func Progress(args ...any) DomNode

Create a `progress` DOM node. Arguments follow the semantics of NewDomNode.

func Q

func Q(args ...any) DomNode

Create a `q` DOM node. Arguments follow the semantics of NewDomNode.

func Rp

func Rp(args ...any) DomNode

Create an `rp` DOM node. Arguments follow the semantics of NewDomNode.

func Rt

func Rt(args ...any) DomNode

Create an `rt` DOM node. Arguments follow the semantics of NewDomNode.

func Ruby

func Ruby(args ...any) DomNode

Create a `ruby` DOM node. Arguments follow the semantics of NewDomNode.

func S

func S(args ...any) DomNode

Create an `s` DOM node. Arguments follow the semantics of NewDomNode.

func Samp

func Samp(args ...any) DomNode

Create a `samp` DOM node. Arguments follow the semantics of NewDomNode.

func Script

func Script(args ...any) DomNode

Create a `script` DOM node. Arguments follow the semantics of NewDomNode.

func ScriptSrc

func ScriptSrc(src string) DomNode

Create a `script` DOM node with the given "src" URL.

func Section

func Section(args ...any) DomNode

Create a `section` DOM node. Arguments follow the semantics of NewDomNode.

func Select

func Select(args ...any) DomNode

Create a `select` DOM node. Arguments follow the semantics of NewDomNode.

func Small

func Small(args ...any) DomNode

Create a `small` DOM node. Arguments follow the semantics of NewDomNode.

func Source

func Source(args ...any) DomNode

Create a `source` DOM node. Arguments follow the semantics of NewDomNode.

func Span

func Span(args ...any) DomNode

Create a `span` DOM node. Arguments follow the semantics of NewDomNode.

func Strong

func Strong(args ...any) DomNode

Create a `strong` DOM node. Arguments follow the semantics of NewDomNode.

func Style

func Style(args ...any) DomNode

Create a `style` DOM node. Arguments follow the semantics of NewDomNode.

func Sub

func Sub(args ...any) DomNode

Create a `sub` DOM node. Arguments follow the semantics of NewDomNode.

func Summary

func Summary(args ...any) DomNode

Create a `summary` DOM node. Arguments follow the semantics of NewDomNode.

func Sup

func Sup(args ...any) DomNode

Create a `sup` DOM node. Arguments follow the semantics of NewDomNode.

func Svg

func Svg(args ...any) DomNode

Create a `svg` DOM node. Arguments follow the semantics of NewDomNode.

func Table

func Table(args ...any) DomNode

Create a `table` DOM node. Arguments follow the semantics of NewDomNode.

func Tbody

func Tbody(args ...any) DomNode

Create a `tbody` DOM node. Arguments follow the semantics of NewDomNode.

func Td

func Td(args ...any) DomNode

Create a `td` DOM node. Arguments follow the semantics of NewDomNode.

func Template

func Template(args ...any) DomNode

Create a `template` DOM node. Arguments follow the semantics of NewDomNode.

func Textarea

func Textarea(args ...any) DomNode

Create a `textarea` DOM node. Arguments follow the semantics of NewDomNode.

func Tfoot

func Tfoot(args ...any) DomNode

Create a `tfoot` DOM node. Arguments follow the semantics of NewDomNode.

func Th

func Th(args ...any) DomNode

Create a `th` DOM node. Arguments follow the semantics of NewDomNode.

func Thead

func Thead(args ...any) DomNode

Create a `thead` DOM node. Arguments follow the semantics of NewDomNode.

func Time

func Time(args ...any) DomNode

Create a `time` DOM node. Arguments follow the semantics of NewDomNode.

func Title

func Title(args ...any) DomNode

Create a `title` DOM node. Arguments follow the semantics of NewDomNode.

func Tr

func Tr(args ...any) DomNode

Create a `tr` DOM node. Arguments follow the semantics of NewDomNode.

func Track

func Track(args ...any) DomNode

Create a `track` DOM node. Arguments follow the semantics of NewDomNode.

func U

func U(args ...any) DomNode

Create a `u` DOM node. Arguments follow the semantics of NewDomNode.

func Ul

func Ul(args ...any) DomNode

Create a `ul` DOM node. Arguments follow the semantics of NewDomNode.

func Var

func Var(args ...any) DomNode

Create a `var` DOM node. Arguments follow the semantics of NewDomNode.

func Video

func Video(args ...any) DomNode

Create a `video` DOM node. Arguments follow the semantics of NewDomNode.

func Wbr

func Wbr(args ...any) DomNode

Create a `wbr` DOM node. Arguments follow the semantics of NewDomNode.

func (*DomNode) AssignAttrs

func (node *DomNode) AssignAttrs(attrs Attrs)

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

func (node *DomNode) AssignChildren(children Children)

Append more children to the end of a DomNode.

func (DomNode) ToHtml

func (node DomNode) ToHtml(builder *Builder)

Convert a DomNode to HTML.

type EM

type EM float32

Utility type for marking CSS values as em (adds an "em" suffix).

func (EM) String

func (value EM) String() string

type EX

type EX float32

Utility type for marking CSS values as ex (adds an "ex" suffix).

func (EX) String

func (value EX) String() string

type EquivNode

type EquivNode struct {
	Equiv   string
	Content string
}

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 Equiv

func Equiv(equiv string, content string) EquivNode

Create a generic EquivNode with the given http-equiv and content

func Refresh

func Refresh(value uint) EquivNode

Create an EquivNode with "http-equiv" set to "refresh" and "content" set to the provided value in seconds.

func XUaCompatible

func XUaCompatible(value string) EquivNode

Create an EquivNode with "http-equiv" set to "x-ua-compatible" and "content" set to the given value

func (EquivNode) ToHtml

func (node EquivNode) ToHtml(builder *Builder)

Convert an EquivNode to HTML

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

type HSL struct {
	H uint16
	S float32
	L float32
}

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.

func Hsl

func Hsl(h uint16, s float32, l float32) HSL

Create an HSL color.

func (HSL) String added in v0.2.0

func (c HSL) String() string

Convert an HSL color to a CSS string.

func (HSL) ToHsla

func (c HSL) ToHsla() HSLA

Convert an HSL into an HSLA.

func (HSL) ToRgba

func (c HSL) ToRgba() RGBA

Convert an HSL into an RGBA.

type HSLA

type HSLA struct {
	H uint16
	S float32
	L float32
	A float32
}

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

func Darken(c Color, amount float32) HSLA

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 Hsla

func Hsla(h uint16, s float32, l float32, a float32) HSLA

Create an HSL color.

func Lighten

func Lighten(c Color, amount float32) HSLA

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.

func (HSLA) String added in v0.2.0

func (c HSLA) String() string

Convert an HSLA color to a CSS string.

func (HSLA) ToHsla

func (c HSLA) ToHsla() HSLA

Convert an HSLA into an HSLA.

func (HSLA) ToRgba

func (c HSLA) ToRgba() RGBA

Convert an HSLA into an RGBA.

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

func Html(args ...any) HtmlNode

Create an `html` DOM node. Arguments follow the semantics of NewDomNode.

func (HtmlNode) ToHtml

func (node HtmlNode) ToHtml(builder *Builder)

Convert an HtmlNode to HTML.

type IN

type IN float32

Utility type for marking CSS values as inches (adds an "in" suffix).

func (IN) String

func (value IN) String() string

type MM

type MM float32

Utility type for marking CSS values as millimeters (adds an "mm" suffix).

func (MM) String

func (value MM) String() string

type MetaNode

type MetaNode struct {
	Name    string
	Content string
}

A "meta" Node in an HTML document to associate some "content" value to a particular "name".

func Author

func Author(value string) MetaNode

Create an "author" MetaNode with the given value

func Description

func Description(value string) MetaNode

Create a "description" MetaNode with the given value

func Keywords

func Keywords(value string) MetaNode

Create a "keywords" MetaNode with the given value

func Meta

func Meta(name string, content string) MetaNode

Create a generic MetaNode with the given name and content

func Viewport

func Viewport(value string) MetaNode

Create a "viewport" MetaNode with the given value, or, if the empty string is provided, the default "width=device-width, initial-scale=1.0"

func (MetaNode) ToHtml

func (node MetaNode) ToHtml(builder *Builder)

Convert a MetaNode to HTML

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 PC

type PC float32

Utility type for marking CSS values as pc (adds a "pc" suffix).

func (PC) String

func (value PC) String() string

type PT

type PT float32

Utility type for marking CSS values as points (adds a "pt" suffix).

func (PT) String

func (value PT) String() string

type PX

type PX float32

Utility type for marking CSS values as pixels (adds a "px" suffix).

func (PX) String

func (value PX) String() string

type Palette added in v0.2.0

type Palette map[string]fmt.Stringer

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

type PalettePrintfData struct {
	Format string
	Args   []any
}

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 Palettes added in v0.2.0

type Palettes map[string]Palette

A map from a palette name to a Palette

type Perc

type Perc float32

Utility type for marking CSS values as a percentage (adds a "%" suffix).

func (Perc) String

func (value Perc) String() string

type REM

type REM float32

Utility type for marking CSS values as rem (adds a "rem" suffix).

func (REM) String

func (value REM) String() string

type RGB

type RGB struct {
	R uint8
	G uint8
	B uint8
}

Structure representing an RGB Color. All values are unsigned from 0-255 inclusive. Also see Rgb.

func Hex

func Hex(s string) RGB

Create an RGB color from a hex string (ie; "#FFFFFF").

func Rgb

func Rgb(r uint8, g uint8, b uint8) RGB

Create an RGB color.

func (RGB) String added in v0.2.0

func (c RGB) String() string

Convert an RGB color to a CSS string.

func (RGB) ToHsla

func (c RGB) ToHsla() HSLA

Convert an RGB into an HSLA.

func (RGB) ToRgba

func (c RGB) ToRgba() RGBA

Convert an RGB into an RGBA.

type RGBA

type RGBA struct {
	R uint8
	G uint8
	B uint8
	A uint8
}

Structure representing an RGB Color plus an alpha channel. All values are unsigned from 0-255 inclusive. Also see Rgba.

func Rgba

func Rgba(r uint8, g uint8, b uint8, a uint8) RGBA

Create an RGBA color.

func (RGBA) String added in v0.2.0

func (c RGBA) String() string

Convert an RGBA color to a CSS string.

func (RGBA) ToHsla

func (c RGBA) ToHsla() HSLA

Convert an RGBA into an HSLA.

func (RGBA) ToRgba

func (c RGBA) ToRgba() RGBA

Convert an RGBA into an 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.

func (Sitemap) ToXml added in v0.2.0

func (sitemap Sitemap) ToXml(builder *Builder)

Convert a Sitemap to an XML string.

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 NewSmetanaWithPalettes(palettes Palettes) Smetana

Create a new Smetana instance with specific Palettes.

func (*Smetana) AddPalette added in v0.2.0

func (s *Smetana) AddPalette(name string, palette Palette)

Add a new Palette to a Smetana context with the given name.

func (Smetana) RenderStyles added in v0.2.0

func (s Smetana) RenderStyles() map[string]string

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

func (s Smetana) RenderStylesOpts(logger *log.Logger) map[string]string

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

type StyleSheetBlock struct {
	Selector string
	Props    CssProps
}

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 StylesCss

func StylesCss(css string) StyleSheetCss

Create a StyleSheetCss StyleSheetElement.

func (StyleSheetCss) ToCss

func (css StyleSheetCss) ToCss(builder *Builder, palette Palette)

Convert [StyleSheetCSS] into a CSS string.

type StyleSheetElement

type StyleSheetElement interface {
	ToCss(builder *Builder, palette Palette)
}

Interface representing an abstract element to be inserted into a CSS StyleSheet.

type StyleSheetFontFace

type StyleSheetFontFace struct {
	Family string
	Srcs   []string
}

@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

type StyleSheetPaletteCss func(palette Palette) string

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 Tag

type Tag = string

Type alias for an HTML tag name (ie; "div", "span", etc.)

type TextNode

type TextNode struct {
	Text string
}

A Node representing raw text without any surrounding tag.

func Text

func Text(text string) TextNode

Create a TextNode from the given string.

func (TextNode) ToHtml

func (node TextNode) ToHtml(builder *Builder)

Convert a TextNode to HTML.

type VH

type VH float32

Utility type for marking CSS values as vh (adds a "vh" suffix).

func (VH) String

func (value VH) String() string

type VMax

type VMax float32

Utility type for marking CSS values as vmax (adds a "vmax" suffix).

func (VMax) String

func (value VMax) String() string

type VMin

type VMin float32

Utility type for marking CSS values as vmin (adds a "vmin" suffix).

func (VMin) String

func (value VMin) String() string

type VW

type VW float32

Utility type for marking CSS values as vw (adds a "vw" suffix).

func (VW) String

func (value VW) String() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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