diff --git a/LICENSE b/LICENSE index 5e9f32f..7aa1d09 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2022 Paul Smith. All rights reserved. +Copyright (c) Paul Smith. All rights reserved. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in diff --git a/main.go b/main.go index dd57367..37e42a2 100644 --- a/main.go +++ b/main.go @@ -1514,9 +1514,11 @@ func (g *pageCodeGen) genNodePartial(n node, p *partial) { g.bodyPrintf("printEscaped(%s, %s)\n", g.ioWriterVar, n.expr) } case *nodeFor: - g.bodyPrintf("for %s {\n", n.clause.code) - f(n.block) - g.bodyPrintf("}\n") + if state == stateInPartialScope { + g.bodyPrintf("for %s {\n", n.clause.code) + f(n.block) + g.bodyPrintf("}\n") + } return false case *nodeIf: g.bodyPrintf("if %s {\n", n.cond.expr) diff --git a/testdata/partial_for.out b/testdata/partial_for.out new file mode 100644 index 0000000..46b0f21 --- /dev/null +++ b/testdata/partial_for.out @@ -0,0 +1,11 @@ + + +

0

+

1

+

2

+ +
+ + 0 + 1 +
diff --git a/testdata/partial_for.up b/testdata/partial_for.up new file mode 100644 index 0000000..07217ec --- /dev/null +++ b/testdata/partial_for.up @@ -0,0 +1,11 @@ +^layout ! +^for i := 0; i < 3; i++ { +

^i

+} +^partial p { +
+ ^for ii := 0; ii < 2; ii++ { + ^ii + } +
+} diff --git a/testdata/partial_for/0.conf b/testdata/partial_for/0.conf new file mode 100644 index 0000000..964f20a --- /dev/null +++ b/testdata/partial_for/0.conf @@ -0,0 +1 @@ +requestPath=/testdata/partial_for/p diff --git a/testdata/partial_for/0.out b/testdata/partial_for/0.out new file mode 100644 index 0000000..0d95d12 --- /dev/null +++ b/testdata/partial_for/0.out @@ -0,0 +1,6 @@ + +
+ + 0 + 1 +
\ No newline at end of file