Skip to content

Commit

Permalink
Create lightweight forks of text/template and html/template
Browse files Browse the repository at this point in the history
This commit also removes support for Ace and Amber templates.

Updates #6594
  • Loading branch information
bep committed Dec 12, 2019
1 parent 4c80431 commit 167c015
Show file tree
Hide file tree
Showing 82 changed files with 17,792 additions and 264 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ dist

resources/sunset.jpg

vendor
vendor

4 changes: 1 addition & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
22 changes: 0 additions & 22 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down Expand Up @@ -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=
Expand All @@ -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=
Expand Down
16 changes: 3 additions & 13 deletions hugolib/case_insensitive_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ package hugolib
import (
"fmt"
"path/filepath"
"strings"
"testing"

"github.com/gohugoio/hugo/hugofs"
Expand Down Expand Up @@ -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)

Expand Down
18 changes: 3 additions & 15 deletions hugolib/template_engines_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion magefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
13 changes: 4 additions & 9 deletions output/layout_base.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
}
Expand All @@ -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)
Expand All @@ -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)
Expand Down
1 change: 1 addition & 0 deletions scripts/fork_go_templates/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fork_go_templates
Loading

0 comments on commit 167c015

Please sign in to comment.