tailwind
tailwind copied to clipboard
How to use with html/template?
Hi, this looks interesting!
I saw you claim that this works well with go templates, but it isn't immediately obvious to me what that use-case would look like.
Say I have a directory of go template files that uses most of the available features: defines, template invocations, range, if, custom funcs, etc, and I load them all up into a single *template.Template instance. How could I process that object to get the corresponding css for it? Or am I overthinking it and I should just process the template files directly? In that case, how to process multiple files at once?
(As an aside, dynamically setting classes on nodes is possible with html/template, but that makes preprocessing impossible (like, the halting problem hard) so lets ignore that case for the scope of this issue. Such a scenario would have to use a CDN solution to be general.)
Hey @infogulch, I'd probably process the template files directly. The example usage should provide a decent starting point there.
I think you're touching on a limitation with the current API though. We probably want a way to process multiple templates at once. Looking at the underlying Tailwind API (code) this seems possible to pass an array through.
I'm not actively working on this package at the moment, but I'd certainly accept a PR that adds the ability to process multiple files at once!
Since this is pre-1.0, we could either change the API to something like Process(ctx, files...), where file is a File{path, code} or add a new method.