Skip to content

Commit

Permalink
Merge pull request #5 from moul/dev/moul/helpers
Browse files Browse the repository at this point in the history
feat: add template helpers
  • Loading branch information
moul authored Sep 8, 2020
2 parents a80a645 + b6ad7e0 commit 53c9e24
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
1 change: 0 additions & 1 deletion go.mod

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 0 additions & 7 deletions go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 12 additions & 1 deletion prefix.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,22 @@ package prefix

import (
"bytes"
"fmt"
"text/template"

"github.com/Masterminds/sprig"
)

const DefaultFormat = `{{printf "%-3d" .LineNumber}} `
/// Public API

const DefaultFormat = `{{.LineNumber3}} `

type LinePrefixer interface {
PrefixLine(string) string
}

/// Main implementation

type linePrefixer struct {
Format string
LineNumber int
Expand Down Expand Up @@ -40,3 +45,9 @@ func (p *linePrefixer) PrefixLine(line string) string {
_ = p.t.Execute(&prefix, p)
return prefix.String() + line
}

/// Template helpers

func (p *linePrefixer) LineNumber3() string { return fmt.Sprintf("%-3d", p.LineNumber) }
func (p *linePrefixer) LineNumber4() string { return fmt.Sprintf("%-4d", p.LineNumber) }
func (p *linePrefixer) LineNumber5() string { return fmt.Sprintf("%-5d", p.LineNumber) }

0 comments on commit 53c9e24

Please sign in to comment.