gomponents

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2020 License: MIT Imports: 3 Imported by: 0

README

gomponents

GoDoc codecov

gomponents are components of DOM nodes for Go, that can render to an HTML Document. gomponents aims to make it easy to build HTML pages of reusable components, without the use of a template language. Think server-side-rendered React, but without the virtual DOM and diffing.

The implementation is still incomplete, but usable. The API may change until version 1 is reached.

Documentation

Overview

Package gomponents provides components of DOM nodes for Go, that can render to an HTML Document. The primary interface is a Node, which has a single function Render, which should render the Node to a string. Furthermore, NodeFunc is a function which implements the Node interface by calling itself on Render. All DOM elements and attributes can be created by using the El and Attr functions. The package also provides a lot of convenience functions for creating elements and attributes with the most commonly used parameters. If they don't suffice, a fallback to El and Attr is always possible.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Node

type Node interface {
	Render() string
}

Node is a DOM node that can Render itself to a string representation.

func Attr

func Attr(name string, value ...string) Node

Attr creates an attr DOM Node. If one parameter is passed, it's a name-only attribute (like "required"). If two parameters are passed, it's a name-value attribute (like `class="header"`). More parameter counts make Attr panic. Use this if no convenience creator exists.

type NodeFunc

type NodeFunc func() string

NodeFunc is render function that is also a Node.

func El

func El(name string, children ...Node) NodeFunc

El creates an element DOM Node with a name and child Nodes. Use this if no convenience creator exists.

func Raw

func Raw(t string) NodeFunc

Raw creates a raw Node that just Renders the unescaped string t.

func Text

func Text(t string) NodeFunc

Text creates a text DOM Node that Renders the escaped string t.

func (NodeFunc) Render

func (n NodeFunc) Render() string

func (NodeFunc) String added in v0.2.0

func (n NodeFunc) String() string

String satisfies fmt.Stringer.

Directories

Path Synopsis
Package attr provides shortcuts and helpers to common HTML attributes.
Package attr provides shortcuts and helpers to common HTML attributes.
Package el provides shortcuts and helpers to common HTML elements.
Package el provides shortcuts and helpers to common HTML elements.

Jump to

Keyboard shortcuts

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