Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

57 řádky
1.2KB

  1. // Package template makes it possible to describe templates and patterns in yaml files and
  2. // to render them to SVG.
  3. package template
  4. import (
  5. "fmt"
  6. "os"
  7. "unicode"
  8. "gopkg.in/yaml.v3"
  9. )
  10. // Sizes defines a map with the size name and the size value.
  11. type Sizes map[string]float64
  12. // Template contains the generic information to draw a specific clothing pattern.
  13. type Template struct {
  14. Points `yaml:"points"`
  15. Panels `yaml:"panels"`
  16. }
  17. // LoadPattern reads and decodes a [Request] from a yaml file.
  18. func LoadPattern(name string) (Request, error) {
  19. fh, err := os.Open(name)
  20. if err != nil {
  21. return Request{}, fmt.Errorf("open pattern file %q: %w", name, err)
  22. }
  23. pat := Request{}
  24. err = yaml.NewDecoder(fh).Decode(&pat)
  25. if err != nil {
  26. return Request{}, fmt.Errorf("decode content of file %q as yaml: %w", name, err)
  27. }
  28. return pat, nil
  29. }
  30. func startCase(text string) string {
  31. output := make([]rune, len(text))
  32. for i, val := range text {
  33. switch {
  34. case i == 0:
  35. output[i] = unicode.ToUpper(val)
  36. case val == '_':
  37. output[i] = ' '
  38. case output[i-1] == ' ':
  39. output[i] = unicode.ToUpper(val)
  40. default:
  41. output[i] = val
  42. }
  43. }
  44. return string(output)
  45. }