StubbleOrg / Stubble

Trimmed down {{mustache}} templates in .NET
Other
406 stars 58 forks source link

Add Single File Generator for Visual Studio #38

Open gtbuchanan opened 5 years ago

gtbuchanan commented 5 years ago

It's possible to have Visual Studio generate a file on save of another file using a Single File Generator. T4 templates use the built-in TextTemplatingFileGenerator, but I believe other custom generators can be installed by a Visual Studio Extension.

It'd be great to have this functionality with Mustache templates as well.

Getting it working on .NET Standard

Romanx commented 5 years ago

Hi @gtbuchanan,

I don't actually think i've ever used the functionality in visual studio so am not entirely sure what it'd be used for. What would you like the file to be transformed in to, a .cs file? If so i'd probably recommend Scripty over this since it's a much more fully featured tool. I'd be interested in hearing your ideas though.

gtbuchanan commented 5 years ago

@Romanx With T4, the generator functionality is used to automatically create the resulting file when the template is saved in Visual Studio. However, T4 has a built-in construct for defining the output file extension:

<#@ output extension=".cs" #>

After thinking about it a little longer, the following would be required for this to work:

  1. The template would need to define the output file extension. One idea is to require the extension to be in the file name. For example: Glyphicons.cs.mustache
  2. The template would need to know where to get the data to use. This is easy with T4 because you can load files from the template. Not too sure about this one for Mustache. Perhaps it could rely on an accompaning JSON file. For example: Glyphicons.json

I was not aware of Scripty. Considering these things, you might be right about Scripty being a better choice. Though there is a current issue about 3rd party references being a pain.