Skip to content

Commit

Permalink
shortcode updates
Browse files Browse the repository at this point in the history
  • Loading branch information
lesichkovm committed Mar 24, 2024
1 parent 5e8ba98 commit e028457
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 21 deletions.
6 changes: 2 additions & 4 deletions Cms.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package cms

import (
"net/http"

"github.com/gouniverse/cachestore"
"github.com/gouniverse/entitystore"
"github.com/gouniverse/logstore"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
3 changes: 1 addition & 2 deletions Config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package cms

import (
"database/sql"
"net/http"

"github.com/gouniverse/sb"
)
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions ContentRenderShortcodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 2 additions & 6 deletions ShortcodeAdd.go
Original file line number Diff line number Diff line change
@@ -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)
}
9 changes: 9 additions & 0 deletions ShortcodeInterface.go
Original file line number Diff line number Diff line change
@@ -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
}
10 changes: 3 additions & 7 deletions ShortcodesAdd.go
Original file line number Diff line number Diff line change
@@ -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)
}
}

0 comments on commit e028457

Please sign in to comment.