Documentation ¶
Index ¶
- Variables
- func EmptyNodes(nodes []Node) bool
- func IsHeader(t NodeType) bool
- func IsInline(t NodeType) bool
- func IsItemsList(t NodeType) bool
- type ButtonNode
- type CodeNode
- type GridCell
- type GridNode
- type HeaderNode
- type IframeNode
- type ImageNode
- type ImportNode
- type InfoboxKind
- type InfoboxNode
- type ItemsListNode
- func (b *ItemsListNode) Block() interface{}
- func (il *ItemsListNode) Empty() bool
- func (b *ItemsListNode) Env() []string
- func (b *ItemsListNode) MutateBlock(v interface{})
- func (b *ItemsListNode) MutateEnv(e []string)
- func (il *ItemsListNode) MutateType(t NodeType)
- func (il *ItemsListNode) NewItem(nodes ...Node) *ListNode
- func (b *ItemsListNode) Type() NodeType
- type ListNode
- func (l *ListNode) Append(n ...Node)
- func (b *ListNode) Block() interface{}
- func (l *ListNode) Empty() bool
- func (b *ListNode) Env() []string
- func (b *ListNode) MutateBlock(v interface{})
- func (b *ListNode) MutateEnv(e []string)
- func (b *ListNode) MutateType(t NodeType)
- func (b *ListNode) Type() NodeType
- type NewImageNodeOptions
- type NewTextNodeOptions
- type Node
- type NodeType
- type SurveyGroup
- type SurveyNode
- type TextNode
- type URLNode
- type YouTubeNode
Constants ¶
This section is empty.
Variables ¶
var IframeAllowlist = []string{
"carto.com",
"codepen.io",
"dartlang.org",
"dartpad.dev",
"demo.arcade.software",
"github.com",
"glitch.com",
"google.com",
"google.dev",
"observablehq.com",
"repl.it",
"stackblitz.com",
"vimeo.com",
"web.dev",
}
iframe allowlist - set of domains allow to embed iframes in a codelab. TODO make this configurable somehow
Functions ¶
func EmptyNodes ¶
EmptyNodes returns true if all of nodes are empty.
func IsItemsList ¶
IsItemsList returns true if t is one of ItemsListNode types.
Types ¶
type ButtonNode ¶
type ButtonNode struct { Raise bool Color bool Download bool Content *ListNode // contains filtered or unexported fields }
ButtonNode represents a button, e.g. "Download Zip".
func NewButtonNode ¶
func NewButtonNode(raise, color, download bool, n ...Node) *ButtonNode
TODO this is a long arg signature. Maybe use an options type? NewButtonNode creates a new button with optional content nodes n.
func (*ButtonNode) Empty ¶
func (bn *ButtonNode) Empty() bool
Empty returns true if its content is empty.
func (*ButtonNode) MutateBlock ¶
func (b *ButtonNode) MutateBlock(v interface{})
func (*ButtonNode) MutateType ¶
func (b *ButtonNode) MutateType(t NodeType)
Default implementation is a no op.
type CodeNode ¶
type CodeNode struct { Term bool Lang string Value string // contains filtered or unexported fields }
CodeNode is either a source code snippet or a terminal output. TODO is there any room to consolidate Term and Lang?
func NewCodeNode ¶
NewCodeNode creates a new Node of type NodeCode. Use term argument to specify a terminal output.
func (*CodeNode) MutateBlock ¶
func (b *CodeNode) MutateBlock(v interface{})
func (*CodeNode) MutateType ¶
func (b *CodeNode) MutateType(t NodeType)
Default implementation is a no op.
type GridNode ¶
type GridNode struct { Rows [][]*GridCell // contains filtered or unexported fields }
TODO define a convenience type for row GridNode is a 2d matrix.
func NewGridNode ¶
NewGridNode creates a new grid with optional content.
func (*GridNode) MutateBlock ¶
func (b *GridNode) MutateBlock(v interface{})
func (*GridNode) MutateType ¶
func (b *GridNode) MutateType(t NodeType)
Default implementation is a no op.
type HeaderNode ¶
HeaderNode is any regular header, a checklist header, or an FAQ header.
func NewHeaderNode ¶
func NewHeaderNode(level int, n ...Node) *HeaderNode
NewHeaderNode creates a new HeaderNode with optional content nodes n.
func (*HeaderNode) Empty ¶
func (hn *HeaderNode) Empty() bool
Empty returns true if header content is empty.
func (*HeaderNode) MutateBlock ¶
func (b *HeaderNode) MutateBlock(v interface{})
func (*HeaderNode) MutateType ¶
func (hn *HeaderNode) MutateType(t NodeType)
MutateType sets the header's node type if the given type is a header type.
type IframeNode ¶
type IframeNode struct { URL string // contains filtered or unexported fields }
IframeNode is an embeddes iframe.
func NewIframeNode ¶
func NewIframeNode(url string) *IframeNode
NewIframeNode creates a new embedded iframe.
func (*IframeNode) Empty ¶
func (iframe *IframeNode) Empty() bool
Empty returns true if iframe's URL field is empty.
func (*IframeNode) MutateBlock ¶
func (b *IframeNode) MutateBlock(v interface{})
func (*IframeNode) MutateType ¶
func (b *IframeNode) MutateType(t NodeType)
Default implementation is a no op.
type ImageNode ¶
type ImageNode struct { Src string Width float32 Alt string Title string Bytes []byte // contains filtered or unexported fields }
ImageNode represents a single image.
func ImageNodes ¶
ImageNodes extracts everything except NodeImage nodes, recursively. TODO rename
func NewImageNode ¶
func NewImageNode(opts NewImageNodeOptions) *ImageNode
NewImageNode creates a new ImageNode with the given options. TODO this API is inconsistent with button
func (*ImageNode) MutateBlock ¶
func (b *ImageNode) MutateBlock(v interface{})
func (*ImageNode) MutateType ¶
func (b *ImageNode) MutateType(t NodeType)
Default implementation is a no op.
type ImportNode ¶
ImportNode indicates a remote resource available at ImportNode.URL.
func ImportNodes ¶
func ImportNodes(nodes []Node) []*ImportNode
ImportNodes extracts everything except NodeImport nodes, recursively.
func NewImportNode ¶
func NewImportNode(url string) *ImportNode
NewImportNode creates a new Node of type NodeImport, with initialized ImportNode.Content.
func (*ImportNode) Empty ¶
func (in *ImportNode) Empty() bool
Empty returns the result of in.Content.Empty method.
func (*ImportNode) MutateBlock ¶
func (in *ImportNode) MutateBlock(v interface{})
MutateBlock mutates both in's block marker and that of in.Content.
func (*ImportNode) MutateType ¶
func (b *ImportNode) MutateType(t NodeType)
Default implementation is a no op.
type InfoboxKind ¶
type InfoboxKind string
InfoboxKind defines kind type for InfoboxNode.
const ( InfoboxPositive InfoboxKind = "special" InfoboxNegative InfoboxKind = "warning" )
InfoboxNode variants.
type InfoboxNode ¶
type InfoboxNode struct { Kind InfoboxKind Content *ListNode // contains filtered or unexported fields }
InfoboxNode is any regular header, a checklist header, or an FAQ header.
func NewInfoboxNode ¶
func NewInfoboxNode(k InfoboxKind, n ...Node) *InfoboxNode
NewInfoboxNode creates a new infobox node with specified kind and optional content.
func (*InfoboxNode) Empty ¶
func (ib *InfoboxNode) Empty() bool
Empty returns true if ib content is empty.
func (*InfoboxNode) MutateBlock ¶
func (b *InfoboxNode) MutateBlock(v interface{})
func (*InfoboxNode) MutateType ¶
func (b *InfoboxNode) MutateType(t NodeType)
Default implementation is a no op.
type ItemsListNode ¶
type ItemsListNode struct { ListType string Start int Items []*ListNode // contains filtered or unexported fields }
ItemsListNode containts sets of ListNode. Non-zero ListType indicates an ordered list.
func NewItemsListNode ¶
func NewItemsListNode(typ string, start int) *ItemsListNode
NewItemsListNode creates a new ItemsListNode of type NodeItemsList, which defaults to an unordered list. Provide a positive start to make this a numbered list. NodeItemsCheck and NodeItemsFAQ are always unnumbered.
func (*ItemsListNode) Empty ¶
func (il *ItemsListNode) Empty() bool
Empty returns true if every item has empty content.
func (*ItemsListNode) MutateBlock ¶
func (b *ItemsListNode) MutateBlock(v interface{})
func (*ItemsListNode) MutateType ¶
func (il *ItemsListNode) MutateType(t NodeType)
MutateType sets the items list's node type if the given type is an items list type.
func (*ItemsListNode) NewItem ¶
func (il *ItemsListNode) NewItem(nodes ...Node) *ListNode
NewItem creates a new ListNode and adds it to il.Items.
type ListNode ¶
type ListNode struct { Nodes []Node // contains filtered or unexported fields }
ListNode contains other nodes.
func NewListNode ¶
NewListNode creates a new Node of type NodeList.
func (*ListNode) MutateBlock ¶
func (b *ListNode) MutateBlock(v interface{})
func (*ListNode) MutateType ¶
func (b *ListNode) MutateType(t NodeType)
Default implementation is a no op.
type NewImageNodeOptions ¶
type NewTextNodeOptions ¶
type Node ¶
type Node interface { // Type returns node type. Type() NodeType // MutateType changes node type where possible. // Only changes within this same category are allowed. // For instance, items list or header nodes can change their types // to another kind of items list or header. MutateType(NodeType) // Block returns a source reference of the node. Block() interface{} // MutateBlock updates source reference of the node. MutateBlock(interface{}) // Empty returns true if the node has no content. Empty() bool // Env returns node environment Env() []string // MutateEnv replaces current node environment tags with env. MutateEnv(env []string) }
Node is an interface common to all node types.
type NodeType ¶
type NodeType uint32
NodeType is type for parsed codelab nodes tree.
const ( NodeInvalid NodeType = 1 << iota NodeList // A node which contains a list of other nodes NodeGrid // Table NodeText // Simple node with a string as the value NodeCode // Source code or console (terminal) output NodeInfobox // An aside box for notes or warnings NodeSurvey // Sets of grouped questions NodeURL // Represents elements such as <a href="..."> NodeImage // Image NodeButton // Button NodeItemsList // Set of NodeList items NodeItemsCheck // Special kind of NodeItemsList, checklist NodeItemsFAQ // Special kind of NodeItemsList, FAQ NodeHeader // A header text node NodeHeaderCheck // Special kind of header, checklist NodeHeaderFAQ // Special kind of header, FAQ NodeYouTube // YouTube video NodeIframe // Embedded iframe NodeImport // A node which holds content imported from another resource )
Codelab node kinds.
type SurveyGroup ¶
SurveyGroup contains group name/question and possible answers.
type SurveyNode ¶
type SurveyNode struct { ID string Groups []*SurveyGroup // contains filtered or unexported fields }
SurveyNode contains groups of questions. Each group name is the Survey key.
func NewSurveyNode ¶
func NewSurveyNode(id string, groups ...*SurveyGroup) *SurveyNode
NewSurveyNode creates a new survey node with optional questions. If survey is nil, a new empty map will be created. TODO is "map" above a mistake, or should the code below contain a map?
func (*SurveyNode) Empty ¶
func (sn *SurveyNode) Empty() bool
Empty returns true if each group has 0 options.
func (*SurveyNode) MutateBlock ¶
func (b *SurveyNode) MutateBlock(v interface{})
func (*SurveyNode) MutateType ¶
func (b *SurveyNode) MutateType(t NodeType)
Default implementation is a no op.
type TextNode ¶
type TextNode struct { Bold bool Italic bool Code bool Value string // contains filtered or unexported fields }
TextNode is a simple node containing text as a string value.
func NewTextNode ¶
func NewTextNode(opts NewTextNodeOptions) *TextNode
NewTextNode creates a new Node of type NodeText.
func (*TextNode) MutateBlock ¶
func (b *TextNode) MutateBlock(v interface{})
func (*TextNode) MutateType ¶
func (b *TextNode) MutateType(t NodeType)
Default implementation is a no op.
type URLNode ¶
type URLNode struct { URL string Name string Target string Content *ListNode // contains filtered or unexported fields }
URLNode represents elements such as <a href="...">
func NewURLNode ¶
NewURLNode creates a new Node of type NodeURL with optional content n.
func (*URLNode) MutateBlock ¶
func (b *URLNode) MutateBlock(v interface{})
func (*URLNode) MutateType ¶
func (b *URLNode) MutateType(t NodeType)
Default implementation is a no op.
type YouTubeNode ¶
type YouTubeNode struct { VideoID string // contains filtered or unexported fields }
YouTubeNode is a YouTube video.
func NewYouTubeNode ¶
func NewYouTubeNode(vid string) *YouTubeNode
NewYouTubeNode creates a new YouTube video node.
func (*YouTubeNode) Empty ¶
func (yt *YouTubeNode) Empty() bool
Empty returns true if yt's VideoID field is zero.
func (*YouTubeNode) MutateBlock ¶
func (b *YouTubeNode) MutateBlock(v interface{})
func (*YouTubeNode) MutateType ¶
func (b *YouTubeNode) MutateType(t NodeType)
Default implementation is a no op.