Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions dumb.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ func PrettyDumb(w io.Writer, tokens []Token) {
level -= 1
case IndentKeep:
fmt.Fprintf(w, "%s", token.Value)
case IndentKeepNewline:
fmt.Fprintf(w, "%s\n", token.Value)
case IndentInc:
fmt.Fprintln(w)
printIndent(w, level)
Expand Down
21 changes: 19 additions & 2 deletions lex.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ type TokenSubtype int

const (
IndentKeep = 0
IndentKeepNewline = 3
IndentInc = 1
IndentDec = -1
IndentNewlineKeep = 2
Expand All @@ -55,7 +56,7 @@ const (
func TokenIndent(s TokenSubtype) int {
switch s {
case Pipe:
return IndentKeep
return IndentKeepNewline
case Block:
return IndentInc
case Define:
Expand Down Expand Up @@ -85,7 +86,7 @@ func TokenIndent(s TokenSubtype) int {
case Comment:
return IndentNewlineKeep
}
return 0
return IndentKeep
}

const (
Expand Down Expand Up @@ -187,6 +188,22 @@ func (l *Lexer) emit(t TokenType) {
case strings.HasPrefix(value, "{{- "+s):
subtype = Subtypes[s]
break Loop

default:
// Quick fix to keep short pipe tokens inline,
// while adding new line after longer ones.
//
// E.g.:
// <span>{{.}}</span>
//
// {{ partialCached "head/css.html" . }}
// {{ partialCached "head/js.html" . }}
//
// This is however, not really elegant.

if len(value) >= 25 {
subtype = Pipe
}
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions testdata/multiple-pipes.pretty
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{{partialCached "head/css.html" .}}
{{partialCached "head/js.html" .}}
<span>{{short}}</span>
4 changes: 4 additions & 0 deletions testdata/multiple-pipes.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{{ partialCached "head/css.html" . }}{{ partialCached "head/js.html" . }}
<span>
{{ short }}
</span>