clipperhouse / gen

Type-driven code generation for Go
http://clipperhouse.com/gen/overview/
Other
1.43k stars 90 forks source link

{{.name}} Template Variable #95

Open derekdowling opened 8 years ago

derekdowling commented 8 years ago

Hello, I am trying to get up to speed on implementing a TypeWriter based on the Set example. How do you feel about adding a "{{.name}}" template variable which is just the lowercased version of "{{.Name}". Perhaps this is simply a templating problem and there is a way I can do this myself? This is useful for things like:

{{.name}} := &{{.Name}}{}

Alternatively, I could achieve this if there was some sort of function that allows us to inject our own template helpers from the most basic information you provide us such as Pointer, Name, and any other arguments I might be missing. Is there currently a way to do any of these things?

WnP commented 8 years ago

Here is the method to inject your proper helper functions Here is the golang template documentation on custom function And here a good example on how to inject a custom type Read the source Luke ;-)