コード例 #1
0
ファイル: table.go プロジェクト: brnv/croc
func (table Table) String() string {
	myTpl := template.Must(
		template.New("table").Parse(tplutil.Strip(
			tableTpl,
		)),
	)

	buf := bytes.NewBuffer([]byte{})

	myTpl.Execute(buf, table)

	return buf.String()
}
コード例 #2
0
ファイル: changeset_writer.go プロジェクト: kovetskiy/godiff
func init() {
	commentsTpl := template.New("comment")

	reBeginningOfLine := regexp.MustCompile(`(?m)^`)
	reNewLine := regexp.MustCompile(`^|\n`)
	reDanglingSpace := regexp.MustCompile(`(?m)\s+$`)

	funcs := template.FuncMap{
		"indent": func(input string) string {
			return reBeginningOfLine.ReplaceAllString(input, "    ")
		},
		"writeComments": func(input CommentsTree) string {
			res, _ := tplutil.ExecuteToString(commentsTpl, input)
			return res
		},
		"writeNote": func(input string) string {
			return Note(input)
		},
		"trimWhitespace": func(input string) string {
			return strings.TrimSpace(input)
		},
		"comment": func(input string) string {
			//log.Printf("%#v", input)
			return reDanglingSpace.ReplaceAllString(
				reNewLine.ReplaceAllString(input, `$0# `),
				``,
			)
		},
	}

	template.Must(
		commentsTpl.Funcs(funcs).Funcs(tplutil.Last).Parse(
			tplutil.Strip(commentsTplText)))
	template.Must(
		changesetTpl.Funcs(funcs).Funcs(tplutil.Last).Parse(
			tplutil.Strip(changesetTplText)))
}