Skip to content

Commit

Permalink
Replace package collection
Browse files Browse the repository at this point in the history
  • Loading branch information
jellyterra committed Jul 24, 2024
1 parent 2cddbc5 commit 580d5c6
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 220 deletions.
72 changes: 0 additions & 72 deletions collection/array.go

This file was deleted.

125 changes: 0 additions & 125 deletions collection/map.go

This file was deleted.

1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ require (
github.com/fsnotify/fsnotify v1.7.0
github.com/gomarkdown/markdown v0.0.0-20240419095408-642f0ee99ae2
github.com/gorilla/websocket v1.5.3
github.com/jellyterra/collection-go v0.0.1
)

require (
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ github.com/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aN
github.com/gorilla/websocket v1.5.3/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
github.com/jellyterra/collection-go v0.0.1 h1:pJhz3YSqSupliQPgeVtGuDTSCZ9qq/Q7V4kDf09fkiI=
github.com/jellyterra/collection-go v0.0.1/go.mod h1:oKzk4H4F2OEoKwNnbVV01P/QacuP7liUNgkmK0YtXj4=
github.com/mna/pigeon v1.1.0 h1:EjlvVbkGnNGemf8OrjeJX0nH8orujY/HkJgzJtd7kxc=
github.com/mna/pigeon v1.1.0/go.mod h1:rkFeDZ0gc+YbnrXPw0q2RlI0QRuKBBPu67fgYIyGRNg=
github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
Expand Down
20 changes: 10 additions & 10 deletions structure/hierarchy.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
package structure

import (
"github.com/webpagine/pagine/v2/collection"
"github.com/jellyterra/collection-go"
"github.com/webpagine/pagine/v2/util"
"github.com/webpagine/pagine/v2/vfs"
"maps"
Expand Down Expand Up @@ -69,9 +69,9 @@ func ExecuteLevels(env *Env, root, dest vfs.DirFS, inherit MetadataSet) (Level,
unitManifest UnitManifest
metadata MetadataSet

units collection.SyncArray[Unit]
reports collection.SyncArray[LevelReport]
levels collection.SyncArray[Level]
units collection.SyncVector[Unit]
reports collection.SyncVector[LevelReport]
levels collection.SyncVector[Level]
)

err := func() error {
Expand Down Expand Up @@ -104,7 +104,7 @@ func ExecuteLevels(env *Env, root, dest vfs.DirFS, inherit MetadataSet) (Level,
}

unit.Report.TemplateErrors, unit.Report.Error = unit.Generate(env, root, dest, metadata, unitItem.Define)
units.Append(unit)
units.Push(unit)
}()
}
case os.IsNotExist(err):
Expand Down Expand Up @@ -132,13 +132,13 @@ func ExecuteLevels(env *Env, root, dest vfs.DirFS, inherit MetadataSet) (Level,

level, err := ExecuteLevels(env, sub, dest, metadata)
if err != nil {
reports.Append(LevelReport{
reports.Push(LevelReport{
Level: &level,
Err: err,
})
return
}
levels.Append(level)
levels.Push(level)
}()
}

Expand All @@ -153,8 +153,8 @@ func ExecuteLevels(env *Env, root, dest vfs.DirFS, inherit MetadataSet) (Level,
return Level{
Root: root,
Data: metadata,
Units: units.RawArray,
Levels: levels.RawArray,
Reports: reports.RawArray,
Units: units.It.Raw,
Levels: levels.It.Raw,
Reports: reports.It.Raw,
}, nil
}
26 changes: 13 additions & 13 deletions structure/unit.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package structure

import (
"bytes"
"github.com/webpagine/pagine/v2/collection"
"github.com/jellyterra/collection-go"
"github.com/webpagine/pagine/v2/global"
"github.com/webpagine/pagine/v2/render"
"github.com/webpagine/pagine/v2/vfs"
Expand Down Expand Up @@ -36,7 +36,7 @@ type Unit struct {
}

func (u *Unit) Generate(env *Env, root, dest vfs.DirFS, data MetadataSet, define map[string]any) ([]error, error) {
var errors collection.Array[error]
var errors collection.Vector[error]

templateName, templateKey := ParseTemplatePair(u.Template)

Expand All @@ -58,7 +58,7 @@ func (u *Unit) Generate(env *Env, root, dest vfs.DirFS, data MetadataSet, define
renderFromPath := func(r render.Renderer, pathStr any) string {
result, err := render.FromPath(r, root, pathStr.(string))
if err != nil {
errors.Append(err)
errors.Push(err)
return ""
}
return result
Expand Down Expand Up @@ -88,64 +88,64 @@ func (u *Unit) Generate(env *Env, root, dest vfs.DirFS, data MetadataSet, define
"apply": func(pathStr any, data any) any {
path := filepath.Join(root.Path, pathStr.(string))
if _, ok := appliedTemplates[path]; ok {
errors.Append(&RecursiveInvokeError{Templates: nil})
errors.Push(&RecursiveInvokeError{Templates: nil})
return nil
}
appliedTemplates[path] = struct{}{}
defer delete(appliedTemplates, path)

t, err := template.New(filepath.Base(pathStr.(string))).Funcs(funcMap).ParseFS(root, pathStr.(string))
if err != nil {
errors.Append(err)
errors.Push(err)
return ""
}
b := bytes.NewBuffer(nil)
err = t.Execute(b, data)
if err != nil {
errors.Append(err)
errors.Push(err)
return ""
}
return b.String()
},
"applyFromEnv": func(nameStr any, data any) any {
path := nameStr.(string)
if _, ok := appliedTemplates[path]; ok {
errors.Append(&RecursiveInvokeError{Templates: nil})
errors.Push(&RecursiveInvokeError{Templates: nil})
return nil
}
appliedTemplates[path] = struct{}{}
defer delete(appliedTemplates, path)

split := strings.Split(nameStr.(string), ":")
if len(split) != 2 {
errors.Append(&TemplateUndefinedError{Name: nameStr.(string)})
errors.Push(&TemplateUndefinedError{Name: nameStr.(string)})
return nil
}
t, ok := env.Templates[split[0]]
if !ok {
errors.Append(&TemplateUndefinedError{Name: split[0]})
errors.Push(&TemplateUndefinedError{Name: split[0]})
return nil
}
buf := bytes.NewBuffer(nil)
err := t.ExecuteTemplate(buf, funcMap, split[1], data)
if err != nil {
errors.Append(err)
errors.Push(err)
return nil
}
return buf.String()
},
"embed": func(pathStr any) any {
b, err := root.ReadFile(pathStr.(string))
if err != nil {
errors.Append(err)
errors.Push(err)
return ""
}
return string(b)
},
"render": func(pathStr any) any {
r, ok := render.Renderers[filepath.Ext(pathStr.(string))[1:]]
if !ok {
errors.Append(&render.NotFoundError{Path: pathStr.(string)})
errors.Push(&render.NotFoundError{Path: pathStr.(string)})
return ""
}
return renderFromPath(r, pathStr)
Expand All @@ -167,5 +167,5 @@ func (u *Unit) Generate(env *Env, root, dest vfs.DirFS, data MetadataSet, define
return nil, err
}

return errors.RawArray, nil
return errors.Raw, nil
}

0 comments on commit 580d5c6

Please sign in to comment.