diff --git a/dumb.go b/dumb.go
index a270f13..9d6cf1d 100644
--- a/dumb.go
+++ b/dumb.go
@@ -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)
diff --git a/lex.go b/lex.go
index bf9f2cb..2e9bf76 100644
--- a/lex.go
+++ b/lex.go
@@ -39,6 +39,7 @@ type TokenSubtype int
const (
IndentKeep = 0
+ IndentKeepNewline = 3
IndentInc = 1
IndentDec = -1
IndentNewlineKeep = 2
@@ -55,7 +56,7 @@ const (
func TokenIndent(s TokenSubtype) int {
switch s {
case Pipe:
- return IndentKeep
+ return IndentKeepNewline
case Block:
return IndentInc
case Define:
@@ -85,7 +86,7 @@ func TokenIndent(s TokenSubtype) int {
case Comment:
return IndentNewlineKeep
}
- return 0
+ return IndentKeep
}
const (
@@ -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.:
+ // {{.}}
+ //
+ // {{ partialCached "head/css.html" . }}
+ // {{ partialCached "head/js.html" . }}
+ //
+ // This is however, not really elegant.
+
+ if len(value) >= 25 {
+ subtype = Pipe
+ }
}
}
}
diff --git a/testdata/multiple-pipes.pretty b/testdata/multiple-pipes.pretty
new file mode 100644
index 0000000..abb0e81
--- /dev/null
+++ b/testdata/multiple-pipes.pretty
@@ -0,0 +1,3 @@
+{{partialCached "head/css.html" .}}
+{{partialCached "head/js.html" .}}
+{{short}}
diff --git a/testdata/multiple-pipes.tmpl b/testdata/multiple-pipes.tmpl
new file mode 100644
index 0000000..6ded0e7
--- /dev/null
+++ b/testdata/multiple-pipes.tmpl
@@ -0,0 +1,4 @@
+{{ partialCached "head/css.html" . }}{{ partialCached "head/js.html" . }}
+
+ {{ short }}
+