|
- // Package template makes it possible to describe templates and patterns in yaml files and
- // to render them to SVG.
- package template
-
- import (
- "fmt"
- "os"
- "unicode"
-
- "gopkg.in/yaml.v3"
- )
-
- // Sizes defines a map with the size name and the size value.
- type Sizes map[string]float64
-
- // Template contains the generic information to draw a specific clothing pattern.
- type Template struct {
- Points `yaml:"points"`
- Panels `yaml:"panels"`
- }
-
- // LoadPattern reads and decodes a [Request] from a yaml file.
- func LoadPattern(name string) (Request, error) {
- fh, err := os.Open(name)
- if err != nil {
- return Request{}, fmt.Errorf("open pattern file %q: %w", name, err)
- }
-
- pat := Request{}
-
- err = yaml.NewDecoder(fh).Decode(&pat)
- if err != nil {
- return Request{}, fmt.Errorf("decode content of file %q as yaml: %w", name, err)
- }
-
- return pat, nil
- }
-
- func startCase(text string) string {
- output := make([]rune, len(text))
-
- for i, val := range text {
- switch {
- case i == 0:
- output[i] = unicode.ToUpper(val)
- case val == '_':
- output[i] = ' '
- case output[i-1] == ' ':
- output[i] = unicode.ToUpper(val)
- default:
- output[i] = val
- }
- }
-
- return string(output)
- }
|