EurekaAdapter: flesh out CreatePage, SavePage, DeletePage and added TODO comments and the Config map; gofmt
This commit is contained in:
parent
1bc8eac481
commit
b9d971140a
5 changed files with 62 additions and 35 deletions
|
@ -4,7 +4,7 @@ type Adapter interface {
|
||||||
Init(cfg *Config)
|
Init(cfg *Config)
|
||||||
Name() string
|
Name() string
|
||||||
EditableSlugs() bool
|
EditableSlugs() bool
|
||||||
BuildOptions() ([]string)
|
BuildOptions() []string
|
||||||
GetConfig(key string) (interface{}, error)
|
GetConfig(key string) (interface{}, error)
|
||||||
SetConfig(key string, value interface{}) error
|
SetConfig(key string, value interface{}) error
|
||||||
ListPages() map[string]string
|
ListPages() map[string]string
|
||||||
|
|
|
@ -10,6 +10,7 @@ import (
|
||||||
|
|
||||||
type EurekaAdapter struct {
|
type EurekaAdapter struct {
|
||||||
Root string
|
Root string
|
||||||
|
Config map[string]interface{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *EurekaAdapter) Init(cfg *Config) {
|
func (self *EurekaAdapter) Init(cfg *Config) {
|
||||||
|
@ -21,6 +22,8 @@ func (self *EurekaAdapter) Init(cfg *Config) {
|
||||||
}
|
}
|
||||||
|
|
||||||
self.Root = cfg.Root
|
self.Root = cfg.Root
|
||||||
|
|
||||||
|
// TODO: read config.h and build self.Config
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *EurekaAdapter) Name() string {
|
func (self *EurekaAdapter) Name() string {
|
||||||
|
@ -88,25 +91,49 @@ func (self *EurekaAdapter) GetPage(filename string) (Page, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *EurekaAdapter) FormatPage(raw string) string {
|
func (self *EurekaAdapter) FormatPage(raw string) string {
|
||||||
|
// TODO: implement Eureka formatter to show preview
|
||||||
return raw
|
return raw
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *EurekaAdapter) FormattingHelp() string {
|
func (self *EurekaAdapter) FormattingHelp() string {
|
||||||
|
// TODO: show Eureka formatting guide
|
||||||
return "help!"
|
return "help!"
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *EurekaAdapter) CreatePage(slug, title, content string) error {
|
func (self *EurekaAdapter) CreatePage(slug, title, content string) error {
|
||||||
|
// eureka makes titles from slugs, so we don't use title here
|
||||||
|
f, err := os.Create(filepath.Join(self.Root, "inc", newSlug))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer f.Close()
|
||||||
|
f.WriteString(content)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *EurekaAdapter) SavePage(oldSlug, newSlug, title, content string) error {
|
func (self *EurekaAdapter) SavePage(oldSlug, newSlug, title, content string) error {
|
||||||
|
// eureka makes titles from slugs, so we don't use title here
|
||||||
|
f, err := os.Create(filepath.Join(self.Root, "inc", newSlug))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer f.Close()
|
||||||
|
|
||||||
|
if oldSlug != newSlug {
|
||||||
|
// TODO: delete old html as well
|
||||||
|
os.Remove(filepath.Join(self.Root, "inc", oldSlug))
|
||||||
|
}
|
||||||
|
|
||||||
|
f.WriteString(content)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *EurekaAdapter) DeletePage(slug string) error {
|
func (self *EurekaAdapter) DeletePage(slug string) error {
|
||||||
return nil
|
// TODO: delete old html as well
|
||||||
|
return os.Remove(filepath.Join(self.Root, "inc", slug))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *EurekaAdapter) Build(buildOptions map[string]string) (bool, string) {
|
func (self *EurekaAdapter) Build(buildOptions map[string]string) (bool, string) {
|
||||||
|
// TODO: shell out to build.sh with buildOptions, record exit status and output
|
||||||
return true, "Build successful"
|
return true, "Build successful"
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,9 +2,9 @@ package lfo
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"strings"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
core "nilfm.cc/git/nirvash/archetype"
|
core "nilfm.cc/git/nirvash/archetype"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
func WithAdapter(next http.Handler, adapter core.Adapter) http.Handler {
|
func WithAdapter(next http.Handler, adapter core.Adapter) http.Handler {
|
||||||
|
|
Loading…
Reference in a new issue