summaryrefslogtreecommitdiff
path: root/management/manager
diff options
context:
space:
mode:
authorSteve <nilslice@gmail.com>2016-12-19 11:19:53 -0800
committerGitHub <noreply@github.com>2016-12-19 11:19:53 -0800
commit3791fadda7b761ffba38c567da29e2e71acd1dfb (patch)
tree79d810f9aafa1868ee0760983937470d0eea3db8 /management/manager
parentb20c5bdee38682edc851e646d815a34689c3c923 (diff)
[addons] Creating foundation for plugin-like system "Addons" (#24)
* adding addons dir and sample addon which enables the use of a new input element in forms for referencing other content. "addons" is a conceptual plugin-like feature, similar to wordpress "plugins" dir, but not as sophisticated
Diffstat (limited to 'management/manager')
-rw-r--r--management/manager/manager.go10
-rw-r--r--management/manager/process.go72
2 files changed, 5 insertions, 77 deletions
diff --git a/management/manager/manager.go b/management/manager/manager.go
index 989eb98..5eafb9a 100644
--- a/management/manager/manager.go
+++ b/management/manager/manager.go
@@ -5,8 +5,8 @@ import (
"fmt"
"html/template"
- "github.com/bosssauce/ponzu/content"
"github.com/bosssauce/ponzu/management/editor"
+ "github.com/bosssauce/ponzu/system/item"
uuid "github.com/satori/go.uuid"
)
@@ -121,14 +121,14 @@ func Manage(e editor.Editable, typeName string) ([]byte, error) {
return nil, fmt.Errorf("Couldn't marshal editor for content %s. %s", typeName, err.Error())
}
- i, ok := e.(content.Identifiable)
+ i, ok := e.(item.Identifiable)
if !ok {
- return nil, fmt.Errorf("Content type %s does not implement content.Identifiable.", typeName)
+ return nil, fmt.Errorf("Content type %s does not implement item.Identifiable.", typeName)
}
- s, ok := e.(content.Sluggable)
+ s, ok := e.(item.Sluggable)
if !ok {
- return nil, fmt.Errorf("Content type %s does not implement content.Sluggable.", typeName)
+ return nil, fmt.Errorf("Content type %s does not implement item.Sluggable.", typeName)
}
m := manager{
diff --git a/management/manager/process.go b/management/manager/process.go
deleted file mode 100644
index ad6da94..0000000
--- a/management/manager/process.go
+++ /dev/null
@@ -1,72 +0,0 @@
-package manager
-
-import (
- "regexp"
- "strings"
- "unicode"
-
- "github.com/bosssauce/ponzu/content"
-
- "golang.org/x/text/transform"
- "golang.org/x/text/unicode/norm"
-)
-
-// Slug returns a URL friendly string from the title of a post item
-func Slug(i content.Identifiable) (string, error) {
- // get the name of the post item
- name := strings.TrimSpace(i.String())
-
- // filter out non-alphanumeric character or non-whitespace
- slug, err := stringToSlug(name)
- if err != nil {
- return "", err
- }
-
- return slug, nil
-}
-
-func isMn(r rune) bool {
- return unicode.Is(unicode.Mn, r) // Mn: nonspacing marks
-}
-
-// modified version of: https://www.socketloop.com/tutorials/golang-format-strings-to-seo-friendly-url-example
-func stringToSlug(s string) (string, error) {
- src := []byte(strings.ToLower(s))
-
- // convert all spaces to dash
- rx := regexp.MustCompile("[[:space:]]")
- src = rx.ReplaceAll(src, []byte("-"))
-
- // remove all blanks such as tab
- rx = regexp.MustCompile("[[:blank:]]")
- src = rx.ReplaceAll(src, []byte(""))
-
- rx = regexp.MustCompile("[!/:-@[-`{-~]")
- src = rx.ReplaceAll(src, []byte(""))
-
- rx = regexp.MustCompile("/[^\x20-\x7F]/")
- src = rx.ReplaceAll(src, []byte(""))
-
- rx = regexp.MustCompile("`&(amp;)?#?[a-z0-9]+;`i")
- src = rx.ReplaceAll(src, []byte("-"))
-
- rx = regexp.MustCompile("`&([a-z])(acute|uml|circ|grave|ring|cedil|slash|tilde|caron|lig|quot|rsquo);`i")
- src = rx.ReplaceAll(src, []byte("\\1"))
-
- rx = regexp.MustCompile("`[^a-z0-9]`i")
- src = rx.ReplaceAll(src, []byte("-"))
-
- rx = regexp.MustCompile("`[-]+`")
- src = rx.ReplaceAll(src, []byte("-"))
-
- str := strings.Replace(string(src), "'", "", -1)
- str = strings.Replace(str, `"`, "", -1)
-
- t := transform.Chain(norm.NFD, transform.RemoveFunc(isMn), norm.NFC)
- slug, _, err := transform.String(t, str)
- if err != nil {
- return "", err
- }
-
- return strings.TrimSpace(slug), nil
-}