package template import ( "fmt" "git.wtrh.nl/patterns/gopatterns/pkg/pattern/text" "slices" "strings" ) type Information struct { Point `yaml:",inline"` Anchor string `yaml:"anchor"` } func (t Template) createInformation(req request) (text.Text, error) { templatePanel, ok := t.Panels[req.panel] if !ok { return text.Text{}, ErrPanelNotFound } dims := make([]string, 0, len(req.dimensions)) for _, dimension := range req.dimensions { dims = append(dims, fmt.Sprintf(" %s: %.1f cm", dimension.Name, dimension.Value/10)) } slices.Sort(dims) dims = append([]string{ "For: " + req.owner, "Pattern: " + startCase(t.Name), "Panel: " + startCase(req.panel), "Hem allowance: " + templatePanel.Allowances.Hem, "Seam allowance: " + templatePanel.Allowances.Seam, "\nMeasurements:", }, dims...) templatePanel.Points["_information"] = templatePanel.Information.Point point, err := t.getOrCreatePoint("_information", req, 0) if err != nil { return text.Text{}, err } info := text.NewText(point.Position(), templatePanel.Information.Anchor, strings.Join(dims, "\n")) return info, nil }