Documentation ¶
Overview ¶
Gohtx is an extended version of github.com/Michael-F-Ellis/goht. It embeds HTMX, HyperScript and Bulma CSS in the package binary.
Index ¶
- Constants
- Variables
- func AddGohtxAssetHandler()
- func Gohtify(htext string, gofmt bool, ignoreTags map[string]struct{}, gohttext *string) (err error)
- func GohtxFS() embed.FS
- func Ids(tree *HtmlTree, ids *[]string) (err error)
- func Render(h *HtmlTree, b *bytes.Buffer, nindent int) (err error)
- type AttributeErrors
- type HtmlTree
- func A(a string, c ...interface{}) *HtmlTree
- func Address(a string, c ...interface{}) *HtmlTree
- func Area(a string) *HtmlTree
- func Article(a string, c ...interface{}) *HtmlTree
- func Aside(a string, c ...interface{}) *HtmlTree
- func Audio(a string, c ...interface{}) *HtmlTree
- func B(a string, c ...interface{}) *HtmlTree
- func Blockquote(a string, c ...interface{}) *HtmlTree
- func Body(a string, c ...interface{}) *HtmlTree
- func Br(a string) *HtmlTree
- func Button(a string, c ...interface{}) *HtmlTree
- func Canvas(a string, c ...interface{}) *HtmlTree
- func Caption(a string, c ...interface{}) *HtmlTree
- func Cite(a string, c ...interface{}) *HtmlTree
- func Code(a string, c ...interface{}) *HtmlTree
- func Col(a string) *HtmlTree
- func Comment(a string) *HtmlTree
- func CustomHeadContent(htmx, hyperscript, bulma bool) (h *HtmlTree)
- func Datalist(a string, c ...interface{}) *HtmlTree
- func Dd(a string, c ...interface{}) *HtmlTree
- func DefaultHeadContent() (h *HtmlTree)
- func Details(a string, c ...interface{}) *HtmlTree
- func Dialog(a string, c ...interface{}) *HtmlTree
- func Div(a string, c ...interface{}) *HtmlTree
- func Dl(a string, c ...interface{}) *HtmlTree
- func Dt(a string, c ...interface{}) *HtmlTree
- func Em(a string, c ...interface{}) *HtmlTree
- func Embed(a string) *HtmlTree
- func Fieldset(a string, c ...interface{}) *HtmlTree
- func Figcaption(a string, c ...interface{}) *HtmlTree
- func Figure(a string, c ...interface{}) *HtmlTree
- func Footer(a string, c ...interface{}) *HtmlTree
- func Form(a string, c ...interface{}) *HtmlTree
- func H1(a string, c ...interface{}) *HtmlTree
- func H2(a string, c ...interface{}) *HtmlTree
- func H3(a string, c ...interface{}) *HtmlTree
- func H4(a string, c ...interface{}) *HtmlTree
- func H5(a string, c ...interface{}) *HtmlTree
- func H6(a string, c ...interface{}) *HtmlTree
- func Head(a string, c ...interface{}) *HtmlTree
- func Header(a string, c ...interface{}) *HtmlTree
- func Hr(a string) *HtmlTree
- func Html(a string, c ...interface{}) *HtmlTree
- func I(a string, c ...interface{}) *HtmlTree
- func Img(a string) *HtmlTree
- func Input(a string) *HtmlTree
- func Label(a string, c ...interface{}) *HtmlTree
- func Legend(a string, c ...interface{}) *HtmlTree
- func Li(a string, c ...interface{}) *HtmlTree
- func Link(a string) *HtmlTree
- func Main(a string, c ...interface{}) *HtmlTree
- func Map(a string, c ...interface{}) *HtmlTree
- func Meta(a string) *HtmlTree
- func Meter(a string, c ...interface{}) *HtmlTree
- func Nav(a string, c ...interface{}) *HtmlTree
- func Noscript(a string, c ...interface{}) *HtmlTree
- func Null(c ...interface{}) *HtmlTree
- func Object(a string, c ...interface{}) *HtmlTree
- func Ol(a string, c ...interface{}) *HtmlTree
- func Optgroup(a string, c ...interface{}) *HtmlTree
- func Option(a string, c ...interface{}) *HtmlTree
- func Output(a string, c ...interface{}) *HtmlTree
- func P(a string, c ...interface{}) *HtmlTree
- func Param(a string) *HtmlTree
- func Pre(a string, c ...interface{}) *HtmlTree
- func Progress(a string, c ...interface{}) *HtmlTree
- func S(a string, c ...interface{}) *HtmlTree
- func Samp(a string, c ...interface{}) *HtmlTree
- func Script(a string, c ...interface{}) *HtmlTree
- func Section(a string, c ...interface{}) *HtmlTree
- func Select(a string, c ...interface{}) *HtmlTree
- func Small(a string, c ...interface{}) *HtmlTree
- func Source(a string) *HtmlTree
- func Span(a string, c ...interface{}) *HtmlTree
- func Strong(a string, c ...interface{}) *HtmlTree
- func Style(a string, c ...interface{}) *HtmlTree
- func Sub(a string, c ...interface{}) *HtmlTree
- func Summary(a string, c ...interface{}) *HtmlTree
- func Sup(a string, c ...interface{}) *HtmlTree
- func Table(a string, c ...interface{}) *HtmlTree
- func Tbody(a string, c ...interface{}) *HtmlTree
- func Td(a string, c ...interface{}) *HtmlTree
- func Textarea(a string, c ...interface{}) *HtmlTree
- func Tfoot(a string, c ...interface{}) *HtmlTree
- func Th(a string, c ...interface{}) *HtmlTree
- func Thead(a string, c ...interface{}) *HtmlTree
- func Title(a string, c ...interface{}) *HtmlTree
- func Tr(a string, c ...interface{}) *HtmlTree
- func Track(a string) *HtmlTree
- func U(a string, c ...interface{}) *HtmlTree
- func Ul(a string, c ...interface{}) *HtmlTree
- func Video(a string, c ...interface{}) *HtmlTree
Constants ¶
const GohtxAssetPath = "/gohtx/" // default route to embedded assets.
Variables ¶
var Attributes map[string][]string
Attributes is filled in at init time with a list of attributes and the tag names that support them.
var HxAttrs []string = []string{
"hx-boost",
"hx-get",
"hx-post",
"hx-push-url",
"hx-select",
"hx-select-oob",
"hx-swap",
"hx-swap-oob",
"hx-target",
"hx-trigger",
"hx-vals",
"hx-confirm",
"hx-delete",
"hx-disable",
"hx-disinherit",
"hx-encoding",
"hx-ext",
"hx-headers",
"hx-history-elt",
"hx-include",
"hx-indicator",
"hx-params",
"hx-patch",
"hx-preserve",
"hx-prompt",
"hx-put",
"hx-replace-url",
"hx-request",
"hx-sse",
"hx-sync",
"hx-vars",
"hx-ws",
"_",
"script",
}
HxAttrs is a slice of string containing the names of all valid htmx attributes. The names ad descriptions are taken from https://htmx.org/reference/
Functions ¶
func AddGohtxAssetHandler ¶ added in v0.10.0
func AddGohtxAssetHandler()
AddGohtxAssetHandler is a convenience function that adds an http.Handler to process requests for assets in the embedded FS. Use this to avoid having to know about the path string.
func Gohtify ¶
func Gohtify(htext string, gofmt bool, ignoreTags map[string]struct{}, gohttext *string) (err error)
Gohtify parses an html string, htext, and returns equivalent goht code in gohttext. The ignoreTags map contains one or more tags to be ignored as map keys. These are typically "html", "head" and "body" because html.Parse creates them if they're not present in the string. That's usually not desired since the chief use of Gohtify is to turn useful fragments of html into into equivalent Go code.
func GohtxFS ¶
GohtxFS returns the embedded filesystem containing htmx.min.js and bulma.css. To serve them, do something like: fs := GohtxFS() buf, err := fs.ReadFile("htmx.min.js")
func Ids ¶
Ids returns a slice of string containing all the id attributes found in tree. It will return an error if the search finds a malformed id, multiple ids in the same tag or the same id in different tags.
func Render ¶
Render walks through HtmlTree h and writes html text to byte buffer b. The nindent argument specifies whether and how much to indent the output where -1 means render all on one line and 0 means indent each inner tag by 2 spaces relative to its parent. Render returns an error when it encounters invalid content.
Types ¶
type AttributeErrors ¶
type AttributeErrors struct { Tag string // an html tag Attrs string // a string of zero or more attributes Errs []error // errors found in attrs }
AttributeErrors is a struct returned by CheckAttributes. It contains the tag, the string of attributes and a slice of errors returned by checkTagAttributes.
type HtmlTree ¶
type HtmlTree struct { T string // html tagname, e.g. 'head' A string // zero or more html attributes, e.g 'id=1 class="foo"' C []interface{} // a slice of content whose elements may be strings or *HtmlTree // contains filtered or unexported fields }
HtmlTree represents a tree of html content.
func Address ¶
Address, when rendered, returns a <address> element with the given attributes and content.
func Article ¶
Article, when rendered, returns an <article> element with the given attributes and content.
func Aside ¶
Aside, when rendered, returns an <aside> element with the given attributes and content.
func Blockquote ¶
Blockquote, when rendered, returns a <blockquote> element with the given attributes and content.
func Button ¶
Button, when rendered, returns a <button> element with the given attributes and content.
func Canvas ¶
Canvas, when rendered, returns a <canvas> element with the given attributes and content.
func Caption ¶
Caption, when rendered, returns a <caption> element with the given attributes and content.
func CustomHeadContent ¶ added in v0.9.0
CustomHeadContent returns the same Meta elements you would typically include in the <head> element of a responsive web page and allows you to choose which, if any, of htmx, hyperscript, and bulma to include.
func Datalist ¶
Datalist, when rendered, returns a <datalist> element with the given attributes and content.
func DefaultHeadContent ¶ added in v0.8.0
func DefaultHeadContent() (h *HtmlTree)
DefaultHeadContent calls CustomHeadContent specifying htmx and bulma without hyperscript.
func Details ¶
Details, when rendered, returns a <details> element with the given attributes and content.
func Dialog ¶
As of 2021, <dialog> is supported by Chrome, Edge & Opera but not by FireFox and Safari. Dialog, when rendered, returns a <dialog> element with the given attributes and content.
func Fieldset ¶
Fieldset, when rendered, returns a <fieldset> element with the given attributes and content.
func Figcaption ¶
Figcaption, when rendered, returns a <figcaption> element with the given attributes and content.
func Figure ¶
Figure, when rendered, returns a <figure> element with the given attributes and content.
func Footer ¶
Footer, when rendered, returns a <footer> element with the given attributes and content.
func Header ¶
Header, when rendered, returns a <header> element with the given attributes and content.
func Legend ¶
Legend, when rendered, returns a <legend> element with the given attributes and content.
func Noscript ¶
Noscript, when rendered, returns a <noscript> element with the given attributes and content.
func Null ¶
func Null(c ...interface{}) *HtmlTree
Null tag is a special case and does not correspond to any valid HTML tag. When rendered it returns its content with no enclosing tag, e.g. Null(Br(“),Br(“)) --> <br><br> . It is defined in goht to support injecting a list of elements into an existing tag as JavaScript innerHTML content.
func Object ¶
Object, when rendered, returns a <object> element with the given attributes and content.
func Optgroup ¶
Optgroup, when rendered, returns a <optgroup> element with the given attributes and content.
func Option ¶
Option, when rendered, returns a <option> element with the given attributes and content.
func Output ¶
Output, when rendered, returns a <output> element with the given attributes and content.
func Progress ¶
Progress, when rendered, returns a <progress> element with the given attributes and content.
func Script ¶
Script, when rendered, returns a <script> element with the given attributes and content.
func Section ¶
Section, when rendered, returns a <section> element with the given attributes and content.
func Select ¶
Select, when rendered, returns a <select> element with the given attributes and content.
func Strong ¶
Strong, when rendered, returns a <strong> element with the given attributes and content.
func Style ¶
Style is a special case in the sense that the only valid content is one or more strings of CSS. At this time there's no check to complain about other content.
func Summary ¶
Summary, when rendered, returns a <summary> element with the given attributes and content.
func Textarea ¶
Textarea, when rendered, returns a <textarea> element with the given attributes and content.
func Thead ¶
Thead, when rendered , returns a <thead> element with the given attributes and content.
func (*HtmlTree) CheckAttributes ¶
func (e *HtmlTree) CheckAttributes(perrs *[]AttributeErrors)
CheckAttributes walks through an ElementTree and checks each tag to verify that the attribute names associated with the tag are valid for that tag. It returns a slice AttributeErrors. The slice will be empty if no errors were found.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
cmd
|
|
gohtify
gohtify reads html fragments from stdin and emits goht code on stdout.
|
gohtify reads html fragments from stdin and emits goht code on stdout. |
playground
The gohtx app skeleton demonstrates the essentials of using gohtx, htmx, hyperscript and bulma to build a single binary containing a server and embedded content to generate and serve a responsive application.
|
The gohtx app skeleton demonstrates the essentials of using gohtx, htmx, hyperscript and bulma to build a single binary containing a server and embedded content to generate and serve a responsive application. |
skeleton
The gohtx app skeleton demonstrates the essentials of using gohtx, htmx, hyperscript and bulma to build a single binary containing a server and embedded content to generate and serve a responsive application.
|
The gohtx app skeleton demonstrates the essentials of using gohtx, htmx, hyperscript and bulma to build a single binary containing a server and embedded content to generate and serve a responsive application. |