Skip to content

Commit

Permalink
feat: define draft version of sparkle.toml configuration file
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilsk committed Nov 7, 2023
1 parent 55b160a commit 80c3a7d
Show file tree
Hide file tree
Showing 9 changed files with 113 additions and 20 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ go 1.21.3

require (
connectrpc.com/connect v1.12.0
github.com/BurntSushi/toml v1.3.2
github.com/fatih/color v1.15.0
github.com/gohugoio/hugo v0.120.3
github.com/golang/mock v1.6.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 23 additions & 1 deletion internal/config/services.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,27 @@
package config

import (
"go.octolab.org/ecosystem/sparkle/internal/plugins/obsidian/calendar"
diary "go.octolab.org/ecosystem/sparkle/internal/plugins/obsidian/daily-notes"
"go.octolab.org/ecosystem/sparkle/internal/plugins/obsidian/periodic-notes"
)

type Server struct {
Name string `mapstructure:"APP_NAME"`
Name string `json:"name"`
Service Service `json:"service"`
}

type Service struct {
License string `json:"license"`
Plugins Plugins `json:"plugins"`
}

type Plugins struct {
Obsidian ObsidianPlugins `json:"obsidian"`
}

type ObsidianPlugins struct {
Calendar calendar.Config `json:"calendar"`
DailyNotes diary.Config `json:"daily-notes"`
PeriodicNotes periodic.Config `json:"periodic-notes"`
}
20 changes: 20 additions & 0 deletions internal/config/services_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package config

import (
"os"
"testing"

"github.com/BurntSushi/toml"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestToml(t *testing.T) {
f, err := os.Open("testdata/sparkle.toml")
require.NoError(t, err)

var cfg Server
_, err = toml.NewDecoder(f).Decode(&cfg)
assert.NoError(t, err)
assert.Equal(t, "locale", cfg.Service.Plugins.Obsidian.Calendar.WeekStart)
}
60 changes: 60 additions & 0 deletions internal/config/testdata/sparkle.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
[service]
license = "65541023-fb3e-4107-ac8e-158fc2e64a18"



[service.plugins.obsidian.calendar]
enabled = true
localeOverride = "system-default"
shouldConfirmBeforeCreate = true
weekStart = "locale"
wordsPerDot = 500
showWeeklyNote = true
weeklyNoteFormat = "[Week] W, YYYY"
weeklyNoteTemplate = "4. Resources/Templates/Weekly plans"
weeklyNoteFolder = "1. Stream/Tactic"


[service.plugins.obsidian.daily-notes]
enabled = true
autorun = false
format = "YYYY-MM-DD"
folder = "1. Stream/Diary"
template = "4. Resources/Templates/Daily notes"


[service.plugins.obsidian.periodic-notes]
enabled = true
showGettingStartedBanner = true
hasMigratedDailyNoteSettings = true
hasMigratedWeeklyNoteSettings = true

[service.plugins.obsidian.periodic-notes.daily]
enabled = true
format = "YYYY-MM-DD"
folder = "1. Stream/Diary"
template = "4. Resources/Templates/Daily notes"

[service.plugins.obsidian.periodic-notes.weekly]
enabled = true
format = "[Week] W, YYYY"
folder = "1. Stream/Tactic"
template = "4. Resources/Templates/Weekly plans"

[service.plugins.obsidian.periodic-notes.monthly]
enabled = true
format = "MMMM, YYYY"
template = "4. Resources/Templates/Monthly plans"
folder = "1. Stream/Tactic"

[service.plugins.obsidian.periodic-notes.quarterly]
enabled = true
format = "[Q]Q, YYYY"
template = "4. Resources/Templates/Quarterly plans"
folder = "1. Stream/Tactic"

[service.plugins.obsidian.periodic-notes.yearly]
enabled = true
format = "YYYY"
template = "4. Resources/Templates/Annual plans"
folder = "1. Stream/Tactic"
8 changes: 2 additions & 6 deletions internal/plugins/obsidian/calendar/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func LoadConfig(fs afero.Fs) (Config, error) {
}
}

cnf.enabled = true
cnf.Enabled = true
return cnf, nil
}

Expand All @@ -61,7 +61,7 @@ type Config struct {
WeeklyNoteFolder string `json:"weeklyNoteFolder"`
LocaleOverride string `json:"localeOverride"`

enabled bool
Enabled bool
}

func (Config) Documentation() string {
Expand All @@ -72,10 +72,6 @@ func (Config) Enabler() string {
return "Settings > Options > Community plugins > Installed plugins > Calendar"
}

func (cnf Config) IsEnabled() bool {
return cnf.enabled
}

func (Config) Section() string {
return "Settings > Community plugins > Calendar"
}
Expand Down
8 changes: 2 additions & 6 deletions internal/plugins/obsidian/daily-notes/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func LoadConfig(fs afero.Fs) (Config, error) {
}
}

cnf.enabled = true
cnf.Enabled = true
return cnf, nil
}

Expand All @@ -53,7 +53,7 @@ type Config struct {
Format string `json:"format"`
Template string `json:"template"`

enabled bool
Enabled bool
}

func (Config) Documentation() string {
Expand All @@ -64,10 +64,6 @@ func (Config) Enabler() string {
return "Settings > Options > Core plugins > Daily notes"
}

func (cnf Config) IsEnabled() bool {
return cnf.enabled
}

func (Config) Section() string {
return "Settings > Core plugins > Daily notes"
}
Expand Down
2 changes: 1 addition & 1 deletion internal/plugins/obsidian/daily-notes/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func TestLoadConfig(t *testing.T) {
Format: "DD.MM.YYYY",
Template: "path/to/template.md",

enabled: true,
Enabled: true,
}
fs := afero.NewMemMapFs()
r := bytes.NewBuffer(nil)
Expand Down
8 changes: 2 additions & 6 deletions internal/plugins/obsidian/periodic-notes/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func LoadConfig(fs afero.Fs) (Config, error) {
}
}

cnf.enabled = true
cnf.Enabled = true
return cnf, nil
}

Expand All @@ -76,7 +76,7 @@ type Config struct {
Quarterly Period `json:"quarterly"`
Yearly Period `json:"yearly"`

enabled bool
Enabled bool
}

type Period struct {
Expand All @@ -94,10 +94,6 @@ func (Config) Enabler() string {
return "Settings > Options > Community plugins > Installed plugins > Periodic Notes"
}

func (cnf Config) IsEnabled() bool {
return cnf.enabled
}

func (Config) Section() string {
return "Settings > Community plugins > Periodic Notes"
}
Expand Down

0 comments on commit 80c3a7d

Please sign in to comment.