Add new template functions and rename Track to TrackLink
This commit is contained in:
parent
ad96a4341c
commit
67d65b3a8b
|
@ -50,8 +50,8 @@ const (
|
||||||
// and substituting it with {{ Track "http://link.com" .Campaign.UUID .Subscriber.UUID }}
|
// and substituting it with {{ Track "http://link.com" .Campaign.UUID .Subscriber.UUID }}
|
||||||
// before compilation. This string gimmick is to make linking easier for users.
|
// before compilation. This string gimmick is to make linking easier for users.
|
||||||
var (
|
var (
|
||||||
regexpLinkTag = regexp.MustCompile(`{{(\s+)?Track\s+?"(.+?)"(\s+)?}}`)
|
regexpLinkTag = regexp.MustCompile(`{{(\s+)?TrackLink\s+?"(.+?)"(\s+)?}}`)
|
||||||
regexpLinkTagReplace = `{{ Track "$2" .Campaign.UUID .Subscriber.UUID }}`
|
regexpLinkTagReplace = `{{ TrackLink "$2" .Campaign.UUID .Subscriber.UUID }}`
|
||||||
)
|
)
|
||||||
|
|
||||||
// Base holds common fields shared across models.
|
// Base holds common fields shared across models.
|
||||||
|
|
|
@ -5,6 +5,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"html/template"
|
"html/template"
|
||||||
"log"
|
"log"
|
||||||
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -195,19 +196,8 @@ func (r *Runner) SpawnWorkers() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TemplateFuncs returns the template functions to be applied into
|
|
||||||
// compiled campaign templates.
|
|
||||||
func (r *Runner) TemplateFuncs(c *models.Campaign) template.FuncMap {
|
|
||||||
return template.FuncMap{
|
|
||||||
"Track": func(url, campUUID, subUUID string) string {
|
|
||||||
return r.trackLink(url, campUUID, subUUID)
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// addCampaign adds a campaign to the process queue.
|
// addCampaign adds a campaign to the process queue.
|
||||||
func (r *Runner) addCampaign(c *models.Campaign) error {
|
func (r *Runner) addCampaign(c *models.Campaign) error {
|
||||||
|
|
||||||
// Validate messenger.
|
// Validate messenger.
|
||||||
if _, ok := r.messengers[c.MessengerID]; !ok {
|
if _, ok := r.messengers[c.MessengerID]; !ok {
|
||||||
r.src.CancelCampaign(c.ID)
|
r.src.CancelCampaign(c.ID)
|
||||||
|
@ -324,3 +314,39 @@ func (r *Runner) trackLink(url, campUUID, subUUID string) string {
|
||||||
|
|
||||||
return fmt.Sprintf(r.cfg.LinkTrackURL, uu, campUUID, subUUID)
|
return fmt.Sprintf(r.cfg.LinkTrackURL, uu, campUUID, subUUID)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TemplateFuncs returns the template functions to be applied into
|
||||||
|
// compiled campaign templates.
|
||||||
|
func (r *Runner) TemplateFuncs(c *models.Campaign) template.FuncMap {
|
||||||
|
return template.FuncMap{
|
||||||
|
"TrackLink": func(url, campUUID, subUUID string) string {
|
||||||
|
return r.trackLink(url, 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 {
|
||||||
|
if layout == "" {
|
||||||
|
layout = time.ANSIC
|
||||||
|
}
|
||||||
|
return time.Now().Format(layout)
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue