Example #1
0
// parse will parse the string into a templateRenderer or return an error if the template
// is malformed.
func (m *mustacheParser) parse(template string) (templateRenderer, error) {
	tpl, err := mustache.ParseString(template)
	if err != nil {
		return nil, err
	}

	return &mustacheRenderer{tpl}, nil
}
Example #2
0
func template(source string) *m.Template {
	t, err := m.ParseString(source)
	if err != nil {
		panic(err)
	}

	return t
}
Example #3
0
func PrintHtml(issues []*Issue) ([]byte, error) {
	var bs []byte
	out := bytes.NewBuffer(bs)
	var tmpl *mustache.Template
	tmpl, err := mustache.ParseString(defaultTemplate)

	if err != nil {
		return out.Bytes(), err
	}
	fmt.Fprintln(out, tmpl.Render(map[string]interface{}{"Issues": issues}))
	return out.Bytes(), err

}
Example #4
0
File: cli.go Project: shiwano/musta
func createTemplate(templateFileName string, templateData string) *mustache.Template {
	if templateFileName != "" {
		template, err := mustache.ParseFile(templateFileName)
		if err != nil {
			Fatalf("Failed to load a template file: ", err)
		}
		return template
	} else if templateData != "" {
		template, err := mustache.ParseString(templateData)
		if err != nil {
			Fatalf("Failed to parse a template data: ", err)
		}
		return template
	} else {
		Fatalf("No template file or template data")
		return nil
	}
}
Example #5
0
	Type   string
}

func NewEvent(author, repo, branch, action, msg, date, ty string) *Event {
	return &Event{
		Author: author,
		Repo:   repo,
		Branch: branch,
		Action: action,
		Msg:    msg,
		Date:   date,
		Type:   ty,
	}
}

var pushTmpl, _ = mustache.ParseString("{{Date}} -- {{Author}} {{Action}} to {{Repo}}/{{Branch}}\n\t{{Msg}}\n")
var pqTmpl, _ = mustache.ParseString("{{Date}} -- {{Author}} {{Action}} Pull Request{{Branch}} to {{Repo}}\n\t{{Msg}}\n")

func (e *Event) String() string {
	m := structs.Map(e)
	if e.Type == "push" {
		return pushTmpl.Render(m)
	}
	if e.Type == "pullrequest" {
		return pqTmpl.Render(m)
	}
	return ""
}

type Server struct {
	Port   int
Example #6
0
package views

import "github.com/hoisie/mustache"

var (
	Add, _    = mustache.ParseString(add)
	Feed, _   = mustache.ParseString(feed)
	Layout, _ = mustache.ParseString(layout)
	List, _   = mustache.ParseString(list)
)