Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/pacedotdev/oto
Browse files Browse the repository at this point in the history
  • Loading branch information
matryer committed Feb 23, 2023
2 parents 2cb08ab + e0d5dbc commit 81fd203
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
11 changes: 11 additions & 0 deletions render/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ func Render(template string, def parser.Definition, params map[string]interface{
ctx.Set("format_comment_html", formatCommentHTML)
ctx.Set("format_tags", formatTags)
ctx.Set("object_golang", ObjectGolang)
ctx.Set("smart_prefix", smartPrefix)
s, err := plush.Render(string(template), ctx)
if err != nil {
return "", err
Expand Down Expand Up @@ -81,3 +82,13 @@ func formatTags(tags ...string) (template.HTML, error) {
tagsStr = "`" + tagsStr + "`"
return template.HTML(tagsStr), nil
}

// smartPrefix prepends a string before s, allowing for the specific use
// case of pointers to objects. If the s begins with * (as in, *Object), the
// result will be *prefixObject to preserve its original meaning.
func smartPrefix(prefix, s string) string {
if strings.HasPrefix(s, "*") {
return "*" + prefix + s[1:]
}
return prefix + s
}
11 changes: 11 additions & 0 deletions render/render_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,14 @@ func TestFormatCommentText(t *testing.T) {
is.Equal(actual, `// What about new lines?`)

}

func TestSmartPrefix(t *testing.T) {
is := is.New(t)

actual := smartPrefix("public", "*Object")
is.Equal(actual, "*publicObject")

actual = smartPrefix("public", "Object")
is.Equal(actual, "publicObject")

}

0 comments on commit 81fd203

Please sign in to comment.