Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions jade_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,15 @@ type mixinNode struct {
func (t *tree) newMixin(pos pos) *mixinNode {
return &mixinNode{tr: t, nodeType: nodeMixin, pos: pos}
}
func (m *mixinNode) cloneMixin() *mixinNode {
return &mixinNode{
tr: m.tr,
nodeType: nodeMixin,
pos: m.pos,
AttrName: m.AttrName,
AttrCode: m.AttrCode,
}
}

func (l *mixinNode) append(n node) {
l.Nodes = append(l.Nodes, n)
Expand Down Expand Up @@ -630,19 +639,24 @@ func (l *mixinNode) WriteIn(b io.Writer) {
fmt.Fprintf(b, mixin__end)
}

func (l *mixinNode) CopyMixin() *mixinNode {
func (l *mixinNode) CopyMixin(withAttributes bool) *mixinNode {
if l == nil {
return l
}
n := l.tr.newMixin(l.pos)
var n *mixinNode
if withAttributes {
n = l.cloneMixin()
} else {
n = l.tr.newMixin(l.pos)
}
for _, elem := range l.Nodes {
n.append(elem.Copy())
}
return n
}

func (l *mixinNode) Copy() node {
return l.CopyMixin()
return l.CopyMixin(true)
}

//
Expand Down
2 changes: 1 addition & 1 deletion jade_parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ func (t *tree) parseMixinUse(tk item) node {
}
var (
deep = tk.depth
mixin = tMix.CopyMixin()
mixin = tMix.CopyMixin(false)
)
Loop:
for {
Expand Down
16 changes: 16 additions & 0 deletions testdata/v2/mixins.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions testdata/v2/mixins.jade
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,11 @@ mixin list(id, ...items)
//- Use
// TODO for string
+list(fn("my-list"), "string", 2, 3.5, 4)

//- Declaration
mixin inner(bar)
p= bar
mixin outer(foo)
+inner(foo)
//- Use
+outer('My inner paragraph')
3 changes: 3 additions & 0 deletions testdata/v2/mixins.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,6 @@
<li>{{ item }}</li>
{{ end }}
</ul>
{{ $foo := "My inner paragraph" }}
{{ $bar := foo }}
<p>{{ bar }}</p>