Skip to content

Commit

Permalink
rename struct from gokoku to Tmpl
Browse files Browse the repository at this point in the history
  • Loading branch information
Songmu committed Mar 3, 2019
1 parent 1621d46 commit fccc146
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
15 changes: 8 additions & 7 deletions gokoku.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@ import (
"golang.org/x/xerrors"
)

type gokoku struct {
// Tmpl is a struct for scaffolding
type Tmpl struct {
IncludeVCSDir, ExcludeDotDir bool
Suffix string
}

var defaultGokoku = &gokoku{}
var defaultGokoku = &Tmpl{}

// Logger is replaceable logger
var Logger *log.Logger
Expand All @@ -37,7 +38,7 @@ func Scaffold(hfs http.FileSystem, root, dst string, data interface{}) error {
}

// Scaffold directory from http.FileSystem
func (gkk *gokoku) Scaffold(
func (tpl *Tmpl) Scaffold(
hfs http.FileSystem,
root, dst string,
data interface{}) error {
Expand All @@ -47,13 +48,13 @@ func (gkk *gokoku) Scaffold(
}
if fi.IsDir() {
fname := fi.Name()
if !gkk.IncludeVCSDir {
if !tpl.IncludeVCSDir {
switch fname {
case ".git", ".bzr", ".fossil", ".hg", ".svn":
return filepath.SkipDir
}
}
if gkk.ExcludeDotDir && strings.HasPrefix(fname, ".") {
if tpl.ExcludeDotDir && strings.HasPrefix(fname, ".") {
return filepath.SkipDir
}
return nil
Expand All @@ -75,9 +76,9 @@ func (gkk *gokoku) Scaffold(
return xerrors.Errorf("failed to scaffold while MkdirAll of %q: %w",
dstPath, err)
}
isTmpl := strings.HasSuffix(dstPath, gkk.Suffix)
isTmpl := strings.HasSuffix(dstPath, tpl.Suffix)
if isTmpl {
dstPath = strings.TrimSuffix(dstPath, gkk.Suffix)
dstPath = strings.TrimSuffix(dstPath, tpl.Suffix)
}
err = func() (rerr error) {
logf("Writing %s\n", dstPath)
Expand Down
4 changes: 2 additions & 2 deletions scaffold_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ func TestGokoku_Scaffold(t *testing.T) {
tdir := tempd(t)
defer os.RemoveAll(tdir)

gkk := &gokoku{Suffix: ".tmpl"}
err := gkk.Scaffold(http.Dir("testdata/basic-suffix"), ".", tdir, testdata)
tpl := &Tmpl{Suffix: ".tmpl"}
err := tpl.Scaffold(http.Dir("testdata/basic-suffix"), ".", tdir, testdata)
if err != nil {
t.Errorf("something went wrong: %s", err)
}
Expand Down

0 comments on commit fccc146

Please sign in to comment.