Documentation ¶
Overview ¶
Package types provide types for format-independent codelab data model.
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 Codelab
- type Context
- type ContextMeta
- type ContextTime
- 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 (b *ItemsListNode) MutateType(t NodeType)
- func (il *ItemsListNode) NewItem(nodes ...Node) *ListNode
- func (b *ItemsListNode) Type() NodeType
- type LegacyStatus
- 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 (l *ListNode) Prepend(n ...Node)
- func (b *ListNode) Type() NodeType
- type Meta
- type Node
- type NodeType
- type Step
- type SurveyGroup
- type SurveyNode
- type TextNode
- type URLNode
- type YouTubeNode
Constants ¶
This section is empty.
Variables ¶
var IframeWhitelist = []string{
"google.com",
"google.dev",
"dartlang.org",
"web.dev",
"observablehq.com",
"repl.it",
"codepen.io",
"glitch.com",
"carto.com",
"github.com",
}
iframe whitelist - set of domains allow to embed iframes in a codelab.
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 { Raised bool Colored bool Download bool Content *ListNode // contains filtered or unexported fields }
ButtonNode represents a button, e.g. "Download Zip".
func NewButtonNode ¶
func NewButtonNode(raised, colored, download bool, n ...Node) *ButtonNode
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)
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.
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)
type Codelab ¶
Codelab is a top-level structure containing metadata and codelab steps.
func NewCodelab ¶
func NewCodelab() *Codelab
type Context ¶
type Context struct { Env string `json:"environment"` // Current export environment Format string `json:"format"` // Output format, e.g. "html" Prefix string `json:"prefix,omitempty"` // Assets URL prefix for HTML-based formats MainGA string `json:"mainga,omitempty"` // Global Google Analytics ID Updated *ContextTime `json:"updated,omitempty"` // Last update timestamp }
Context is an export context. It is defined in this package so that it can be used by both cli and a server.
type ContextMeta ¶
ContextMeta is a composition of export context and meta data.
type ContextTime ¶
ContextTime is codelab metadata timestamp. It can be of "YYYY-MM-DD" or RFC3339 formats but marshaling always uses RFC3339 format.
func (ContextTime) MarshalJSON ¶
func (ct ContextTime) MarshalJSON() ([]byte, error)
MarshalJSON implements Marshaler interface.
func (*ContextTime) UnmarshalJSON ¶
func (ct *ContextTime) UnmarshalJSON(b []byte) error
UnmarshalJSON implements Unmarshaler interface. Accepted format is "YYYY-MM-DD" or RFC3339.
type GridNode ¶
type GridNode struct { Rows [][]*GridCell // contains filtered or unexported fields }
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)
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 (b *HeaderNode) MutateType(t NodeType)
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)
type ImageNode ¶
type ImageNode struct { Src string Width float32 Alt string Title string // contains filtered or unexported fields }
ImageNode represents a single image.
func ImageNodes ¶
ImageNodes extracts everything except NodeImage nodes, recursively.
func NewImageNode ¶
NewImageNode creates a new ImageNode with the give src.
func (*ImageNode) MutateBlock ¶
func (b *ImageNode) MutateBlock(v interface{})
func (*ImageNode) MutateType ¶
func (b *ImageNode) MutateType(t NodeType)
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)
type InfoboxKind ¶
type InfoboxKind string
InfoboxKind defines kind type for InfoboxNode.
const ( InfoboxPositive InfoboxKind = "special" InfoboxNegative InfoboxKind = "warning" )
InfoboxNode variations.
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)
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 (b *ItemsListNode) MutateType(t NodeType)
func (*ItemsListNode) NewItem ¶
func (il *ItemsListNode) NewItem(nodes ...Node) *ListNode
NewItem creates a new ListNode and adds it to il.Items.
type LegacyStatus ¶
type LegacyStatus []string
LegacyStatus supports legacy status values which are strings as opposed to an array, e.g. "['one', u'two', ...]".
func (LegacyStatus) MarshalJSON ¶
func (s LegacyStatus) MarshalJSON() ([]byte, error)
MarshalJSON implements Marshaler interface.
func (LegacyStatus) String ¶
func (s LegacyStatus) String() string
String turns a status into a string
func (*LegacyStatus) UnmarshalJSON ¶
func (s *LegacyStatus) UnmarshalJSON(b []byte) error
UnmarshalJSON implements Unmarshaler interface.
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)
type Meta ¶
type Meta struct { ID string `json:"id"` // ID is also part of codelab URL Duration int `json:"duration"` // Codelab duration in minutes Title string `json:"title"` // Codelab title Authors string `json:"authors,omitempty"` // Arbitrary authorship text BadgePath string `json:"badge_path,omitempty"` // Path of the Badge to grant on codelab completion on devsite Summary string `json:"summary"` // Short summary Source string `json:"source"` // Codelab source doc Theme string `json:"theme"` // Usually first item of Categories Status *LegacyStatus `json:"status"` // Draft, Published, Hidden, etc. Categories []string `json:"category"` // Categories from the meta table Tags []string `json:"tags"` // All environments supported by the codelab Feedback string `json:"feedback,omitempty"` // Issues and bugs are sent here GA string `json:"ga,omitempty"` // Codelab-specific GA tracking ID Extra map[string]string `json:"extra,omitempty"` // Extra metadata specified in pass_metadata URL string `json:"url"` // Legacy ID; TODO: remove }
Meta contains a single codelab metadata.
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 Step ¶
type Step struct { Title string // Step title Tags []string // Step environments Duration time.Duration // Duration Content *ListNode // Root node of the step nodes tree }
Step is a single codelab step, containing metadata and actual content.
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.
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)
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 ¶
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)
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 optinal content n.
func (*URLNode) MutateBlock ¶
func (b *URLNode) MutateBlock(v interface{})
func (*URLNode) MutateType ¶
func (b *URLNode) MutateType(t NodeType)
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)