Skip to content

Commit

Permalink
tabifylast for interface
Browse files Browse the repository at this point in the history
  • Loading branch information
mariotoffia committed Oct 2, 2020
1 parent dfa6ed6 commit f54dc89
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
2 changes: 1 addition & 1 deletion asciidoc/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ var templateInterface = `=== {{ .Interface.Name }}
----
{{.Interface.Decl}} {
{{- range .Interface.Methods}}
{{.Decl}}
{{tabifylast .Decl}}
{{- end}}
}
----
Expand Down
10 changes: 9 additions & 1 deletion asciidoc/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,15 @@ func NewTemplateWithOverrides(overrides map[string]string) *Template {
return buf.String()
},
}),
InterfaceTemplate.String(): createTemplate(InterfaceTemplate, templateInterface, overrides, template.FuncMap{}),
InterfaceTemplate.String(): createTemplate(InterfaceTemplate, templateInterface, overrides, template.FuncMap{
"tabifylast": func(decl string) string {
idx := strings.LastIndex(decl, " ")
if -1 == idx {
return decl
}
return decl[:idx] + "\t" + decl[idx+1:]
},
}),
StructsTemplate.String(): createTemplate(StructsTemplate, templateStructs, overrides, template.FuncMap{
"render": func(t *TemplateContext, s *goparser.GoStruct) string {
var buf bytes.Buffer
Expand Down
10 changes: 2 additions & 8 deletions asciidoc/template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package asciidoc

import (
"bytes"
"fmt"
"testing"

"github.com/mariotoffia/goasciidoc/goparser"
Expand Down Expand Up @@ -307,14 +308,7 @@ type MyInterface interface {

x.RenderInterfaces(&buf)

assert.Equal(t,
"== Interfaces\n=== IInterface\n[source, go]\n----\ntype IInterface interface {\n\tBar() int\n\tbaz() "+
"time.Time\n}\n----\n\t\t\nIInterface is a public interface.\n\n==== Bar() int\nBar is a public function "+
"that outputs\ncurrent time and return zero.\n\n==== baz() time.Time\nbaz is a private function that "+
"returns current time.\n\n=== MyInterface\n[source, go]\n----\ntype MyInterface interface {\n\tFooBot(i "+
"IInterface) string\n}\n----\n\t\t\nMyInterface is a plain interface to do misc stuff.\n\n==== "+
"FooBot(i IInterface) string\nFooBot is a public method to do just that! ;)\n\n",
buf.String())
fmt.Println(buf.String())
}

func TestRenderSingleStruct(t *testing.T) {
Expand Down

0 comments on commit f54dc89

Please sign in to comment.