vscode-folder-templates icon indicating copy to clipboard operation
vscode-folder-templates copied to clipboard

[Feature Request] Loop through provided custom values.

Open theAdhocracy opened this issue 8 months ago • 0 comments

For generating files that have repetitive subsections, it would be great to have a transform that would loop through and output the same codeblock for each specified input. This would use the existing customVariables option, along with a new settings option for the codeblocks themselves, and then be a different transform with some custom logic. An example might look like this:

// .ftsettings.json
{
   "customVariables": ["schemaOptions=>title,description"],
   "customLoopOutput": [
      {
          "schema": [
             "<FTLoop>: {"
                "title: '<FTLoop | snakecase>',"
                "type: 'document',"
                "required: true,"
             "}"
          ]
      }
   ]
}

Here the customLoopOutput is an array of codeblocks, each with an assignable name, and then the content to input. Within it, the <FTLoop> keyword can be used to clone in whatever the value was, in this case either title or description.

And then in the template file, the transform could be:

...
<schemaOptions | loop(',' , 'schema')
...

So the first argument defines the character to split on (in this case ,) and the second argument names the codeblock defined in the loop output.

This would be incredibly useful for generating files like GraphQL schemas, CMS or Markdown config files, TypeScript files (feeding in props, for instance) etc.

theAdhocracy avatar May 31 '24 11:05 theAdhocracy