Joker / jade

Jade.go - pug template engine for Go (golang)
BSD 3-Clause "New" or "Revised" License
354 stars 37 forks source link

Bare mixins declaration causes compilation error #40

Closed kolotaev closed 3 years ago

kolotaev commented 3 years ago

Hello,

I have the following case. All my mixins are declared in a separate file mixins.pug:

mixin pet(name='')
  p.pet= name

And used in other parts of my templates. Like (nothing fancy here):

include mixins.pug
doctype html
html(lang='en')
  head Test
  body
    +pet('Cat')

The problem is that mixins.pug is compiled into this go-code:

// Code generated by "jade.go"; DO NOT EDIT.

package pug

import (
    "io"
)

const ()

func Jade_mixins(wr io.Writer) {
    buffer := &WriterAsBuffer{wr}

}

And is causing a standard golang compilation error for such cases:

mixins.pug.go:12:2: buffer declared but not used

The only workaround is to add some no-op tag or an HTML comment into mixins.pug. But this introduces an unnecessary clutter in the resulting HTML code.

Is there a way to detect such cases upon generation and produce no-op code like _ = &WriterAsBuffer{wr} or simply skip generation of such container-files at all?

Thanks!

kolotaev commented 3 years ago

👍 Thank you for the fix.