prototype

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: May 31, 2018 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultAPIVersion = "0.0.1"
)

Variables

View Source
var (
	// DefaultBuilder is a builder that will build a prototype from a source string.
	DefaultBuilder = JsonnetParse
)

Functions

This section is empty.

Types

type Builder added in v0.11.0

type Builder func(source string) (*Prototype, error)

PrototypeBuilder builds a prototype from a source string.

type Index

type Index interface {
	List() (Prototypes, error)
	SearchNames(query string, opts SearchOptions) (Prototypes, error)
}

Index represents a queryable index of prototype specifications.

func NewIndex

func NewIndex(prototypes []*Prototype, builder Builder) (Index, error)

NewIndex constructs an index of prototype specifications from a list.

type ParamSchema

type ParamSchema struct {
	Name        string    `json:"name"`
	Alias       *string   `json:"alias"` // Optional.
	Description string    `json:"description"`
	Default     *string   `json:"default"` // `nil` only if the parameter is optional.
	Type        ParamType `json:"type"`
}

ParamSchema is the JSON-serializable representation of a parameter provided to a prototype.

func (*ParamSchema) Quote

func (ps *ParamSchema) Quote(value string) (string, error)

Quote will parse a prototype parameter and quote it appropriately, so that it shows up correctly in Jsonnet source code. For example, `--image nginx` would likely need to show up as `"nginx"` in Jsonnet source.

type ParamSchemas

type ParamSchemas []*ParamSchema

ParamSchemas is a slice of `ParamSchema`

func (ParamSchemas) PrettyString

func (ps ParamSchemas) PrettyString(prefix string) string

PrettyString creates a prettified string representing a collection of parameters.

type ParamType

type ParamType string

ParamType represents a type constraint for a prototype parameter (e.g., it must be a number).

const (
	// Number represents a prototype parameter that must be a number.
	Number ParamType = "number"

	// String represents a prototype parameter that must be a string.
	String ParamType = "string"

	// NumberOrString represents a prototype parameter that must be either a
	// number or a string.
	NumberOrString ParamType = "numberOrString"

	// Object represents a prototype parameter that must be an object.
	Object ParamType = "object"

	// Array represents a prototype parameter that must be a array.
	Array ParamType = "array"
)

func (ParamType) String

func (pt ParamType) String() string

type Prototype added in v0.11.0

type Prototype struct {
	APIVersion string `json:"apiVersion"`
	Kind       string `json:"kind"`

	// Unique identifier of the mixin library. The most reliable way to make a
	// name unique is to embed a domain you own into the name, as is commonly done
	// in the Java community.
	Name     string        `json:"name"`
	Params   ParamSchemas  `json:"params"`
	Template SnippetSchema `json:"template"`
}

Prototype is the JSON-serializable representation of a prototype specification.

func JsonnetParse added in v0.11.0

func JsonnetParse(src string) (*Prototype, error)

JsonnetParse parses a source Jsonnet document into a Prototype.

func Unmarshal

func Unmarshal(bytes []byte) (*Prototype, error)

Unmarshal takes the bytes of a JSON-encoded prototype specification, and de-serializes them to a `SpecificationSchema`.

func (*Prototype) OptionalParams added in v0.11.0

func (s *Prototype) OptionalParams() ParamSchemas

OptionalParams retrieves all parameters that can optionally be provided to a prototype.

func (*Prototype) RequiredParams added in v0.11.0

func (s *Prototype) RequiredParams() ParamSchemas

RequiredParams retrieves all parameters that are required by a prototype.

type Prototypes added in v0.11.0

type Prototypes []*Prototype

Prototypes is a slice of pointer to `SpecificationSchema`.

type SearchOptions

type SearchOptions int

SearchOptions represents the type of prototype search to execute on an `Index`.

const (
	// Prefix represents a search over prototype name prefixes.
	Prefix SearchOptions = iota

	// Suffix represents a search over prototype name suffixes.
	Suffix

	// Substring represents a search over substrings of prototype names.
	Substring
)

type SnippetSchema

type SnippetSchema struct {
	Prefix string `json:"prefix"`

	// Description describes what the prototype does.
	Description string `json:"description"`

	// ShortDescription briefly describes what the prototype does.
	ShortDescription string `json:"shortDescription"`

	// Various body types of the prototype. Follows the TextMate snippets syntax,
	// with several features disallowed. At least one of these is required to be
	// filled out.
	JSONBody    []string `json:"jsonBody"`
	YAMLBody    []string `json:"yamlBody"`
	JsonnetBody []string `json:"jsonnetBody"`
}

SnippetSchema is the JSON-serializable representation of the TextMate snippet specification, as implemented by the Language Server Protocol.

func (*SnippetSchema) AvailableTemplates

func (schema *SnippetSchema) AvailableTemplates() (ts []TemplateType)

AvailableTemplates returns the list of available `TemplateType`s this prototype implements.

func (*SnippetSchema) Body

func (schema *SnippetSchema) Body(t TemplateType) (template []string, err error)

Body attempts to retrieve the template body associated with some type `t`.

type TemplateType

type TemplateType string

TemplateType represents the possible type of a prototype.

const (
	// YAML represents a prototype written in YAML.
	YAML TemplateType = "yaml"

	// JSON represents a prototype written in JSON.
	JSON TemplateType = "json"

	// Jsonnet represents a prototype written in Jsonnet.
	Jsonnet TemplateType = "jsonnet"
)

func ParseTemplateType

func ParseTemplateType(t string) (TemplateType, error)

ParseTemplateType attempts to parse a string as a `TemplateType`.

Directories

Path Synopsis
Package snippet provides primitives for parsing and evaluating TextMate snippets.
Package snippet provides primitives for parsing and evaluating TextMate snippets.

Jump to

Keyboard shortcuts

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