Skip to content

Commit

Permalink
Fix align
Browse files Browse the repository at this point in the history
  • Loading branch information
bep committed Jan 1, 2022
1 parent 134c239 commit 2406e8d
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 18 deletions.
10 changes: 8 additions & 2 deletions hugolib/hugo_sites_rebuild_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,12 @@ CONTENT
Shortcode: {{< d >}}
-- content/blog/p4.md --
Shortcode: {{< d >}}
-- content/blog/p5.md --
Shortcode: {{< d >}}
-- content/blog/p6.md --
Shortcode: {{< d >}}
-- content/blog/p7.md --
Shortcode: {{< d >}}
-- layouts/_default/single.html --
{{ .Pathc }}: {{ .Content }}
-- layouts/shortcodes/c.html --
Expand All @@ -193,13 +199,13 @@ MYPARTIAL
},
).Build()

b.AssertRenderCountPage(4)
b.AssertRenderCountPage(7)
b.AssertFileContent("public/blog/p1/index.html", `/blog/p1: <p>Shortcode: MYPARTIAL`)
b.AssertFileContent("public/blog/p3/index.html", `/blog/p3: <p>Shortcode: MYPARTIAL`)

b.EditFiles("layouts/partials/p.html", "MYPARTIAL CHANGED").Build()

b.AssertRenderCountPage(3)
b.AssertRenderCountPage(6)
b.AssertFileContent("public/blog/p1/index.html", `/blog/p1: <p>Shortcode: MYPARTIAL CHANGED`)
b.AssertFileContent("public/blog/p3/index.html", `/blog/p3: <p>Shortcode: MYPARTIAL CHANGED`)
b.AssertFileContent("public/blog/p4/index.html", `/blog/p4: <p>Shortcode: MYPARTIAL CHANGED`)
Expand Down
6 changes: 6 additions & 0 deletions hugolib/shortcode.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"sync"

"github.com/gohugoio/hugo/helpers"
"github.com/gohugoio/hugo/identity"

"github.com/gohugoio/hugo/common/herrors"
"github.com/pkg/errors"
Expand Down Expand Up @@ -154,6 +155,11 @@ func (scp *ShortcodeWithPage) Page() page.Page {
return scp.page
}

// TODO1
func (scp *ShortcodeWithPage) GetDependencyManager() identity.Manager {
return scp.Page().GetDependencyManager()
}

// Note - this value must not contain any markup syntax
const shortcodePlaceholderPrefix = "HAHAHUGOSHORTCODE"

Expand Down
3 changes: 0 additions & 3 deletions hugolib/site.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import (
"time"

"github.com/gohugoio/hugo/cache/memcache"
"github.com/gohugoio/hugo/htesting"

"github.com/gohugoio/hugo/common/types"

Expand Down Expand Up @@ -1058,8 +1057,6 @@ func (s *Site) processPartial(config *BuildCfg, init func(config *BuildCfg) erro
events = s.filterFileEvents(events)
events = s.translateFileEvents(events)

htesting.Println("PROC", events)

h := s.h

var (
Expand Down
6 changes: 3 additions & 3 deletions lazy/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ func New() *Init {

// Init holds a graph of lazily initialized dependencies.
type Init struct {
// Used in tests
initCount uint64

mu sync.Mutex

prev *Init
Expand All @@ -38,9 +41,6 @@ type Init struct {
out interface{}
err error
f func() (interface{}, error)

// Use in tests
initCount uint64
}

// Add adds a func as a new child dependency.
Expand Down
34 changes: 24 additions & 10 deletions tpl/partials/partials.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,21 +46,26 @@ type partialCacheKey struct {
variant interface{}
}

type partialCacheEntry struct {
templateIdentity identity.Identity
v interface{}
}

// partialCache represents a cache of partials protected by a mutex.
type partialCache struct {
sync.RWMutex
p map[partialCacheKey]interface{}
p map[partialCacheKey]partialCacheEntry
}

func (p *partialCache) clear() {
p.Lock()
defer p.Unlock()
p.p = make(map[partialCacheKey]interface{})
p.p = make(map[partialCacheKey]partialCacheEntry)
}

// New returns a new instance of the templates-namespaced template functions.
func New(deps *deps.Deps) *Namespace {
cache := &partialCache{p: make(map[partialCacheKey]interface{})}
cache := &partialCache{p: make(map[partialCacheKey]partialCacheEntry)}
deps.BuildStartListeners.Add(
func() {
cache.clear()
Expand Down Expand Up @@ -102,7 +107,6 @@ func (ns *Namespace) Include(ctx context.Context, name string, dataList ...inter
}
if ns.deps.Running {
// Track the usage of this partial so we know when to re-render pages using it.
// TODO1 test case for partialCached.
tpl.AddIdentiesToDataContext(ctx, id)
}
return v, nil
Expand Down Expand Up @@ -187,7 +191,12 @@ func (ns *Namespace) IncludeCached(ctx context.Context, name string, data interf
result, err = ns.getOrCreate(ctx, key, data)
}

return result, err
if ns.deps.Running {
// Track the usage of this partial so we know when to re-render pages using it.
tpl.AddIdentiesToDataContext(ctx, result.templateIdentity)
}

return result.v, err
}

func createKey(name string, variants ...interface{}) (partialCacheKey, error) {
Expand All @@ -213,7 +222,7 @@ func createKey(name string, variants ...interface{}) (partialCacheKey, error) {

var errUnHashable = errors.New("unhashable")

func (ns *Namespace) getOrCreate(ctx context.Context, key partialCacheKey, dot interface{}) (result interface{}, err error) {
func (ns *Namespace) getOrCreate(ctx context.Context, key partialCacheKey, dot interface{}) (pe partialCacheEntry, err error) {
defer func() {
if r := recover(); r != nil {
err = r.(error)
Expand All @@ -233,9 +242,9 @@ func (ns *Namespace) getOrCreate(ctx context.Context, key partialCacheKey, dot i
return p, nil
}

p, err = ns.Include(ctx, key.name, dot)
v, id, err := ns.include(ctx, key.name, dot)
if err != nil {
return nil, err
return
}

ns.cachedPartials.Lock()
Expand All @@ -244,7 +253,12 @@ func (ns *Namespace) getOrCreate(ctx context.Context, key partialCacheKey, dot i
if p2, ok := ns.cachedPartials.p[key]; ok {
return p2, nil
}
ns.cachedPartials.p[key] = p

return p, nil
pe = partialCacheEntry{
templateIdentity: id,
v: v,
}
ns.cachedPartials.p[key] = pe

return
}
3 changes: 3 additions & 0 deletions tpl/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,9 @@ func GetDataFromContext(ctx context.Context) interface{} {
// AddIdentiesToDataContext adds the identities found in v to the
// DependencyManager found in ctx.
func AddIdentiesToDataContext(ctx context.Context, v interface{}) {
if v == nil {
return
}
if dot := GetDataFromContext(ctx); dot != nil {
if dp, ok := dot.(identity.DependencyManagerProvider); ok {
idm := dp.GetDependencyManager()
Expand Down

0 comments on commit 2406e8d

Please sign in to comment.