diff --git a/Cms.go b/Cms.go index d1625ca..d86e541 100644 --- a/Cms.go +++ b/Cms.go @@ -1,8 +1,6 @@ package cms import ( - "net/http" - "github.com/gouniverse/cachestore" "github.com/gouniverse/entitystore" "github.com/gouniverse/logstore" @@ -65,7 +63,7 @@ type Cms struct { tasksTaskTableName string tasksQueueTableName string - shortcodes map[string]func(*http.Request, string, map[string]string) string + shortcodes []ShortcodeInterface translationLanguageDefault string translationLanguages map[string]string @@ -103,7 +101,7 @@ func configToCms(config Config) *Cms { } if config.Shortcodes == nil { - config.Shortcodes = map[string]func(*http.Request, string, map[string]string) string{} + config.Shortcodes = []ShortcodeInterface{} } if config.TranslationLanguageDefault == "" && len(config.TranslationLanguages) > 0 { diff --git a/Config.go b/Config.go index f973082..1ea5c1f 100644 --- a/Config.go +++ b/Config.go @@ -2,7 +2,6 @@ package cms import ( "database/sql" - "net/http" "github.com/gouniverse/sb" ) @@ -26,7 +25,7 @@ type Config struct { SessionEnable bool SettingsAutomigrate bool SettingsEnable bool - Shortcodes map[string]func(*http.Request, string, map[string]string) string + Shortcodes []ShortcodeInterface TasksEnable bool TasksAutomigrate bool TasksQueueTableName string diff --git a/ContentRenderShortcodes.go b/ContentRenderShortcodes.go index cab2fa0..1db4c0e 100644 --- a/ContentRenderShortcodes.go +++ b/ContentRenderShortcodes.go @@ -14,8 +14,8 @@ func (cms *Cms) ContentRenderShortcodes(req *http.Request, content string) (stri return "", err } - for k, v := range cms.shortcodes { - content = sh.RenderWithRequest(req, content, k, v) + for _, shortcode := range cms.shortcodes { + content = sh.RenderWithRequest(req, content, shortcode.Alias(), shortcode.Render()) } return content, nil diff --git a/ShortcodeAdd.go b/ShortcodeAdd.go index df5803b..24fdec4 100644 --- a/ShortcodeAdd.go +++ b/ShortcodeAdd.go @@ -1,9 +1,5 @@ package cms -import ( - "net/http" -) - -func (cms *Cms) ShortcodeAdd(key string, fnRender func(r *http.Request, s string, m map[string]string) string) { - cms.shortcodes[key] = fnRender +func (cms *Cms) ShortcodeAdd(shortcode ShortcodeInterface) { + cms.shortcodes = append(cms.shortcodes, shortcode) } diff --git a/ShortcodeInterface.go b/ShortcodeInterface.go new file mode 100644 index 0000000..f593de2 --- /dev/null +++ b/ShortcodeInterface.go @@ -0,0 +1,9 @@ +package cms + +import "net/http" + +type ShortcodeInterface interface { + Alias() string + Description() string + Render() func(r *http.Request, s string, m map[string]string) string +} diff --git a/ShortcodesAdd.go b/ShortcodesAdd.go index 41f5a68..741fc9f 100644 --- a/ShortcodesAdd.go +++ b/ShortcodesAdd.go @@ -1,11 +1,7 @@ package cms -import ( - "net/http" -) - -func (cms *Cms) ShortcodesAdd(shortcodes map[string]func(r *http.Request, s string, m map[string]string) string) { - for key, fnRender := range shortcodes { - cms.ShortcodeAdd(key, fnRender) +func (cms *Cms) ShortcodesAdd(shortcodes []ShortcodeInterface) { + for _, shortcode := range shortcodes { + cms.ShortcodeAdd(shortcode) } }