templating icon indicating copy to clipboard operation
templating copied to clipboard

Duplication of custom operations

Open XomegaNet opened this issue 5 years ago • 6 comments

First of all, neither CustomOperations nor SpecialCustomOperations are included in the json schema, which results in no Intellisense support in VS 2017, and makes them hard to work with.

We need to use conditional processing for XML content in various template files, but, while it works fine for our *proj files, it does not work for .config files out of the box. We had to add special operations for .config files to enable it as follows.

  "SpecialCustomOperations": {
    "**/*.config": {
      "operations": [
        {
          "type": "conditional",
          "configuration": {
            "actionableIf": [ "<!--#if" ],
            "actionableElse": [ "#else", "<!--#else" ],
            "actionableElseif": [ "#elseif", "<!--#elseif", "#elif", "<!--#elif" ],
            "endif": [ "#endif", "<!--#endif" ],
            "trim": "true",
            "wholeLine": "true",
            "actions": [ "fixPseudoNestedComments" ]
          }
        },
        {
          "type": "balancednesting",
          "configuration": {
            "startToken": "<!--",
            "realEndToken": "-->",
            "pseudoEndToken": "-- >",
            "id": "fixPseudoNestedComments",
            "resetFlag": "_TestResetFlag_"
          }
        }
      ]
    },...

However, we also have other files that contain XML with a different extension (*.xom). So, to enable conditional processing for those as well, we had to repeat the same configuration for the **/*.xom pattern, since I don't know how to specify the glob to cover multiple extensions. This results in unnecessary duplication, and bloats the template configuration.

It would be great if the operations could be defined separately under a unique name, and then just referenced by the special custom operations under the respective globs. In this case we would just reference the standard operation to apply it to any additional extensions. Please let me know if there is a better way to define such conditional processing without duplicating configurations.

XomegaNet avatar Mar 04 '19 05:03 XomegaNet

Hello @XomegaNet , can you please confirm this remains something you're interested in?

donJoseLuis avatar Mar 24 '20 17:03 donJoseLuis

Hi @donJoseLuis, yes, sure. Given the limitations of the glob patterns to cover multiple file extensions or any special cases, I think it's important to be able to define reusable configurations for operations to avoid bloating templates with duplicate operations.

XomegaNet avatar Mar 24 '20 20:03 XomegaNet

Exactly what I was looking for. Thank you, @donJoseLuis for bringing this up.

Antoshjkee avatar Apr 23 '20 13:04 Antoshjkee

If we had some sort of an import feature, could that solve it? That would support some places in the ASP.NET templates where blocks of symbols are repeated in different templates (for auth).

In my head it looks like

"import" : "<fileName>",

where the contents of the file would just be dumped into the current location.

I have no idea how hard that would be to build, but it would allow reuse of any type of JSON fragment.

KathleenDollard avatar Apr 13 '21 17:04 KathleenDollard

As a possible solution, we discussed having shorter syntax for it as:

  "SpecialCustomOperations": {
      "inheritsFrom": {
               "**/*.config" : "**/*.xml",
               ...
      }
    },...

where key value pairs are:

  • glob pattern that should inherit the configuration from existing
  • glob pattern to use (should exist either in standard configs or given in template.json)

vlada-shubina avatar May 16 '23 13:05 vlada-shubina

@vlada-shubina I guess this approach should work. Thanks for looking into this.

XomegaNet avatar May 19 '23 02:05 XomegaNet