• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mlange-42 / modo / 13022511414

29 Jan 2025 12:58AM CUT coverage: 67.178%. Remained the same
13022511414

Pull #149

github

web-flow
Merge 04bced741 into 34cbfc238
Pull Request #149: Fix `.gitignore` for mdBook

1226 of 1825 relevant lines covered (67.18%)

28.99 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

41.79
/document/util.go
1
package document
2

3
import (
4
        "fmt"
5
        "io/fs"
6
        "os"
7
        "path/filepath"
8
        "text/template"
9

10
        "github.com/mlange-42/modo/assets"
11
)
12

13
// appends to a slice, but guaranties to return a new one and not alter the original.
14
func appendNew[T any](sl []T, elems ...T) []T {
692✔
15
        sl2 := make([]T, len(sl), len(sl)+len(elems))
692✔
16
        copy(sl2, sl)
692✔
17
        sl2 = append(sl2, elems...)
692✔
18
        return sl2
692✔
19
}
692✔
20

21
func warnOrError(strict bool, pattern string, args ...any) error {
×
22
        if strict {
×
23
                return fmt.Errorf(pattern, args...)
×
24
        }
×
25
        fmt.Printf("WARNING: "+pattern+"\n", args...)
×
26
        return nil
×
27
}
28

29
func LoadTemplates(f Formatter, additional ...string) (*template.Template, error) {
11✔
30
        allTemplates, err := findTemplatesFS()
11✔
31
        if err != nil {
11✔
32
                return nil, err
×
33
        }
×
34
        templ := template.New("all")
11✔
35
        templ = templ.Funcs(template.FuncMap{
11✔
36
                "toLink": f.ToLinkPath,
11✔
37
        })
11✔
38
        templ, err = templ.ParseFS(assets.Templates, allTemplates...)
11✔
39
        if err != nil {
11✔
40
                return nil, err
×
41
        }
×
42

43
        for _, dir := range additional {
11✔
44
                if dir == "" {
×
45
                        continue
×
46
                }
47
                moreTemplates, err := findTemplates(dir)
×
48
                if err != nil {
×
49
                        return nil, err
×
50
                }
×
51
                templ, err = templ.ParseFiles(moreTemplates...)
×
52
                if err != nil {
×
53
                        return nil, err
×
54
                }
×
55
        }
56
        return templ, nil
11✔
57
}
58

59
func findTemplatesFS() ([]string, error) {
11✔
60
        allTemplates := []string{}
11✔
61
        err := fs.WalkDir(assets.Templates, ".",
11✔
62
                func(path string, info os.DirEntry, err error) error {
385✔
63
                        if err != nil {
374✔
64
                                return err
×
65
                        }
×
66
                        if !info.IsDir() {
693✔
67
                                allTemplates = append(allTemplates, path)
319✔
68
                        }
319✔
69
                        return nil
374✔
70
                })
71
        if err != nil {
11✔
72
                return nil, err
×
73
        }
×
74
        return allTemplates, nil
11✔
75
}
76

77
func findTemplates(dir string) ([]string, error) {
×
78
        allTemplates := []string{}
×
79
        err := filepath.WalkDir(dir,
×
80
                func(path string, info os.DirEntry, err error) error {
×
81
                        if err != nil {
×
82
                                return err
×
83
                        }
×
84
                        if !info.IsDir() {
×
85
                                allTemplates = append(allTemplates, path)
×
86
                        }
×
87
                        return nil
×
88
                })
89
        if err != nil {
×
90
                return nil, err
×
91
        }
×
92
        return allTemplates, nil
×
93
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc