Skip to content
Permalink
Browse files

Create lightweight forks of text/template and html/template

This commit also removes support for Ace and Amber templates.

Updates #6594
  • Loading branch information
bep committed Dec 10, 2019
1 parent 4c80431 commit 167c01530bb295c8b8d35921eb27ffa5bee76dfe
Showing with 17,792 additions and 264 deletions.
  1. +2 −1 .gitignore
  2. +1 −3 go.mod
  3. +0 −22 go.sum
  4. +3 −13 hugolib/case_insensitive_test.go
  5. +3 −15 hugolib/template_engines_test.go
  6. +1 −1 magefile.go
  7. +4 −9 output/layout_base.go
  8. +1 −0 scripts/fork_go_templates/.gitignore
  9. +207 −0 scripts/fork_go_templates/main.go
  10. +1 −0 tpl/cast/cast_test.go
  11. +1 −0 tpl/collections/collections.go
  12. +1 −0 tpl/collections/collections_test.go
  13. +11 −0 tpl/internal/go_templates/fmtsort/export_test.go
  14. +216 −0 tpl/internal/go_templates/fmtsort/sort.go
  15. +246 −0 tpl/internal/go_templates/fmtsort/sort_test.go
  16. +175 −0 tpl/internal/go_templates/htmltemplate/attr.go
  17. +16 −0 tpl/internal/go_templates/htmltemplate/attr_string.go
  18. +282 −0 tpl/internal/go_templates/htmltemplate/clone_test.go
  19. +102 −0 tpl/internal/go_templates/htmltemplate/content.go
  20. +461 −0 tpl/internal/go_templates/htmltemplate/content_test.go
  21. +258 −0 tpl/internal/go_templates/htmltemplate/context.go
  22. +260 −0 tpl/internal/go_templates/htmltemplate/css.go
  23. +283 −0 tpl/internal/go_templates/htmltemplate/css_test.go
  24. +16 −0 tpl/internal/go_templates/htmltemplate/delim_string.go
  25. +196 −0 tpl/internal/go_templates/htmltemplate/doc.go
  26. +16 −0 tpl/internal/go_templates/htmltemplate/element_string.go
  27. +234 −0 tpl/internal/go_templates/htmltemplate/error.go
  28. +891 −0 tpl/internal/go_templates/htmltemplate/escape.go
  29. +1,973 −0 tpl/internal/go_templates/htmltemplate/escape_test.go
  30. +184 −0 tpl/internal/go_templates/htmltemplate/example_test.go
  31. +229 −0 tpl/internal/go_templates/htmltemplate/examplefiles_test.go
  32. +266 −0 tpl/internal/go_templates/htmltemplate/html.go
  33. +99 −0 tpl/internal/go_templates/htmltemplate/html_test.go
  34. +33 −0 tpl/internal/go_templates/htmltemplate/hugo_template.go
  35. +418 −0 tpl/internal/go_templates/htmltemplate/js.go
  36. +425 −0 tpl/internal/go_templates/htmltemplate/js_test.go
  37. +16 −0 tpl/internal/go_templates/htmltemplate/jsctx_string.go
  38. +16 −0 tpl/internal/go_templates/htmltemplate/state_string.go
  39. +491 −0 tpl/internal/go_templates/htmltemplate/template.go
  40. +166 −0 tpl/internal/go_templates/htmltemplate/template_test.go
  41. +592 −0 tpl/internal/go_templates/htmltemplate/transition.go
  42. +62 −0 tpl/internal/go_templates/htmltemplate/transition_test.go
  43. +219 −0 tpl/internal/go_templates/htmltemplate/url.go
  44. +171 −0 tpl/internal/go_templates/htmltemplate/url_test.go
  45. +16 −0 tpl/internal/go_templates/htmltemplate/urlpart_string.go
  46. +456 −0 tpl/internal/go_templates/texttemplate/doc.go
  47. +112 −0 tpl/internal/go_templates/texttemplate/example_test.go
  48. +184 −0 tpl/internal/go_templates/texttemplate/examplefiles_test.go
  49. +56 −0 tpl/internal/go_templates/texttemplate/examplefunc_test.go
  50. +980 −0 tpl/internal/go_templates/texttemplate/exec.go
  51. +1,624 −0 tpl/internal/go_templates/texttemplate/exec_test.go
  52. +741 −0 tpl/internal/go_templates/texttemplate/funcs.go
  53. +130 −0 tpl/internal/go_templates/texttemplate/helper.go
  54. +38 −0 tpl/internal/go_templates/texttemplate/hugo_exec.go
  55. +85 −0 tpl/internal/go_templates/texttemplate/hugo_template.go
  56. +425 −0 tpl/internal/go_templates/texttemplate/multi_test.go
  57. +74 −0 tpl/internal/go_templates/texttemplate/option.go
  58. +666 −0 tpl/internal/go_templates/texttemplate/parse/lex.go
  59. +556 −0 tpl/internal/go_templates/texttemplate/parse/lex_test.go
  60. +841 −0 tpl/internal/go_templates/texttemplate/parse/node.go
  61. +736 −0 tpl/internal/go_templates/texttemplate/parse/parse.go
  62. +557 −0 tpl/internal/go_templates/texttemplate/parse/parse_test.go
  63. +228 −0 tpl/internal/go_templates/texttemplate/template.go
  64. +2 −0 tpl/internal/go_templates/texttemplate/testdata/file1.tmpl
  65. +2 −0 tpl/internal/go_templates/texttemplate/testdata/file2.tmpl
  66. +3 −0 tpl/internal/go_templates/texttemplate/testdata/tmpl1.tmpl
  67. +3 −0 tpl/internal/go_templates/texttemplate/testdata/tmpl2.tmpl
  68. +2 −1 tpl/partials/partials.go
  69. +1 −0 tpl/safe/safe_test.go
  70. +1 −0 tpl/strings/strings.go
  71. +1 −0 tpl/strings/strings_test.go
  72. +1 −0 tpl/strings/truncate.go
  73. +1 −0 tpl/strings/truncate_test.go
  74. +4 −3 tpl/template.go
  75. +0 −1 tpl/template_test.go
  76. +0 −71 tpl/tplimpl/ace.go
  77. +0 −47 tpl/tplimpl/amber_compiler.go
  78. +9 −73 tpl/tplimpl/template.go
  79. +5 −3 tpl/tplimpl/template_ast_transformers.go
  80. +2 −1 tpl/tplimpl/template_ast_transformers_test.go
  81. +1 −0 tpl/transform/transform_test.go
  82. +1 −0 tpl/urls/urls.go
@@ -22,4 +22,5 @@ dist

resources/sunset.jpg

vendor
vendor

4 go.mod
@@ -16,7 +16,6 @@ require (
github.com/disintegration/gift v1.2.1
github.com/dlclark/regexp2 v1.2.0 // indirect
github.com/dustin/go-humanize v1.0.0
github.com/eknkc/amber v0.0.0-20171010120322-cdade1c07385
github.com/fortytw2/leaktest v1.3.0
github.com/frankban/quicktest v1.6.0
github.com/fsnotify/fsnotify v1.4.7
@@ -53,8 +52,7 @@ require (
github.com/spf13/pflag v1.0.3
github.com/spf13/viper v1.4.0
github.com/tdewolff/minify/v2 v2.6.1
github.com/yosssi/ace v0.0.5
github.com/yuin/goldmark v1.1.14
github.com/yuin/goldmark v1.1.11

This comment has been minimized.

Copy link
@aletson

aletson Dec 12, 2019

Was this version rollback for Goldmark intended?

This comment has been minimized.

Copy link
@bep

bep Dec 12, 2019

Author Member

No it wasnt, good catch, thanks. I will fix.

github.com/yuin/goldmark-highlighting v0.0.0-20191202084645-78f32c8dd6d5
go.opencensus.io v0.22.0 // indirect
gocloud.dev v0.15.0
22 go.sum
@@ -108,8 +108,6 @@ github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25Kn
github.com/eapache/go-resiliency v1.1.0/go.mod h1:kFI+JgMyC7bLPUVY133qvEBtVayf5mFgVsvEsIPBvNs=
github.com/eapache/go-xerial-snappy v0.0.0-20180814174437-776d5712da21/go.mod h1:+020luEh2TKB4/GOp8oxxtq0Daoen/Cii55CzbTV6DU=
github.com/eapache/queue v1.1.0/go.mod h1:6eCeP0CKFpHLu8blIFXhExK/dRa7WDZfr6jVFPTqq+I=
github.com/eknkc/amber v0.0.0-20171010120322-cdade1c07385 h1:clC1lXBpe2kTj2VHdaIu9ajZQe4kcEY9j0NsnDDBZ3o=
github.com/eknkc/amber v0.0.0-20171010120322-cdade1c07385/go.mod h1:0vRUJqYpeSZifjYj7uP3BG/gKcuzL9xWVV/Y+cK33KM=
github.com/fortytw2/leaktest v1.2.0 h1:cj6GCiwJDH7l3tMHLjZDo0QqPtrXJiWSI9JgpeQKw+Q=
github.com/fortytw2/leaktest v1.2.0/go.mod h1:jDsjWgpAGjm2CA7WthBh/CdZYEPF31XHquHwclZch5g=
github.com/fortytw2/leaktest v1.3.0 h1:u8491cBMTQ8ft8aeV+adlcytMZylmA5nnwwkRZjI8vw=
@@ -322,16 +320,10 @@ github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/tdewolff/minify/v2 v2.5.2 h1:If/q1brvT+91oWiWnIMEGuFcwWtpB6AtLTxba78tvMs=
github.com/tdewolff/minify/v2 v2.5.2/go.mod h1:Q6mWHrmspbdRX0ZuUUoKIT8bDjVVXpIJ73ux7p7HZGg=
github.com/tdewolff/minify/v2 v2.6.1 h1:UJLhbs2Q/iDrqA79EEyKE48uYHeAMPVdiUzdtKsatJ8=
github.com/tdewolff/minify/v2 v2.6.1/go.mod h1:l9hbQnH096st77OkscoRUvKdd23oUM6pDZpYx381sPo=
github.com/tdewolff/parse/v2 v2.3.9 h1:d8/K6XOLy5JVpLTG9Kx+SxA72rlm5OowFmVSVgtOlmM=
github.com/tdewolff/parse/v2 v2.3.9/go.mod h1:HansaqmN4I/U7L6/tUp0NcwT2tFO0F4EAWYGSDzkYNk=
github.com/tdewolff/parse/v2 v2.3.14 h1:Tzam5YoUXx7gybFEfR/zcuR74PXADnrfUqYUXL+K5oA=
github.com/tdewolff/parse/v2 v2.3.14/go.mod h1:+V2lSZ93xpH2Csfs/vtNY1Fjr8kcFMsZKjyLoSkZbM0=
github.com/tdewolff/test v1.0.0 h1:jOwzqCXr5ePXEPGJaq2ivoR6HOCi+D5TPfpoyg8yvmU=
github.com/tdewolff/test v1.0.0/go.mod h1:DiQUlutnqlEvdvhSn2LPGy4TFwRauAaYDsL+683RNX4=
github.com/tdewolff/test v1.0.4 h1:ih38SXuQJ32Hng5EtSW32xqEsVeMnPp6nNNRPhBBDE8=
github.com/tdewolff/test v1.0.4/go.mod h1:6DAvZliBAAnD7rhVgwaM7DE5/d9NMOAJ09SqYqeK4QE=
github.com/tidwall/pretty v0.0.0-20190325153808-1166b9ac2b65/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=
@@ -349,24 +341,10 @@ github.com/xdg/scram v0.0.0-20180814205039-7eeb5667e42c/go.mod h1:lB8K/P019DLNhe
github.com/xdg/stringprep v1.0.0/go.mod h1:Jhud4/sHMO4oL310DaZAKk9ZaJ08SJfe+sJh0HrGL1Y=
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU=
github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q=
github.com/yosssi/ace v0.0.5 h1:tUkIP/BLdKqrlrPwcmH0shwEEhTRHoGnc1wFIWmaBUA=
github.com/yosssi/ace v0.0.5/go.mod h1:ALfIzm2vT7t5ZE7uoIZqF3TQ7SAOyupFZnkrF5id+K0=
github.com/yuin/goldmark v1.1.5 h1:JJy3EDke+PMI2WcFIU6SdaeiP6FgRGK5NKAiPZHiOoE=
github.com/yuin/goldmark v1.1.5/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.1.7 h1:XiwWADvxJeIM1JbXqthrEhDc19hTMui+o+QaY1hGXlk=
github.com/yuin/goldmark v1.1.7/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.1.8 h1:d0m8Ac9JaetYjPZLC4P4W32ac7I0lpJpQbvxZtFqBoM=
github.com/yuin/goldmark v1.1.8/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.1.10 h1:bg3TC1aj4DbjGdhvjSSffGfAgVUdBEIpccuCozwOYWo=
github.com/yuin/goldmark v1.1.10/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.1.11 h1:OO08ilczi3F4swaYWPB99s08WRxP9DdLBemiLFQ6vCo=
github.com/yuin/goldmark v1.1.11/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.1.14 h1:9/OvYI+gdtQ5EAZY0y4kuVnuKjlE03BRqTw/njWYRNo=
github.com/yuin/goldmark v1.1.14/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark-highlighting v0.0.0-20191124122839-ede94e40cc3a h1:L7FTUnbc0WEBqGWgjbx4sPNAOX1/q5W/3KCD6g8XkKo=
github.com/yuin/goldmark-highlighting v0.0.0-20191124122839-ede94e40cc3a/go.mod h1:1gshkGdH4gcrIH5MGSScGH42rOOCO+4Ks6acjAkA9C0=
github.com/yuin/goldmark-highlighting v0.0.0-20191126180129-d7a4bf4d7ea4 h1:vI4Jv29V1cMPqetuLPMW1CMB9xNgxsHVBo8Mid6bwH8=
github.com/yuin/goldmark-highlighting v0.0.0-20191126180129-d7a4bf4d7ea4/go.mod h1:4QGn5rJFOASBa2uK4Q2h3BRTyJqRfsAucPFIipSTcaM=
github.com/yuin/goldmark-highlighting v0.0.0-20191202084645-78f32c8dd6d5 h1:QbH7ca1qtgZHrzvcVAEoiJIwBqrXxMOfHYfwZIniIK0=
github.com/yuin/goldmark-highlighting v0.0.0-20191202084645-78f32c8dd6d5/go.mod h1:4QGn5rJFOASBa2uK4Q2h3BRTyJqRfsAucPFIipSTcaM=
go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU=
@@ -16,7 +16,6 @@ package hugolib
import (
"fmt"
"path/filepath"
"strings"
"testing"

"github.com/gohugoio/hugo/hugofs"
@@ -234,30 +233,21 @@ Page2: {{ $page2.Params.ColoR }}
)
}

// TODO1
func TestCaseInsensitiveConfigurationForAllTemplateEngines(t *testing.T) {
t.Parallel()

noOp := func(s string) string {
return s
}

amberFixer := func(s string) string {
fixed := strings.Replace(s, "{{ .Site.Params", "{{ Site.Params", -1)
fixed = strings.Replace(fixed, "{{ .Params", "{{ Params", -1)
fixed = strings.Replace(fixed, ".Content", "Content", -1)
fixed = strings.Replace(fixed, "{{", "#{", -1)
fixed = strings.Replace(fixed, "}}", "}", -1)

return fixed
}

for _, config := range []struct {
suffix string
templateFixer func(s string) string
}{
{"amber", amberFixer},
//{"amber", amberFixer},
{"html", noOp},
{"ace", noOp},
//{"ace", noOp},
} {
doTestCaseInsensitiveConfigurationForTemplateEngine(t, config.suffix, config.templateFixer)

@@ -18,34 +18,22 @@ import (
"path/filepath"
"testing"

"strings"

"github.com/gohugoio/hugo/deps"
)

// TODO1
func TestAllTemplateEngines(t *testing.T) {
noOp := func(s string) string {
return s
}

amberFixer := func(s string) string {
fixed := strings.Replace(s, "{{ .Title", "{{ Title", -1)
fixed = strings.Replace(fixed, ".Content", "Content", -1)
fixed = strings.Replace(fixed, ".IsNamedParams", "IsNamedParams", -1)
fixed = strings.Replace(fixed, "{{", "#{", -1)
fixed = strings.Replace(fixed, "}}", "}", -1)
fixed = strings.Replace(fixed, `title "hello world"`, `title("hello world")`, -1)

return fixed
}

for _, config := range []struct {
suffix string
templateFixer func(s string) string
}{
{"amber", amberFixer},
//{"amber", amberFixer},
{"html", noOp},
{"ace", noOp},
//{"ace", noOp},
} {
config := config
t.Run(config.suffix,
@@ -320,7 +320,7 @@ func runCmd(env map[string]string, cmd string, args ...string) error {
}

func isGoLatest() bool {
return strings.Contains(runtime.Version(), "1.12")
return strings.Contains(runtime.Version(), "1.13")
}

func isCI() bool {
@@ -26,8 +26,7 @@ const (
)

var (
aceTemplateInnerMarkers = [][]byte{[]byte("= content")}
goTemplateInnerMarkers = [][]byte{[]byte("{{define"), []byte("{{ define"), []byte("{{- define"), []byte("{{-define")}
goTemplateInnerMarkers = [][]byte{[]byte("{{define"), []byte("{{ define"), []byte("{{- define"), []byte("{{-define")}
)

// TemplateNames represents a template naming scheme.
@@ -110,8 +109,8 @@ func CreateTemplateNames(d TemplateLookupDescriptor) (TemplateNames, error) {
id.Name = "_text/" + id.Name
}

// Ace and Go templates may have both a base and inner template.
if ext == "amber" || isShorthCodeOrPartial(name) {
// Go templates may have both a base and inner template.
if isShorthCodeOrPartial(name) {
// No base template support
return id, nil
}
@@ -128,10 +127,6 @@ func CreateTemplateNames(d TemplateLookupDescriptor) (TemplateNames, error) {
baseFilename = fmt.Sprintf("%s.%s", baseFileBase, ext)
}

if ext == "ace" {
innerMarkers = aceTemplateInnerMarkers
}

// This may be a view that shouldn't have base template
// Have to look inside it to make sure
needsBase, err := d.ContainsAny(d.RelPath, innerMarkers)
@@ -152,7 +147,7 @@ func CreateTemplateNames(d TemplateLookupDescriptor) (TemplateNames, error) {
pathsToCheck := createPathsToCheck(pathDir, baseFilename, currBaseFilename)

// We may have language code and/or "terms" in the template name. We want the most specific,
// but need to fall back to the baseof.html or baseof.ace if needed.
// but need to fall back to the baseof.html if needed.
// E.g. list-baseof.en.html and list-baseof.terms.en.html
// See #3893, #3856.
baseBaseFilename, currBaseBaseFilename := helpers.Filename(baseFilename), helpers.Filename(currBaseFilename)
@@ -0,0 +1 @@
fork_go_templates

0 comments on commit 167c015

Please sign in to comment.
You can’t perform that action at this time.