Documentation ¶
Index ¶
- Variables
- func IsDataFormat(path string) bool
- func IsTemplateLanguage(path string) bool
- func LoadData(format DataFormat, in io.Reader, out interface{}) error
- func LoadDataFile(path string, outp interface{}) error
- func SortFileList(paths []string, order string) (sorted []string, err error)
- func WriteData(format DataFormat, data interface{}, w io.Writer) error
- func WriteDataFile(format DataFormat, data interface{}, path string, force bool) (f *os.File, err error)
- type DataFormat
- type Template
- type TemplateLanguage
Constants ¶
This section is empty.
Variables ¶
var ( ErrUnsupportedTemplate = func(format string) error { return fmt.Errorf("template language '%s' is not supported", format) } ErrUnknownTemplateType = func(templateType string) error { return fmt.Errorf("unable to infer template type '%s'", templateType) } ErrRootPathIsDir = func(path string) error { return fmt.Errorf("rootPath path must be a file, not a directory (%s)", path) } ErrNilTemplate = errors.New("template is nil") )
var ErrUnsupportedData = func(format string) error { return fmt.Errorf("data format '%s' is not supported", format) }
Functions ¶
func IsDataFormat ¶ added in v1.1.0
IsDataFile checks if `path` is one of the known *DatFormat*s.
func IsTemplateLanguage ¶ added in v1.1.0
IsTemplateLanguage will return a bool if the file found at `path` is a known *TemplateLanguage*, based upon it's file extension.
func LoadData ¶
func LoadData(format DataFormat, in io.Reader, out interface{}) error
LoadData attempts to load all data from `in` as `format` and writes the result in the pointer `out`.
func LoadDataFile ¶
LoadDataFile loads all the data from the file found at `path` into the the format of that files extension (e.g. "x.json" will be loaded as a json). The result is written to the value pointed at by `outp`.
func SortFileList ¶
SortFileList sorts `filepath` (a list of filepaths) in `order`. `order` can be any of the following values: "filename", "filename-asc", "filename-desc", "modified", "modified-asc", "modified-desc"; by default "filename" and "modified" are in ascending direction, if specified an "-asc" suffix will set the direction to ascending and "-desc" will set the direction to descending. This was originally intended to be used before calling LoadDataFiles on a set of "data" files.
func WriteData ¶ added in v1.2.1
func WriteData(format DataFormat, data interface{}, w io.Writer) error
WriteData attempts to write `data` as `format` to `outp`.
func WriteDataFile ¶ added in v1.2.1
func WriteDataFile(format DataFormat, data interface{}, path string, force bool) (f *os.File, err error)
WriteDataFile attempts to write `data` as `format` to the file at `path`. If `force` is *true*, then any existing files will be overwritten.
Types ¶
type DataFormat ¶
type DataFormat string
DataFormat provides a list of supported languages for data files (lower-case)
const ( JSON DataFormat = "json" YAML DataFormat = "yaml" TOML DataFormat = "toml" )
func ReadDataFormat ¶
func ReadDataFormat(path string) DataFormat
ReadDataFormat returns the *DataFormat* that the file extension of `path` matches. If the file extension of `path` does not match any *DataFormat*, then an "" is returned.
func (DataFormat) String ¶ added in v1.2.2
func (df DataFormat) String() string
String returns the typical file extension used to represent `df`
type Template ¶
type Template struct { Name string T interface{} }
Template is a wrapper to interface with any template parsed by dati. Ideally it would have just been an interface{} that defines Execute but the libaries being used aren't that uniform.
func LoadTemplate ¶
func LoadTemplate(lang TemplateLanguage, rootName string, root io.Reader, partials map[string]io.Reader) (t Template, err error)
LoadTemplate loads a Template from `root` of type `lang`, named `name`. `lang` must be an element in `SupportedTemplateLangs`. `name` is optional, if empty the template name will be "template". `root` should be a string of template, with syntax matching that of `lang`. `partials` should be a string of template, with syntax matching that of `lang`.
func LoadTemplateFile ¶
LoadTemplateFilepath loads a Template from file `root`. All files in `partials` that have the same template type (identified by file extension) are also parsed and associated with the parsed root template.
func LoadTemplateString ¶
func LoadTemplateString(lang TemplateLanguage, rootName string, root string, partials map[string]string) (t Template, e error)
LoadTemplateString will convert `root` and `partials` data to io.StringReader variables and return a `LoadTemplate` call using them as parameters. The `partials` map should have the template name to assign the partial template to in the string key and the template data in as the value.
func (*Template) Execute ¶
Execute executes `t` against `d`. Reflection is used to determine the template type and call it's execution fuction.
func (*Template) ExecuteToFile ¶ added in v1.3.0
ExecuteToFile writes the result of `(*Template).Execute(data)` to the file at `path` (if no errors occurred). If `force` is true, any existing file at `path` will be overwritten.
type TemplateLanguage ¶
type TemplateLanguage string
TemplateLanguage provides a list of supported languages for Template files (lower-case)
const ( TMPL TemplateLanguage = "tmpl" HTMPL TemplateLanguage = "htmpl" MST TemplateLanguage = "mst" )
func ReadTemplateLangauge ¶ added in v1.0.0
func ReadTemplateLangauge(path string) TemplateLanguage
ReadTemplateLanguage returns the *TemplateLanguage* that the file extension of `path` matches. If the file extension of `path` does not match any *TemplateLanguage*, then an "" is returned.
func (TemplateLanguage) String ¶ added in v1.2.2
func (t TemplateLanguage) String() string