Skip to content
Snippets Groups Projects
Select Git revision
  • e2d1d058d16523fef03779a9a4d35c36fdd7cc4b
  • main default protected
  • libquassel-migration
  • wip
  • ChenZhangg-Modify_GRADLE_1
  • jetpack-compose-rewrite
  • demo-jump-in-history
  • attachments
  • 1.7.0 protected
  • 1.6.2 protected
  • 1.6.1 protected
  • 1.6.0 protected
  • 1.5.3 protected
  • 1.5.2 protected
  • 1.5.1 protected
  • 1.5.0 protected
  • 1.4.4 protected
  • 1.4.3 protected
  • 1.4.2 protected
  • 1.4.1 protected
  • 1.4.0 protected
  • v1.3.3 protected
  • v1.3.2 protected
  • v1.3.1 protected
  • v1.3.0 protected
  • v1.2.28 protected
  • v1.2.27 protected
  • v1.2.26 protected
28 results

proguard-rules.pro

  • template.go 1022 B
    package cachet
    
    import (
    	"bytes"
    	"text/template"
    )
    
    type MessageTemplate struct {
    	Subject string `json:"subject"`
    	Message string `json:"message"`
    
    	subjectTpl *template.Template
    	messageTpl *template.Template
    }
    
    func (t *MessageTemplate) SetDefault(d MessageTemplate) {
    	if len(t.Subject) == 0 {
    		t.Subject = d.Subject
    	}
    	if len(t.Message) == 0 {
    		t.Message = d.Message
    	}
    }
    
    func (t *MessageTemplate) Compile() error {
    	var err error
    
    	if len(t.Subject) > 0 {
    		t.subjectTpl, err = compileTemplate(t.Subject)
    	}
    
    	if err != nil && len(t.Message) > 0 {
    		t.messageTpl, err = compileTemplate(t.Message)
    	}
    
    	return err
    }
    
    func (t *MessageTemplate) Exec(data interface{}) (string, string) {
    	return t.exec(t.subjectTpl, data), t.exec(t.messageTpl, data)
    }
    
    func (t *MessageTemplate) exec(tpl *template.Template, data interface{}) string {
    	buf := new(bytes.Buffer)
    
    	tpl.Execute(buf, data)
    	return buf.String()
    }
    
    func compileTemplate(text string) (*template.Template, error) {
    	return template.New("").Parse(text)
    }