Documentation ¶
Overview ¶
Package html provide objects representing HTML 5 tags that can be joined into a *Doc object and rendered. It provides support for attaching event objects and dynamic content.
This package is akin to assembly language for web display.
Prerequisites ¶
To get the most out of the package, you will need the following:
- An understanding of how HTML/CSS works
- More than a passing familiarity with the net/http package
Package Layout ¶
All HTML tags and attribute types are contained in one large package. Normally this is undesirable, creating too much "noise" in package documentation. But we want to emulate the HTML flat namespace to allow easy browsing for people already familiar with HTML.
If you are looking for an <a> tag, it will be html.A{}. If you are looking for an <img>, it will be html.Img{} and so on.
Note: This package does not currently contain all tags in HTML 5. These will be slowly added.
Element - The Basic Type ¶
The Element interface is implemeted by all all html objects that wil produce output. These objects represent our HTML tags and special object that can output dynamic content.
Doc - The Core Type ¶
The Doc type represents an HTML 5 document. Everything in the package eventually will end up in in a Doc for rendering.
The Doc is also used to build component.Gear objects which represent HTML Shadow-DOM components.
Basic Usage ¶
Create a page with basic header information that links to a stylesheet and prints "Hello World".
doc := &html.Doc{ Head: &html.Head{ Elements: []html.Element{ &html.Meta{Charset: "UTF-8"}, &html.Title{TagValue: html.TextElement("Simple Example")}, &html.Link{Rel: "stylesheet", Href: html.URLParse("/static/index.css")}, &html.Link{Href: html.URLParse("https://fonts.googleapis.com/css2?family=Share+Tech+Mono&display=swap"), Rel: "stylesheet"}, }, }, Body: &html.Body{ Elements: []html.Element{ html.TextElement("Hello World") }, }, } // To serve the page, see the handlers/ package.
Serve Dynamic Content ¶
Similar to the template system, this package allows adding dynamic generated content. This is done by implementing a DynamicFunc type and attaching it as an Element object to another type. This is done via the Dynamic type. A DynamicFunc simply creates and returns a list of []Element objects that will be inserted. This example will serve a page that dynamically generates content from a slice. In a real situation, this could be fetched from a file, a cache, ....
// site represents a name of a site and a url to that site. type site struct { name string url *url.URL } // sites is used to implement html.DynamicFunc. type sites struct { sites []site } // List implements html.DynamicFunc to take a list of sites and display links to them. func (s sites) List(pipe Pipeline) []html.Element { if err := pipe.Ctx.Err(); err != nil { return nil } elements := []html.Element{} for _, site := range s.sites { elements = append( elements, &html.A{Href: url.String(), Elements: []html.Element(html.TextElement(site.name))}, ) } return elements } // This creats an instance of sites{} that has various names and urls that we wish to list out. var siteLister = sites{ sites: []site{ {"Microsoft", html.URLParse("www.microsoft.com")}, {"Google", html.URLParse("www.google.com")}, {"LucasFilm", html.URLParse("www.lucasfilm.com")}, } // Create a page with basic header information that links to a stylesheet and prints "Hello World". doc := &html.Doc{ Head: &html.Head{ Elements: []html.Element{ &html.Meta{Charset: "UTF-8"}, &html.Title{TagValue: html.TextElement("Dyanic Example")}, &html.Link{Rel: "stylesheet", Href: html.URLParse("/static/index.css")}, &html.Link{Href: html.URLParse("https://fonts.googleapis.com/css2?family=Share+Tech+Mono&display=swap"), Rel: "stylesheet"}, }, }, Body: &html.Body{ Elements: []html.Element{ html.Dynamic(siteLister.List), }, }, } // To serve the page, see the handlers/ package.
The Pipeline ¶
When implementing DynamicFunc above, the function signature requires a Pipeline object. Pipeline provides a changing context object that passes certain information through the program flow. This includes the actual Context of a call, the http.Request object and the output buffer W. The other attributes are not useful in this context.
Here is an example of a DynamicFunc that returns the path of the URL it received for this call:
func URLPath(pipe Pipeline) []html.Element { if err := pipe.Ctx.Err(); err != nil { return nil } return []Element{html.TextElement(pipe.Req.URL.Path)} }
GlobalAttr ¶
Most objects implement the GlobalAttr. This provides standard attributes such as "id" or "class". When available, this is implemented by embedding a GlobalAttr object in a tag type.
&html.A{ GlobalAttr: GlobalAttr{ID: "golangLink"}, Elements: []Element{TextElement("Golang.org")}, Href: "http://golang.org", }
Attaching Events ¶
Events are available on objects that support them via an Event attribute. You can attach an event by simply calling a method on the object that you wish to attach a script to.
&html.Body{Events: &Events{}.OnLoad("DoSomething")}
Index ¶
- Constants
- func GetElementID(e Element) string
- func URLParse(s string) *url.URL
- func Walker(ctx context.Context, root Element) chan Walked
- type A
- type AsLink
- type Attribute
- type BR
- type Base
- type Body
- type Button
- type ButtonType
- type Caption
- type Col
- type ColGroup
- type ColGroupElement
- type Component
- type CrossOrigin
- type Direction
- type Div
- type Doc
- type DynamicFunc
- type Element
- type EventType
- type Events
- type FieldSet
- type Form
- type FormElement
- type FormMethod
- type FormRel
- type GearType
- type GlobalAttrs
- type H
- type HTTPEquiv
- type Head
- type I
- type IFrame
- type Img
- type Initer
- type Input
- type InputType
- type Label
- type LanguageCode
- type Legend
- type Level
- type Li
- type Link
- type ListenerType
- type MediaQuery
- type MediaType
- type Meta
- type MetaName
- type Nav
- type OptGroup
- type OptGroupElement
- type Option
- type Output
- type P
- type Pipeline
- type ReferrerPolicy
- type Relationship
- type RelationshipLink
- type Sandbox
- type Sandboxing
- type Script
- type Select
- type SelectElement
- type Sizes
- type Span
- type Style
- type TBody
- type TD
- type TFoot
- type TH
- type THScope
- type THead
- type TR
- type TRElement
- type Table
- type TableElement
- type Target
- type TextArea
- type TextElement
- type Title
- type Ul
- type Walked
- type WrapType
- type YesNo
Constants ¶
const ( BlankTarget = "_blank" ParentTarget = "_parent" SelfTarget = "_self" TopTarget = "_top" )
const ( // LTRDir is Left-to-right text direction. LTRDir = "ltr" // RTLDir Right-to-left text direction. RTLDir = "rtl" // AutoDir Let the browser figure out the text direction, based on the content (only recommended if the text direction is unknown). AutoDir = "auto" )
const EmptyString = ""
EmptyString is returned by all Element.Execute() calls.
Variables ¶
This section is empty.
Functions ¶
func GetElementID ¶
GetElementID will return the Element's GlobalAttr.ID if it has one. Empty string if not. If the Element is a *Gear, Gear.GearID().
Types ¶
type A ¶
type A struct { // Href specifies the URL of the page the link goes to. Href *url.URL // Download specifies that the target will be downloaded when a user clicks on the hyperlink. Download bool `html:"attr"` // HrefLang specifies the language of the linked document. HrefLang LanguageCode // Media specifies what media/device the linked document is optimized for. Media MediaQuery // Ping specifies a space-separated list of URLs to which, when the link is followed, post requests with the body ping will be sent by the browser (in the background). Typically used for tracking. Ping *url.URL // ReferrerPolicy specifies which referrer to send. ReferrerPolicy ReferrerPolicy // Rel specifies the relationship between the current document and the linked document. Rel Relationship // Target specifies where to open the linked document. Target Target // Type specifies the media type of the linked document. Type MediaType GlobalAttrs Elements []Element Events *Events }
A defines a hyperlink, which is used to link from one page to another.
type AsLink ¶
type AsLink string
AsLink is a a value used in the Link As attribute.
const ( AsAudio AsLink = "audio" AsDocument AsLink = "document" AsEmbed AsLink = "embed" AsFetch AsLink = "fetch" AsFont AsLink = "font" AsImage AsLink = "image" AsObject AsLink = "object" AsScript AsLink = "script" AsStyle AsLink = "style" AsTrack AsLink = "track" AsVideo AsLink = "video" AsWorker AsLink = "worker" )
type Attribute ¶
Attribute provides a custom attribute for a user to provide for custom componenets.
type Base ¶
type Base struct { GlobalAttrs // Href specifies the URL for all relative urls in the page. Href *url.URL // Target specifies the default target for all hyperlinks and forms in the page. Target string }
Base represents an HTML script tag.
type Body ¶
type Body struct { GlobalAttrs // Elements are elements contained within the Div. Elements []Element Events *Events // Componenet is used to indicate that this is a snippet of code, not a full document. // As such, the <body></body> tags will suppressed but the content will be rendered. Component bool }
Body represents the HTML body.
type Button ¶
type Button struct { GlobalAttrs Events *Events // AutoFocus specifies that a text area should automatically get focus when the page loads. AutoFocus bool `html:"attr"` // Disabled specifies that a text area should be disabled. Disabled bool `html:"attr"` // Form specifies which form the text area belongs to. Form string // FormAction specifies where to send the form-data when a form is submitted. Only for type="submit". FormAction *url.URL // FormEncType secifies how form-data should be encoded before sending it to a server. Only for type="submit". FormEncType string // FormMethod specifies how to send the form-data (which HTTP method to use). Only for type="submit". FormMethod FormMethod // FormNoValidate specifies that the form-data should not be validated on submission. Only for type="submit". FormNoValidate bool `html:"attr"` // FormTarget specifies where to display the response after submitting the form. Only for type="submit". // Specific constants such as BlankTarget are defined for common target names in this package. FormTarget string // FrameName specifies where to display the response after submitting the form. Only for type="submit". FrameName string // Name specifies a name for the button. Name string // Type specifies the type of button. Type ButtonType // Value specifies an initial value for the button. Value string Elements []Element }
Button implements the HTML button tag.
type ButtonType ¶
type ButtonType string
ButtonType describes the kind of button a button tag is.
const ( ButtonBT ButtonType = "button" ResetBT ButtonType = "reset" SubmitBt ButtonType = "submit" )
type Caption ¶
type Caption struct { GlobalAttrs Events *Events // Element contains the text in the TH tag. Element TextElement }
Caption is a table element for use inside a Table tag.
type Col ¶
type Col struct { GlobalAttrs Events *Events // Span specifies the number of columns a header cell should span. Span int }
Col is a tag that specifies column properties within a ColGroup.
type ColGroup ¶
type ColGroup struct { GlobalAttrs Events *Events // Elements contains the Col tags associated with this ColGroup. Elements []ColGroupElement // Span specifies the number of columns a header cell should span. Span int }
ColGroup is a table tag that specifies one or more columns in a table for formatting. It is a applied to a Table element after caption tags and before THead, TBody and TFoot.
type ColGroupElement ¶
type ColGroupElement interface { Element // contains filtered or unexported methods }
ColGroupElement is a tag that can be included in a ColGroup.
type Component ¶
type Component struct { GlobalAttrs // Attributes are custom attributes to apply to the component. Attributes []Attribute // Gear is the *component.Gear that implements the componenent. The name of that Gear will be both the tag type and // the id of the Gear. Gear GearType // TagValue provides the value inside a reference. This can be another element such as a div, but most commonly // it is not defined. TagValue Element Events *Events }
Component is for providing custom componenets registered through the javascript window.customElements type. Be aware that the .Gear.Name() will override a provided GlobalAttrs value.
type CrossOrigin ¶
type CrossOrigin string
const ( AnnonymousCO CrossOrigin = "anonymous" UseCredentialsCO CrossOrigin = "use-credentials" )
type Direction ¶
type Direction string
Direction specifies the text direction for the content in an element.
type Div ¶
type Div struct { GlobalAttrs // Elements are elements contained within the Div. Elements []Element Events *Events }
Div represents a division tag.
type Doc ¶
type Doc struct { Head *Head Body *Body GlobalAttrs *Events // Pretty says to make the HTML look pretty before outputting. Pretty bool // Componenet is used to indicate that this is a snippet of code, not a full document. // As such, <html> and <head> tags will be suppressed. Component bool // contains filtered or unexported fields }
Doc represents an HTML 5 document.
func (*Doc) Execute ¶
Execute executes the internal templates and writes the output to the io.Writer. This is thread-safe.
func (*Doc) ExecuteAsGear ¶
ExecuteAsGear uses the Pipeline provided instead of creating one internally. This is for internal use only and no guarantees are made on its operation or that it will exist in the future. This is thread-safe.
type DynamicFunc ¶
DynamicFunc is a function that uses dynamic server data to return Elements that will be rendered.
type Element ¶
type Element interface { // Execute outputs the Element's textual representation to Pipeline.W . Execute returns a string, // but that string value MUST always be an empty string. This is a side effect of the Go template // system not allowing a function call unless it provides output or is in a FuncMap. FuncMap // is not usable in this context. Execute(pipe Pipeline) string }
Element represents an object that can render self container HTML 5. Normally this is an HTML5 tag. Users may implement this, but do so at their own risk as we can change the implementation without changing the major version.
func Dynamic ¶
func Dynamic(f DynamicFunc) Element
Dynamic wraps a DynamicFunc so that it implements Element.
type EventType ¶
type EventType string
EventType represents a browser based event like a click, mouseover, etc...
const ( OnAfterPrint EventType = "onafterprint" OnBeforePrint EventType = "onbeforeprint" OnBeforeUnload EventType = "onbeforeunload" OnError EventType = "onerror" OnHashChange EventType = "onhashchange" OnLoad EventType = "onload" OnMessage EventType = "onmessage" OnOffline EventType = "onoffline" OnOnline EventType = "ononline" OnPageHide EventType = "onpagehide" OnPageShow EventType = "onpageshow" OnPopState EventType = "onpopstate" OnResize EventType = "onresize" OnStorage EventType = "onstorage" OnUnload EventType = "onunload" OnBlur EventType = "onblur" OnChange EventType = "onchange" OnContextMenu EventType = "oncontextmenu" OnFocus EventType = "onfocus" OnInput EventType = "oninput" OnInvalid EventType = "oninvalid" OnReset EventType = "onreset" OnSearch EventType = "onsearch" OnSelect EventType = "onselect" OnSubmit EventType = "onsubmit" OnKeyDown EventType = "onkeydown" OnKeyPress EventType = "onkeypress" OnKeyUp EventType = "onkeyup" OnClick EventType = "onclick" OnDblClick EventType = "ondblclick" OnMouseMove EventType = "onmousemove" OnMouseOut EventType = "onmouseout" OnMouseOver EventType = "onmouseover" OnMouseUp EventType = "onmouseup" OnWheel EventType = "onwheel" )
type Events ¶
type Events struct {
// contains filtered or unexported fields
}
Events represents an HTML event that triggers a javascript function. This is not used directly, but accessible via HTML elements. Once used in by an Execute(), the output will always be the same regardless of changes.
func ExtractEvents ¶
ExtractEvents extracts an *Events object from an Element. If there is no Events, this will be nil.
type FieldSet ¶
type FieldSet struct { // Disabled specifies that a text area should be disabled. Disabled bool `html:"attr"` // Form specifies which form the text area belongs to. Form string // Name specifies a name for the button. Name string Elements []Element }
FieldSet is used to group related elements in a form.
type Form ¶
type Form struct { GlobalAttrs Events *Events // Action defines the action to be performed when the form is submitted. // If the action attribute is omitted, the action is set to the current page. Action string // Target attribute specifies if the submitted result will open in a new browser tab, a frame, // or in the current window. The default value is "_self" which means the form will be submitted // in the current window. To make the form result open in a new browser tab, use the value "_blank". // Other legal values are "_parent", "_top", or a name representing the name of an iframe. Target string // Method attribute specifies the HTTP method (GET or POST) to be used when submitting the form data. Method FormMethod // AcceptCharset specifies the charset used in the submitted form (default: the page charset). AcceptCharset string `html:"accept-charset"` // AutoComplete specifies if the browser should autocomplete the form (default: on). AutoComplete bool // Enctype pecifies the encoding of the submitted data (default: is url-encoded). EncType string // NoValidate Specifies that the browser should not validate the form. NoValidate bool `html:"attr"` // Rel specifies the relationship between a linked resource and the current document. Rel FormRel // Elements are elements contained form. Elements []FormElement }
Form represents an HTML form.
type FormElement ¶
type FormElement interface { Element // contains filtered or unexported methods }
FormElement represents an element within an HTML form.
type FormMethod ¶
type FormMethod string
FormMethod is the method the form will use to submit the form's content.
const ( // GetMethod uses the browser's "get" method. GetMethod FormMethod = "get" // PostMethod uses the browser's "post" method. PostMethod FormMethod = "post" )
type FormRel ¶
type FormRel string
FormRel specifies the relationship between a linked resource and the current document in a form.
type GearType ¶
type GearType interface { Element Name() string GearID() string TagType() html.HTMLAttr Execute(pipe Pipeline) string }
GearType is an interface only meant to be implemented by *component.Gear. We cannot use component.Gear because component uses this package (cyclic dependency). We do not want to merge these packages and don't want to migrate the Element type out. So this is used as a stand in. The only valid use for this in client code is for tests, which should always embed GearType. Any other use has no compatibility promise.
type GlobalAttrs ¶
type GlobalAttrs struct { // AccessKey specifies a shortcut key to activate/focus an element. AccessKey string // Class specifies one or more classnames for an element (refers to a class in a style sheet). Class string // ContentEditable specifies whether the content of an element is editable or not. ContentEditable bool // Dir specifies the text direction for the content in an element. Dir Direction // Draggable specifies whether the element is draggable or not. Draggable bool // Hidden specifies that an element is not yet, or is no longer, relevant. Hidden bool `html:"attr"` // ID specifies a unique id for an element. ID string // Lang specifies the language of the element's content. Lang string // SpellCheck specifies whether the element is to have its spelling and grammar checked or not. SpellCheck bool // Style specifies an inline CSS style for an element. Style string // TabIndex specifies the tabbing order of an element. // Note: we treat the index different than the standard. 0 will not be written out as a value. We required you // to have a sane order (it is not sane to have tab order 1, 2, 3, 4, 5, 0). TabIndex int // Title specifies extra information about an element. Title string // Translate specifies extra information about an element. Translate YesNo // XXXWasmUpdated indicates that a DocUpdater has updated the Element this is attached to, but // we have not flushed the changes to the DOM. This field is not a GlobalAttrs for HTML and is only public // so that is may be manipulated via reflection. XXXWasmUpdated bool }
GlobalAttr is global attributes tha can be assigned to various elements.
func (GlobalAttrs) Attr ¶
func (g GlobalAttrs) Attr() template.HTMLAttr
type H ¶
type H struct { GlobalAttrs // Level is the tag's level, 1-6. Level Level // Elements are elements contained within the H tag. Elements []Element Events *Events }
H represents a H1-6 tag.
type Head ¶
type Head struct { GlobalAttrs // Elements are elements contained within the Head. Elements []Element Events *Events }
Head represents an HTML head tag.
type I ¶
type I struct { GlobalAttrs Element TextElement Events *Events }
I defines a part of text in an alternate voice or mood.
type IFrame ¶
type IFrame struct { GlobalAttrs // Name specifies the name of the <iframe>. Name string // Src specifies the address of the document to embed in the <iframe>. Src *url.URL // SrcDoc specifies the HTML content of the page to show in the <iframe>. SrcDoc template.HTMLAttr // Allow specifies a feature policy for the <iframe>. Allow string // Allow if set to true allows activating fullscreen mode by calling the requestFullscreen() method. AllowFullscreen bool // AllowPaymentRequest if set to true if will allow a cross-origin <iframe> to invoke the Payment Request API. AllowPaymentRequest bool // Height specifies the height of an <iframe>. Default height is 150 pixels. Height uint // Width specifies the width of an <iframe>. Default width is 300 pixels. Width uint // ReferrerPolicy specifies how much/which referrer information that will be sent when processing the iframe attributes. ReferrerPolicy ReferrerPolicy // Sandboxing enables an extra set of restrictions for the content in an <iframe>. Sandboxing Sandboxing Events *Events }
IFrame represents a division tag.
type Img ¶
type Img struct { GlobalAttrs Events *Events // Src specifies the path to the image. Src *url.URL // SrcSet specifies the path to an image to use in different situations. SrcSet *url.URL // Alt specifies an alternate text for the image, if the image for some reason cannot be displayed. Alt string // UseMap specifies an image as a client-side image-map. UseMap string // CrossOrigin allows images from third-party sites that allow cross-origin access to be used with canvas CrossOrigin CrossOrigin // HeightPx is the height set in pixels. HeightPx uint `html:"height" suffix:"px"` // HeightEm is the height set in em. HeightEm uint `html:"height" suffix:"em"` // WidthPx is the width set in pixels. WidthPx uint `html:"width" suffix:"px"` // WidthEm is the width set in pixels. WidthEm uint `html:"width" suffix:"em"` // IsMap specifies an image as a server-side image-map. IsMap bool `html:"attr"` // LongDesc specifies a URL to a detailed description of an image. LongDesc *url.URL // ReferrerPolicy specifies which referrer to send. ReferrerPolicy ReferrerPolicy Sizes string }
Img details an image to be shown.
type Initer ¶
type Initer interface { // Init initalizes the internal state. Init() error }
Initer is a type that requires Init() to be called before using.
type Input ¶
type Input struct { GlobalAttrs *Events // Type is the type of input. Type InputType // Name is the name of the input field, this is mandatory. Name string // Value is the value of the input field. Value string }
Input creates a method of input within a form.
type InputType ¶
type InputType string
InputType describes the type of input that is being created within a form.
type Label ¶
type Label struct { GlobalAttrs *Events // For specifies the id of the form element the label should be bound to. For string // Form specifies which form the label belongs to. Form string // Elements are HTML elements that are contained in the Label tag. // Usually a TextElement and sometimes the input tag the Label is for. Elements []Element }
Label element is useful for screen-reader users, because the screen-reader will read out loud the label when the user is focused on the input element.
type Legend ¶
type Legend struct { // Caption is the legend's caption. Caption string }
Legend defines a caption for the FieldSet element.
type Li ¶
type Li struct { GlobalAttrs Events *Events Elements []Element }
Li defines an HTML li tag.
type Link ¶
type Link struct { GlobalAttrs // Href specifies the location of the linked document. Href *url.URL CrossOrigin CrossOrigin // HrefLang specifies the language of the text in the linked document. HrefLang string // Media specifies on what device the linked document will be displayed. Media string ReferrerPolicy ReferrerPolicy // Rel (required) specifies the relationship between the current document and the linked document. Rel RelationshipLink // As is only used when rel="preload" or rel="prefetch" has been set on the <link> element. // It specifies the type of content being loaded by the <link>, which is necessary for request matching, // application of correct content security policy, and setting of correct Accept request header. // Furthermore, rel="preload" uses this as a signal for request prioritization. As AsLink // Sizes specifies the size of the linked resource. Only for rel="icon". Sizes Sizes // Type specifies the media type of the linked document. Type string }
Link defines an HTML link tag.
type ListenerType ¶
type ListenerType string
ListenerType are event types for event listeners (which are different from event handlers).
const ( LTError ListenerType = "error" LTAbort ListenerType = "abort" LTLoad ListenerType = "load" LTBeforeUnload ListenerType = "beforeunload" LTUnload ListenerType = "unload" LTOnline ListenerType = "online" LTOffline ListenerType = "offline" LTFocus ListenerType = "focus" LTBlur ListenerType = "blur" LTFocusIn ListenerType = "focusin" LTFocusOut ListenerType = "focusout" LTOpen ListenerType = "open" LTMessage ListenerType = "message" LTClose ListenerType = "close" LTPageHide ListenerType = "pagehide" LTPageShow ListenerType = "pageshow" LTPopState ListenerType = "popstate" LTAnimationStart ListenerType = "animationstart" LTAnimationCancel ListenerType = "animationcancel" LTAnimationEnd ListenerType = "animationend" LTAnimationIteration ListenerType = "animationiteration" LTTransitionStart ListenerType = "transitionstart" LTTransitionCancel ListenerType = "transitioncancel" LTTransitionEnd ListenerType = "transitionend" LTTransitionRun ListenerType = "transitionrun" LTReset ListenerType = "reset" LTSubmit ListenerType = "submit" LTBeforePrint ListenerType = "beforeprint" LTAfterPrint ListenerType = "afterprint" LTCompositionStart ListenerType = "compositionstart" LTCompositionUpdate ListenerType = "compositionupdate" LTCompositionEnd ListenerType = "compositionend" LTFullScreenChange ListenerType = "fullscreenchange" LTFullScreenError ListenerType = "fullscreenerror" LTResize ListenerType = "resize" LTScroll ListenerType = "scroll" LTCut ListenerType = "cut" LTCopy ListenerType = "copy" LTPaste ListenerType = "paste" LTKeyDown ListenerType = "keydown" LTKeyPress ListenerType = "keypress" LTKeyUp ListenerType = "keyup" LTAuxClick ListenerType = "auxclick" LTClick ListenerType = "click" LTContextMenu ListenerType = "contextmenu" LTDblClick ListenerType = "dblclick" LTMoudDown ListenerType = "mousedown" LTMouseEnter ListenerType = "mouseenter" LTMouseLeave ListenerType = "mouseleave" LTMouseMove ListenerType = "mousemove" LTMouseOver ListenerType = "mouseover" LTMouseOut ListenerType = "mouseout" LTMouseUp ListenerType = "mouseup" LTPointerLockChange ListenerType = "pointerlockchange" LTPointerLockError ListenerType = "pointerlockerror" LTSelect ListenerType = "select" LTWheel ListenerType = "wheel" LTDrag ListenerType = "drag" LTDragEnd ListenerType = "dragend" LTDragEnter ListenerType = "dragenter" LTDragStart ListenerType = "dragstart" LTDragLeave ListenerType = "dragleave" LTDragOver ListenerType = "dragover" LTDrop ListenerType = "drop" LTAudioProcess ListenerType = "audioprocess" LTCanPlay ListenerType = "canplay" LTCanPlayThrough ListenerType = "canplaythrough" LTComplete ListenerType = "complete" LTDurationChange ListenerType = "durationchange" LTEmptied ListenerType = "emptied" LTEnded ListenerType = "ended" LTLoadedData ListenerType = "loadeddata" LTLoadedMetaData ListenerType = "loadedmetadata" LTPause ListenerType = "pause" LTPlay ListenerType = "play" LTPlaying ListenerType = "playing" LTRateChange ListenerType = "ratechange" LTSeeked ListenerType = "seeked" LTSeeking ListenerType = "seeking" LTStalled ListenerType = "stalled" LTSuspend ListenerType = "suspend" LTTimeUpdate ListenerType = "timeupdate" LTVolumeChange ListenerType = "volumechange" LTWaiting ListenerType = "waiting" LTLoadEnd ListenerType = "loadend" LTLoadStart ListenerType = "loadstart" LTProgress ListenerType = "progress" LTTimeout ListenerType = "timeout" LTStorage ListenerType = "storage" LTChecking ListenerType = "checking" LTDownloading ListenerType = "downloading" LTNoUpdate ListenerType = "noupdate" LTObsolete ListenerType = "obsolete" LTUpdateReady ListenerType = "updateready" LTBroadcast ListenerType = "broadcast" LTCheckboxStateChange ListenerType = "CheckboxStateChange" LTHashChange ListenerType = "hashchange" LTInput ListenerType = "input" LTRadioStateChange ListenerType = "radiostatechange" LTReadyStateChange ListenerType = "readystatechange" LTValueChange ListenerType = "valuechange" LTInvalid ListenerType = "invalid" LTShow ListenerType = "show" )
type Meta ¶
type Meta struct { GlobalAttrs // Charset holds the character encoding of the html document. We only support the value UTF-8. Charset string HTTPEquiv HTTPEquiv `html:"http-equiv"` MetaName MetaName // Content specifies the value associated with the http-equiv or name attribute. Content string }
Meta defines an HTML meta tag.
type OptGroup ¶
type OptGroup struct { // Disabled specifies that a text area should be disabled. Disabled bool `html:"attr"` // Lablel specifies a shorter label for an option. Label string Elements []OptGroupElement }
OptGroup is used to group related options in a Select element.
type OptGroupElement ¶
type OptGroupElement interface { Element // contains filtered or unexported methods }
type Option ¶
type Option struct { GlobalAttrs Events *Events // Disabled specifies that a text area should be disabled. Disabled bool `html:"attr"` // Lablel specifies a shorter label for an option. Label string // Selected specifies that an option should be pre-selected when the page loads. Selected bool `html:"attr"` // Value specifies the value to be sent to a server. Value string // TagValue is the text in the option. TagValue string }
Option defines an option in a select list.
type Output ¶
type Output struct { // For specifies the relationship between the result of the calculation, and the elements used in the calculation. For string // Form specifies which form the text area belongs to. Form string // Name specifies a name for the button. Name string }
Output is used to represent the result of a calculation.
type P ¶
type P struct { GlobalAttrs Events *Events Elements []Element // contains filtered or unexported fields }
P tag defines a paragraph.
type Pipeline ¶
type Pipeline struct { // Ctx is the context of the call chain. This should be set by NewPipeline(). Ctx context.Context // Req is the http.Request object for this call. Req *http.Request // W is the output buffer. W io.Writer // Self represents the data structure of the object that is executing the template. This allows // a template to access attributes that represent a tag, such as A{} accessing Href for rendering. // A user should not set this, as it is automatically changed by the various Element implementations. Self interface{} // GearData provides a map of pipeline data keyed by gear name. // TODO(johnsiilver): Might want to have the component package provide its own Pipeline that this // pipeline is embedded in. Then GearData would only belong to that pipelin. GearData has no // affect on anything in this package. GearData interface{} // contains filtered or unexported fields }
Pipeline represents a template pipeline. The Self attribute is only usable internally, any other use is not supported. Component is used only internally by the component pacakge, any other use is not supported. Data is what the user wishes to pass in for their application.
func NewPipeline ¶
NewPipeline creates a new Pipeline object.
type ReferrerPolicy ¶
type ReferrerPolicy string
ReferrerPolicy specifies which referrer to send.
const ( NoReferrer ReferrerPolicy = "no-referrer" NoReferrerWhenDowngrade ReferrerPolicy = "no-referrer-when-downgrade" Origin ReferrerPolicy = "origin" OriginWhenCrossOrigin ReferrerPolicy = "origin-when-cross-origin" UnsafeUrl ReferrerPolicy = "unsafe-url" )
type Relationship ¶
type Relationship string
const ( AlternateRel Relationship = "alternate" AuthorRel Relationship = "author" BookmarkRel Relationship = "bookmark" ExternalRel Relationship = "external" HelpRel Relationship = "help" LicenseRel Relationship = "license" NextRel Relationship = "next" NoFollowRel Relationship = "nofollow" NoReferrerRel Relationship = "noreferrer" NoOpenerRel Relationship = "noopener" PrevRel Relationship = "prev" SearchRel Relationship = "search" TagRel Relationship = "tag" )
type RelationshipLink ¶
type RelationshipLink string
const ( AlternateRL RelationshipLink = "alternate" AuthorRL RelationshipLink = "author" DNSPrefetchRL RelationshipLink = "dns-prefetch" HelpRL RelationshipLink = "help" IconRL RelationshipLink = "icon" LicenseRL RelationshipLink = "license" NextRL RelationshipLink = "next" PingBackRL RelationshipLink = "pingback" PreConnectRL RelationshipLink = "preconnect" PreFetchRL RelationshipLink = "prefetch" PreLoadRL RelationshipLink = "preload" PreRenderRL RelationshipLink = "prerender" PrevRL RelationshipLink = "prev" SearchRL RelationshipLink = "search" StylesheetRL RelationshipLink = "stylesheet" )
type Sandbox ¶
type Sandbox string
Sandbox reprsents the HTML sandbox attribute commonly used on iframes.
type Sandboxing ¶
type Sandboxing []Sandbox
Sandboxing reprsents all the Sandbox attributes to apply.
func (Sandboxing) String ¶
func (s Sandboxing) String() string
type Script ¶
type Script struct { GlobalAttrs // Src specifies the URL of an external script file. Src *url.URL // Type specifies the media type of the script. Type string // Async specifies that the script is executed asynchronously (only for external scripts). Async bool `html:"attr"` // Defer specifies that the script is executed when the page has finished parsing (only for external scripts). Defer bool `html:"attr"` // TagValue holds the value that is between the begin and ending tag. This should be a script of some type. TagValue template.JS }
Script represents an HTML script tag.
type Select ¶
type Select struct { GlobalAttrs Events *Events // AutoFocus specifies that a text area should automatically get focus when the page loads. AutoFocus bool `html:"attr"` // Disabled specifies that a text area should be disabled. Disabled bool `html:"attr"` // Form specifies which form the text area belongs to. Form string // Multiple specifies that multiple options can be selected at once. Multiple bool `html:"attr"` // Name specifies a name for the button. Name string // Required specifies that the user is required to select a value before submitting the form. Required bool `html:"attr"` // Size defines the number of visible options in a drop-down list. Size uint Elements []SelectElement }
type SelectElement ¶
type SelectElement interface { Element // contains filtered or unexported methods }
type Span ¶
type Span struct { GlobalAttrs // Element is any containing element. Elements []Element Events *Events }
Span tag is an inline container used to mark up a part of a text, or a part of a document.
type Style ¶
type Style struct { GlobalAttrs // TagValue provides the value inside a reference. TagValue template.CSS Events *Events }
Style defines an HTML style tag.
type TBody ¶
type TBody struct { GlobalAttrs Events *Events Elements []*TR }
TBody is used to group the body elements in an Table.
type TD ¶
type TD struct { GlobalAttrs Events *Events Element Element // ColSpan specifies the number of columns a header cell should span. ColSpan int // Headers specifies one or more header cells a cell is related to. Headers []string // RowSpan specifies the number of rows a header cell should span. RowSpan int }
TD holds table data inside a TR tag inside a Table tag.
type TFoot ¶
type TFoot struct { GlobalAttrs Events *Events Elements []*TR }
THead is used to group footer content in a table.
type TH ¶
type TH struct { GlobalAttrs Events *Events // Element contains the text in the TH tag. Element TextElement // Abbr specifies an abbreviated version of the content in a header cell. Abbr string // ColSpan specifies the number of columns a header cell should span. ColSpan int // Headers specifies one or more header cells a cell is related to. Headers []string // RowSpan specifies the number of rows a header cell should span. RowSpan int // Scope specifies whether a header cell is a header for a column, row, or group of columns or rows. Scope THScope }
TH is a table header for use inside a Table tag.
type THead ¶
type THead struct { GlobalAttrs Events *Events Elements []*TR }
THead is used to group header content in a table.
type TR ¶
type TR struct { GlobalAttrs Events *Events Elements []TRElement }
TR is a table row for use inside a Table tag.
type TRElement ¶
type TRElement interface { Element // contains filtered or unexported methods }
TRElement is an element that can be included in a TR tag.
type Table ¶
type Table struct { GlobalAttrs // Elements are elements contained within the Table. Elements []TableElement Events *Events }
Table represents a division tag.
type TableElement ¶
type TableElement interface { Element // contains filtered or unexported methods }
TableElement represents a tag that can be contained inside a Table.
type TextArea ¶
type TextArea struct { GlobalAttrs Events *Events // Name specifies a name for a text area. Name string // Form specifies which form the text area belongs to. Form string // Cols specifies the visible width of a text area. Cols int // MaxLength specifies the maximum number of characters allowed in the text area. MaxLength int // Rows specifies the visible number of lines in a text area. Rows int // DirName specifies that the text direction of the textarea will be submitted. DirName string // Wrap specifies how the text in a text area is to be wrapped when submitted in a form. Wrap WrapType // Placeholder specifies a short hint that describes the expected value of a text area. Placeholder string // AutoFocus specifies that a text area should automatically get focus when the page loads. AutoFocus bool `html:"attr"` // Disabled specifies that a text area should be disabled. Disabled bool `html:"attr"` // ReadOnly specifies that a text area should be read-only. ReadOnly bool `html:"attr"` // Required specifies that a text area is required/must be filled out. Required bool `html:"attr"` // Element contains a TextElement that is the content of TextArea. Element TextElement }
TextArea tag defines a multi-line text input control.
type TextElement ¶
type TextElement string
TextElement is an element that represents text, usually in a value. It is not valid everywhere.
func (TextElement) Execute ¶
func (t TextElement) Execute(pipe Pipeline) string
type Title ¶
type Title struct { GlobalAttrs // TagValue provides the value inside a reference. TagValue TextElement }
A defines a hyperlink, which is used to link from one page to another.
type Ul ¶
type Ul struct { GlobalAttrs Events *Events Elements []Element }
Ul defines an HTML ul tag.
type Walked ¶
type Walked struct { // Element is the HTML Element. Element Element // Parent is the HTML Element parent of Element. Parent Element // ShadowPath is the path of component shadowRoots between the Walker "root" and this Element, not including it. ShadowPath []string }
Walked is returned by Walker which walks all Elements from some root.
type WrapType ¶
type WrapType string
WrapType specifies how the text in a textarea is to be wrapped when submitted in a form.
const ( // SoftWrap specifies the text in the textarea is not wrapped when submitted in a form. This is default. SoftWrap WrapType = "soft" // HardWrap specifies the text in the textarea is wrapped (contains newlines) // when submitted in a form. When "hard" is used, the cols attribute must be specified. HardWrap WrapType = "hard" )
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package builder provides a programatic way of building the HTML tree structure in a way that can be more easily read without the documenet structure becoming a right leaning mess, such as: &Doc{ Head: &Head{}, Body: &Body{ Elements: []Element{ &Div{ Elements: []Element{ &Table{ Elements: []TableElement{ &TR{ Elements: []TRElement{ &TD{}, &TD{}, }, }, }, }, }, }, }, }, } With our builder, this becomes b := NewHTML(&Head{}, &Body{}) b.Into(&Div{}) // Adds the div and moves into the div b.Into(&Table{}) // Adds the table and moves into the table b.Into(&TR{}) // Adds the table row and moves into the table row b.Add(&TD{}, &TD{}) // Adds two table role elements, but stays in the row.
|
Package builder provides a programatic way of building the HTML tree structure in a way that can be more easily read without the documenet structure becoming a right leaning mess, such as: &Doc{ Head: &Head{}, Body: &Body{ Elements: []Element{ &Div{ Elements: []Element{ &Table{ Elements: []TableElement{ &TR{ Elements: []TRElement{ &TD{}, &TD{}, }, }, }, }, }, }, }, }, } With our builder, this becomes b := NewHTML(&Head{}, &Body{}) b.Into(&Div{}) // Adds the div and moves into the div b.Into(&Table{}) // Adds the table and moves into the table b.Into(&TR{}) // Adds the table row and moves into the table row b.Add(&TD{}, &TD{}) // Adds two table role elements, but stays in the row. |
examples
|
|