tmpl

package
v0.0.0-...-bef94b3 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2019 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateOrOverwrite

func CreateOrOverwrite(path string, content []byte) error

CreateOrOverwrite writes to a file. Create if it doesn't exist, replace if it does. Existing files will overwritten.

func DefaultDataDir

func DefaultDataDir() string

DefaultDataDir returns path to the directory containing a user's templates.

func PickFile

func PickFile(dir, message string) string

PickFile prompts a user to choose a file from a given directory.

func PickTemplate

func PickTemplate(message string) (name string)

PickTemplate lets the user select a template and returns its name.

func ReadDir

func ReadDir(path string) []string

ReadDir returns a string slice with the names of all files in a directory.

func Setup

func Setup()

Setup creates all files & folders used by tmpl. Should be called directly after installing.

func SingleFromFile

func SingleFromFile() error

SingleFromFile creates a new single-file template from an existing file.

func StringToFile

func StringToFile(content string, destination string) error

StringToFile writes a string to a new or existing file. Existing files will overwritten.

func Teardown

func Teardown()

Teardown removes all files & folders used by tmpl. Should be called before uninstalling.

Types

type CFG

type CFG struct {
	TemplatesDir string // Path to the folder where a user's templates are stored.
	Editor       string // Text editor used for editing templates.
}

CFG contains config variables for tmpl.

type Data

type Data map[string]string

Data contains variables used in templates.

type Template

type Template struct {
	Name      string   // Name used to identify the template. These are unique.
	MultiFile bool     // True if the template is for more than a single file.
	FileName  string   // Name to use when creating a copy of this template.
	Content   string   // The content of the template itself.
	Data      []string // Data used for dynamic template content.
}

Template is a single file.

func (*Template) AddData

func (t *Template) AddData(data ...string)

AddData to a template.

func (Template) GetContent

func (t Template) GetContent() string

GetContent for a template. Prompts for variable values if the template has any.

func (Template) Use

func (t Template) Use()

Use copies a single template to a user's current directory, applying any data the template has.

type Templates

type Templates struct {
	T []Template `json:"templates"`
}

Templates models a user's existing templates.

func GetTemplates

func GetTemplates() (Templates, error)

GetTemplates returns the user's templates.

func (*Templates) Add

func (ts *Templates) Add(newTmpl Template) error

Add a new template.

func (Templates) GetByName

func (ts Templates) GetByName(name string) (Template, error)

GetByName returns a template with a given name and an error if no template is found.

func (*Templates) NameExists

func (ts *Templates) NameExists(name string) bool

NameExists checks to see if a given name is already being used for a template.

func (Templates) Names

func (ts Templates) Names() []string

Names returns the names of all templates.

func (*Templates) Remove

func (ts *Templates) Remove(name string) error

Remove an existing template, itendified by its name.

func (Templates) Save

func (ts Templates) Save() error

Save templates to a user's templates.json file.

func (*Templates) Update

func (ts *Templates) Update(t Template) error

Update an existing template.

Jump to

Keyboard shortcuts

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