Skip to content

[Feature Request] Loop through provided custom values. #133

Description

@theAdhocracy

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions