Refactor and move FirstName LastName functions to the Subscriber model
This commit is contained in:
parent
ae2ca2cb5d
commit
09b7fc8d0c
|
@ -6,6 +6,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"html/template"
|
"html/template"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/jmoiron/sqlx"
|
"github.com/jmoiron/sqlx"
|
||||||
"github.com/jmoiron/sqlx/types"
|
"github.com/jmoiron/sqlx/types"
|
||||||
|
@ -233,3 +234,31 @@ func (c *Campaign) CompileTemplate(f template.FuncMap) error {
|
||||||
c.Tpl = out
|
c.Tpl = out
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FirstName splits the name by spaces and returns the first chunk
|
||||||
|
// of the name that's greater than 2 characters in length, assuming
|
||||||
|
// that it is the subscriber's first name.
|
||||||
|
func (s *Subscriber) FirstName() string {
|
||||||
|
for _, s := range strings.Split(s.Name, " ") {
|
||||||
|
if len(s) > 2 {
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return s.Name
|
||||||
|
}
|
||||||
|
|
||||||
|
// LastName splits the name by spaces and returns the last chunk
|
||||||
|
// of the name that's greater than 2 characters in length, assuming
|
||||||
|
// that it is the subscriber's last name.
|
||||||
|
func (s *Subscriber) LastName() string {
|
||||||
|
chunks := strings.Split(s.Name, " ")
|
||||||
|
for i := len(chunks) - 1; i >= 0; i-- {
|
||||||
|
chunk := chunks[i]
|
||||||
|
if len(chunk) > 2 {
|
||||||
|
return chunk
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return s.Name
|
||||||
|
}
|
||||||
|
|
|
@ -5,7 +5,6 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"html/template"
|
"html/template"
|
||||||
"log"
|
"log"
|
||||||
"strings"
|
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -327,26 +326,6 @@ func (r *Runner) TemplateFuncs(c *models.Campaign) template.FuncMap {
|
||||||
return template.HTML(fmt.Sprintf(`<img src="%s" alt="campaign" />`,
|
return template.HTML(fmt.Sprintf(`<img src="%s" alt="campaign" />`,
|
||||||
fmt.Sprintf(r.cfg.ViewTrackURL, campUUID, subUUID)))
|
fmt.Sprintf(r.cfg.ViewTrackURL, campUUID, subUUID)))
|
||||||
},
|
},
|
||||||
"FirstName": func(name string) string {
|
|
||||||
for _, s := range strings.Split(name, " ") {
|
|
||||||
if len(s) > 2 {
|
|
||||||
return s
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return name
|
|
||||||
},
|
|
||||||
"LastName": func(name string) string {
|
|
||||||
s := strings.Split(name, " ")
|
|
||||||
for i := len(s) - 1; i >= 0; i-- {
|
|
||||||
chunk := s[i]
|
|
||||||
if len(chunk) > 2 {
|
|
||||||
return chunk
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return name
|
|
||||||
},
|
|
||||||
"Date": func(layout string) string {
|
"Date": func(layout string) string {
|
||||||
if layout == "" {
|
if layout == "" {
|
||||||
layout = time.ANSIC
|
layout = time.ANSIC
|
||||||
|
|
1
todo
1
todo
|
@ -1,6 +1,5 @@
|
||||||
- Add quote support to Quill link feature so that Track function can be inserted
|
- Add quote support to Quill link feature so that Track function can be inserted
|
||||||
- Make {{ template }} a Regex check to account for spaces
|
- Make {{ template }} a Regex check to account for spaces
|
||||||
- Clicking on "all subscribers" from a list subscriber view doesn't do anything
|
|
||||||
- Add css inliner
|
- Add css inliner
|
||||||
- Duplicate mails to subscribers in multiple lists under one campaign?
|
- Duplicate mails to subscribers in multiple lists under one campaign?
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue