chore: planning next refactor

main
Antonio De Lucreziis 2 years ago
parent ea0f84bc18
commit 81490ac758

@ -67,8 +67,6 @@ Each pipeline is a list of operations, the first field in an operation should be
For each incoming item this will render the given path template with the item metadata and write the content to disk.
- `use: <operation>`
This will apply the provided operations to the incoming items, for now available operations are
@ -155,3 +153,21 @@ Each pipeline is a list of operations, the first field in an operation should be
key: <key to use for sorting>
```
## Architecture
- `cabret.go` &mdash; all abstract types and functions
- `path/` &mdash; handles path patterns and templates
- `config/` &mdash; contains config structure definitions and handles loading from YAML
- `cmd/cabret` &mdash; module that puts it all together in a CLI application
- `operation/` &mdash; module containing all operations
(_TODO_):
- `exec/ -> runner/` &mdash; a module that depends on `config`, `parse` and `operations` and evaluates operations.
- `pipeline/ -> {parse/, runner/}`

@ -1,97 +0,0 @@
package operation
// import (
// "fmt"
// "log"
// "mime"
// "path/filepath"
// "strings"
// "github.com/aziis98/cabret"
// "github.com/aziis98/cabret/operation/template"
// )
// func init() {
// registerType("template", &Template{})
// }
// type Template struct {
// // TemplatePatterns is a list of glob patterns of templates that will be loaded
// TemplatePatterns []string
// }
// func (op *Template) Load(config map[string]any) error {
// if v, ok := config[ShortFormValueKey]; ok {
// globPatternsStr, ok := v.(string)
// if !ok {
// return fmt.Errorf(`expected a comma separated list of glob patterns but got "%v" of type %T`, v, v)
// }
// globPatterns := strings.Split(globPatternsStr, ",")
// for _, pat := range globPatterns {
// op.TemplatePatterns = append(op.TemplatePatterns, strings.TrimSpace(pat))
// }
// return nil
// }
// if v, ok := config["paths"]; ok {
// globPatterns, ok := v.([]string)
// if !ok {
// return fmt.Errorf(`expected a list of glob patterns but got "%v" of type %T`, v, v)
// }
// for _, pat := range globPatterns {
// op.TemplatePatterns = append(op.TemplatePatterns, strings.TrimSpace(pat))
// }
// return nil
// }
// if v, ok := config["path"]; ok {
// globPatternStr, ok := v.(string)
// if !ok {
// return fmt.Errorf(`expected a glob pattern but got "%v" of type %T`, v, v)
// }
// op.TemplatePatterns = []string{strings.TrimSpace(globPatternStr)}
// return nil
// }
// return fmt.Errorf(`invalid config for "template": %#v`, config)
// }
// func (op *Template) ProcessList(contents []cabret.Content) ([]cabret.Content, error) {
// // expand glob patterns
// tmplFiles := []string{}
// for _, pat := range op.TemplatePatterns {
// files, err := filepath.Glob(strings.TrimSpace(pat))
// if err != nil {
// return nil, err
// }
// tmplFiles = append(tmplFiles, files...)
// }
// // create template
// tmpl, err := template.ParseFiles(tmplFiles...)
// if err != nil {
// return nil, err
// }
// log.Printf(`[operation.Layout] rendering into layout "%s"`, strings.Join(op.TemplatePatterns, ", "))
// ctx := map[string]any{}
// ctx["Items"] = contents
// data, err := tmpl.Render(ctx)
// if err != nil {
// return nil, err
// }
// return []cabret.Content{
// {
// Type: mime.TypeByExtension(filepath.Ext(tmplFiles[0])),
// Data: data,
// Metadata: ctx,
// },
// }, nil
// }
Loading…
Cancel
Save