Skip to content

Commit 212021d

Browse files
committed
fix relative recursive templating without directory as context
1 parent d9f28f2 commit 212021d

3 files changed

Lines changed: 7 additions & 14 deletions

File tree

internals/template/path/operators/default.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package operators
22

33
import (
4-
"path/filepath"
5-
64
"github.com/codeshelldev/goplater/internals/template/context"
75
"github.com/codeshelldev/goplater/internals/template/core"
86
"github.com/codeshelldev/goplater/internals/template/path/types"
@@ -13,12 +11,8 @@ func init() {
1311
Name: "default",
1412
AllowedProtocols: []types.TemplateProtocol{{ Name: "local" },{ Name: "remote" }},
1513
ApplyFunc: func(pathComponent, content string, context context.TemplateContext) (string, context.TemplateContext) {
16-
newContext := context
17-
newContext.Path = filepath.Base(context.Path)
18-
newContext.Invoker = context.Path
19-
20-
if core.Matcher.Match(newContext) {
21-
content, _ = core.Renderer.Render(content, newContext)
14+
if core.Matcher.Match(context) {
15+
content, _ = core.Renderer.Render(content, context)
2216
}
2317

2418
return content, context

internals/template/path/operators/supress.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package operators
22

33
import (
4-
"fmt"
54
"strings"
65

76
"github.com/codeshelldev/goplater/internals/template/context"
@@ -12,9 +11,7 @@ func init() {
1211
Register(types.TemplateOperator{
1312
Name: "supress",
1413
AllowedProtocols: []types.TemplateProtocol{{ Name: "local" },{ Name: "remote" }},
15-
ApplyFunc: func(pathComponent, content string, context context.TemplateContext) (string, context.TemplateContext) {
16-
fmt.Println(context)
17-
14+
ApplyFunc: func(pathComponent, content string, context context.TemplateContext) (string, context.TemplateContext) {
1815
return content, context
1916
},
2017
MatchFunc: func(match string) (bool, string) {

internals/template/path/protocols/local.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,17 @@ func init() {
2020
isRel := strings.HasPrefix(pathComponent, "./") || strings.HasPrefix(pathComponent, "../")
2121

2222
filePathAbs, _ := filepath.Abs(context.Invoker)
23+
24+
relPathComponent := fsutils.Relative(filepath.Dir(filePathAbs), pathComponent)
25+
26+
context.Invoker = relPathComponent
2327

2428
if isRel {
2529
res = fetchutils.Local(pathComponent, filepath.Dir(filePathAbs))
2630
} else {
2731
res = fetchutils.Local(pathComponent, context.Options.Source)
2832
}
2933

30-
pathComponent = fsutils.Relative(filepath.Dir(filePathAbs), pathComponent)
31-
3234
return res, context
3335
},
3436
MatchFunc: func(match string) (bool, string) {

0 commit comments

Comments
 (0)