types

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2019 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package types provide types for format-independent codelab data model.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EmptyNodes

func EmptyNodes(nodes []Node) bool

EmptyNodes returns true if all of nodes are empty.

func IsHeader

func IsHeader(t NodeType) bool

IsHeader returns true if t is one of header types.

func IsInline

func IsInline(t NodeType) bool

IsInline returns true if t is an inline node type.

func IsItemsList

func IsItemsList(t NodeType) bool

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) Block

func (b *ButtonNode) Block() interface{}

func (*ButtonNode) Empty

func (bn *ButtonNode) Empty() bool

Empty returns true if its content is empty.

func (*ButtonNode) Env

func (b *ButtonNode) Env() []string

func (*ButtonNode) MutateBlock

func (b *ButtonNode) MutateBlock(v interface{})

func (*ButtonNode) MutateEnv

func (b *ButtonNode) MutateEnv(e []string)

func (*ButtonNode) MutateType

func (b *ButtonNode) MutateType(t NodeType)

func (*ButtonNode) Type

func (b *ButtonNode) Type() 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

func NewCodeNode(v string, term bool) *CodeNode

NewCodeNode creates a new Node of type NodeCode. Use term argument to specify a terminal output.

func (*CodeNode) Block

func (b *CodeNode) Block() interface{}

func (*CodeNode) Empty

func (cn *CodeNode) Empty() bool

Empty returns true if cn.Value is zero, exluding space runes.

func (*CodeNode) Env

func (b *CodeNode) Env() []string

func (*CodeNode) MutateBlock

func (b *CodeNode) MutateBlock(v interface{})

func (*CodeNode) MutateEnv

func (b *CodeNode) MutateEnv(e []string)

func (*CodeNode) MutateType

func (b *CodeNode) MutateType(t NodeType)

func (*CodeNode) Type

func (b *CodeNode) Type() NodeType

type Codelab

type Codelab struct {
	Meta
	Steps []*Step
}

Codelab is a top-level structure containing metadata and codelab steps.

func (*Codelab) NewStep

func (c *Codelab) NewStep(title string) *Step

NewStep creates a new codelab step, adding it to c.Steps slice.

type Context

type Context struct {
	Env     string       `json:"environment"`       // Current export environment
	Source  string       `json:"source"`            // Codelab source doc
	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

type ContextMeta struct {
	Context
	Meta
}

ContextMeta is a composition of export context and meta data.

type ContextTime

type ContextTime time.Time

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 GridCell

type GridCell struct {
	Colspan int
	Rowspan int
	Content *ListNode
}

GridCell is a cell of GridNode.

type GridNode

type GridNode struct {
	Rows [][]*GridCell
	// contains filtered or unexported fields
}

GridNode is a 2d matrix.

func NewGridNode

func NewGridNode(rows ...[]*GridCell) *GridNode

NewGridNode creates a new grid with optional content.

func (*GridNode) Block

func (b *GridNode) Block() interface{}

func (*GridNode) Empty

func (gn *GridNode) Empty() bool

Empty returns true when every cell has empty content.

func (*GridNode) Env

func (b *GridNode) Env() []string

func (*GridNode) MutateBlock

func (b *GridNode) MutateBlock(v interface{})

func (*GridNode) MutateEnv

func (b *GridNode) MutateEnv(e []string)

func (*GridNode) MutateType

func (b *GridNode) MutateType(t NodeType)

func (*GridNode) Type

func (b *GridNode) Type() NodeType

type HeaderNode

type HeaderNode struct {
	Level   int
	Content *ListNode
	// contains filtered or unexported fields
}

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) Block

func (b *HeaderNode) Block() interface{}

func (*HeaderNode) Empty

func (hn *HeaderNode) Empty() bool

Empty returns true if header content is empty.

func (*HeaderNode) Env

func (b *HeaderNode) Env() []string

func (*HeaderNode) MutateBlock

func (b *HeaderNode) MutateBlock(v interface{})

func (*HeaderNode) MutateEnv

func (b *HeaderNode) MutateEnv(e []string)

func (*HeaderNode) MutateType

func (b *HeaderNode) MutateType(t NodeType)

func (*HeaderNode) Type

func (b *HeaderNode) Type() NodeType

type ImageNode

type ImageNode struct {
	Src      string
	MaxWidth float32
	Alt      string
	Title    string
	// contains filtered or unexported fields
}

ImageNode represents a single image.

func NewImageNode

func NewImageNode(src string) *ImageNode

NewImageNode creates a new ImageNode with the give src.

func (*ImageNode) Block

func (b *ImageNode) Block() interface{}

func (*ImageNode) Empty

func (in *ImageNode) Empty() bool

Empty returns true if its Src is zero, excluding space runes.

func (*ImageNode) Env

func (b *ImageNode) Env() []string

func (*ImageNode) MutateBlock

func (b *ImageNode) MutateBlock(v interface{})

func (*ImageNode) MutateEnv

func (b *ImageNode) MutateEnv(e []string)

func (*ImageNode) MutateType

func (b *ImageNode) MutateType(t NodeType)

func (*ImageNode) Type

func (b *ImageNode) Type() NodeType

type ImportNode added in v0.3.0

type ImportNode struct {
	URL     string
	Content *ListNode
	// contains filtered or unexported fields
}

ImportNode indicates a remote resource available at ImportNode.URL.

func NewImportNode added in v0.3.0

func NewImportNode(url string) *ImportNode

NewImportNode creates a new Node of type NodeImport, with initialized ImportNode.Content.

func (*ImportNode) Block added in v0.3.0

func (b *ImportNode) Block() interface{}

func (*ImportNode) Empty added in v0.3.0

func (in *ImportNode) Empty() bool

Empty returns the result of in.Content.Empty method.

func (*ImportNode) Env added in v0.3.0

func (b *ImportNode) Env() []string

func (*ImportNode) MutateBlock added in v0.3.0

func (in *ImportNode) MutateBlock(v interface{})

MutateBlock mutates both in's block marker and that of in.Content.

func (*ImportNode) MutateEnv added in v0.3.0

func (b *ImportNode) MutateEnv(e []string)

func (*ImportNode) MutateType added in v0.3.0

func (b *ImportNode) MutateType(t NodeType)

func (*ImportNode) Type added in v0.3.0

func (b *ImportNode) Type() 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) Block

func (b *InfoboxNode) Block() interface{}

func (*InfoboxNode) Empty

func (ib *InfoboxNode) Empty() bool

Empty returns true if ib content is empty.

func (*InfoboxNode) Env

func (b *InfoboxNode) Env() []string

func (*InfoboxNode) MutateBlock

func (b *InfoboxNode) MutateBlock(v interface{})

func (*InfoboxNode) MutateEnv

func (b *InfoboxNode) MutateEnv(e []string)

func (*InfoboxNode) MutateType

func (b *InfoboxNode) MutateType(t NodeType)

func (*InfoboxNode) Type

func (b *InfoboxNode) Type() 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) Block

func (b *ItemsListNode) Block() interface{}

func (*ItemsListNode) Empty

func (il *ItemsListNode) Empty() bool

Empty returns true if every item has empty content.

func (*ItemsListNode) Env

func (b *ItemsListNode) Env() []string

func (*ItemsListNode) MutateBlock

func (b *ItemsListNode) MutateBlock(v interface{})

func (*ItemsListNode) MutateEnv

func (b *ItemsListNode) MutateEnv(e []string)

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.

func (*ItemsListNode) Type

func (b *ItemsListNode) Type() NodeType

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 added in v1.1.0

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

func NewListNode(nodes ...Node) *ListNode

NewListNode creates a new Node of type NodeList.

func (*ListNode) Append

func (l *ListNode) Append(n ...Node)

Append appends nodes n to the end of l.Nodes slice.

func (*ListNode) Block

func (b *ListNode) Block() interface{}

func (*ListNode) Empty

func (l *ListNode) Empty() bool

Empty returns true if all l.Nodes are empty.

func (*ListNode) Env

func (b *ListNode) Env() []string

func (*ListNode) MutateBlock

func (b *ListNode) MutateBlock(v interface{})

func (*ListNode) MutateEnv

func (b *ListNode) MutateEnv(e []string)

func (*ListNode) MutateType

func (b *ListNode) MutateType(t NodeType)

func (*ListNode) Prepend

func (l *ListNode) Prepend(n ...Node)

Prepend prepends nodes n at the beginning of l.Nodes slice.

func (*ListNode) Type

func (b *ListNode) Type() 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
	Author     string        `json:"author,omitempty"`   // Arbitrary authorship text
	Summary    string        `json:"summary"`            // Short summary
	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

	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
	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

type SurveyGroup struct {
	Name    string
	Options []string
}

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) Block

func (b *SurveyNode) Block() interface{}

func (*SurveyNode) Empty

func (sn *SurveyNode) Empty() bool

Empty returns true if each group has 0 options.

func (*SurveyNode) Env

func (b *SurveyNode) Env() []string

func (*SurveyNode) MutateBlock

func (b *SurveyNode) MutateBlock(v interface{})

func (*SurveyNode) MutateEnv

func (b *SurveyNode) MutateEnv(e []string)

func (*SurveyNode) MutateType

func (b *SurveyNode) MutateType(t NodeType)

func (*SurveyNode) Type

func (b *SurveyNode) Type() 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

func NewTextNode(v string) *TextNode

NewTextNode creates a new Node of type NodeText.

func (*TextNode) Block

func (b *TextNode) Block() interface{}

func (*TextNode) Empty

func (tn *TextNode) Empty() bool

Empty returns true if tn.Value is zero, excluding space runes.

func (*TextNode) Env

func (b *TextNode) Env() []string

func (*TextNode) MutateBlock

func (b *TextNode) MutateBlock(v interface{})

func (*TextNode) MutateEnv

func (b *TextNode) MutateEnv(e []string)

func (*TextNode) MutateType

func (b *TextNode) MutateType(t NodeType)

func (*TextNode) Type

func (b *TextNode) Type() 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

func NewURLNode(url string, n ...Node) *URLNode

NewURLNode creates a new Node of type NodeURL with optinal content n.

func (*URLNode) Block

func (b *URLNode) Block() interface{}

func (*URLNode) Empty

func (un *URLNode) Empty() bool

Empty returns true if un content is empty.

func (*URLNode) Env

func (b *URLNode) Env() []string

func (*URLNode) MutateBlock

func (b *URLNode) MutateBlock(v interface{})

func (*URLNode) MutateEnv

func (b *URLNode) MutateEnv(e []string)

func (*URLNode) MutateType

func (b *URLNode) MutateType(t NodeType)

func (*URLNode) Type

func (b *URLNode) Type() NodeType

type YouTubeNode added in v0.2.0

type YouTubeNode struct {
	VideoID string
	// contains filtered or unexported fields
}

YouTubeNode is a YouTube video.

func NewYouTubeNode added in v0.2.0

func NewYouTubeNode(vid string) *YouTubeNode

NewYouTubeNode creates a new YouTube video node.

func (*YouTubeNode) Block added in v0.2.0

func (b *YouTubeNode) Block() interface{}

func (*YouTubeNode) Empty added in v0.2.0

func (yt *YouTubeNode) Empty() bool

Empty returns true if yt's VideoID field is zero.

func (*YouTubeNode) Env added in v0.2.0

func (b *YouTubeNode) Env() []string

func (*YouTubeNode) MutateBlock added in v0.2.0

func (b *YouTubeNode) MutateBlock(v interface{})

func (*YouTubeNode) MutateEnv added in v0.2.0

func (b *YouTubeNode) MutateEnv(e []string)

func (*YouTubeNode) MutateType added in v0.2.0

func (b *YouTubeNode) MutateType(t NodeType)

func (*YouTubeNode) Type added in v0.2.0

func (b *YouTubeNode) Type() NodeType

Jump to

Keyboard shortcuts

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