elements

package module
v0.0.8 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2019 License: GPL-3.0 Imports: 4 Imported by: 0

README

Elements

Build markup documents out of simple objects in Golang.

Inspired by the now retired Apache ECS.

Status: In development.

	el := NewElement("tag").
		AddAttr("tagged").
		SetAttr("foo", "bar").
		AddChild(NewElement("nav")).
		AddChild(NewElement("main"))
		
	fmt.Println(el)	

Features

  • Build markup without resorting to string manipulation.
  • Add any Stringer type.

Roadmap:

  • Use Formatters to change between output types (html, xhtml, html5).
  • Built-in library of HTML5 elements.
  • Use Nodes directly as http.Handlers.

Installation

go get kilobit.ca/go/elements

Building

cd kilobit.ca/go/elements
go test -v
go build

Contribute

Please submit a pull request with any bug fixes or feature requests that you have. All submissions imply consent to use / distribute under the terms of the LICENSE.

Support

Submit tickets through github.

License

See LICENSE.

--
Created: Oct 1, 2019
By: Christian Saunders cps@kilobit.ca
Copyright 2019 Kilobit Labs Inc.

Documentation

Overview

Build markup documents from simple objects.

Index

Constants

View Source
const HTML5Doctype string = "<!DOCTYPE html>"

Variables

This section is empty.

Functions

func Expect

func Expect(t *testing.T, expected interface{}, actual interface{})

func IDString

func IDString(s string) string

func QuoteString

func QuoteString(s string) string

Types

type Attributes

type Attributes map[string]string

type ContentNode

type ContentNode string

func Content

func Content(s string) ContentNode

func (ContentNode) String

func (s ContentNode) String() string

type Document

type Document interface {
	Doctype() string
}

A fully encapsulated markup document.

type Element

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

func NewElement

func NewElement(tag string, opts ...ElementOption) *Element

func (*Element) AddAttr

func (el *Element) AddAttr(ks ...string) *Element

func (*Element) AddChild

func (el *Element) AddChild(c ...Node) *Element

func (*Element) AddClass

func (el *Element) AddClass(class string) *Element

func (*Element) Attr

func (el *Element) Attr(k string) string

func (*Element) ChildN

func (el *Element) ChildN(n int) Node

func (*Element) Children

func (el *Element) Children() []Node

func (*Element) Copy added in v0.0.2

func (el *Element) Copy() *Element

func (*Element) Format

func (el *Element) Format() *Format

func (*Element) HasClass

func (el *Element) HasClass(class string) bool

func (*Element) ID

func (el *Element) ID() string

func (*Element) SetAttr

func (el *Element) SetAttr(k string, v string) *Element

func (*Element) SetAttrs added in v0.0.6

func (el *Element) SetAttrs(kvs map[string]string) *Element

func (*Element) SetFormat

func (el *Element) SetFormat(fmt *Format)

func (*Element) SetID

func (el *Element) SetID(id string) *Element

func (*Element) String

func (el *Element) String() string

func (*Element) Tag

func (el *Element) Tag() string

type ElementOption

type ElementOption func(el *Element)

func OptFormat

func OptFormat(fmt *Format) ElementOption

type Format

type Format struct {
	Close       bool   // Self closing
	Sep         string // Separator
	Prefix      string
	CPrefix     string // Child Prefix
	TagFmt      Formatter
	TagOpen     string
	TagClose    string
	EndTagOpen  string
	EndTagClose string
	AttrSep     string
	AttrKFmt    Formatter
	AttrVFmt    Formatter
}

Format for the element.

type Formatter

type Formatter func(s string) string

Definition for simple functions that format the element.

type HTML5Document

type HTML5Document struct {
}

func (*HTML5Document) Doctype

func (doc *HTML5Document) Doctype() string

type Node

type Node interface {
	fmt.Stringer
}

Directories

Path Synopsis
HTML5 specific documents, tags and formatters.
HTML5 specific documents, tags and formatters.

Jump to

Keyboard shortcuts

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