replace form not working as intended #5085
-
using dotnet v6, I have the following in my template.json {
"sourceName": "MyWebApp",
"symbols": {
"nameUpper": {
"description": "replaces content matching 'MYWEBAPP' to the uppercased '{sourceName}', e.g. sourceName 'Foo.Bar' becomes 'FOO.BAR'",
"type": "generated",
"generator": "casing",
"parameters": {
"source": "name",
"toLower": false
},
"replaces": "MYWEBAPP"
},
"nameUpperSnake": {
"description": "replaces content matching 'MY_WEB_APP' to the uppercased and underscored '{sourceName}', e.g. sourceName 'Foo.Bar' becomes 'FOO_BAR'",
"type": "derived",
"valueSource": "nameUpper",
"valueTransform": "DotToSnake",
"replaces": "MY_WEB_APP"
}
},
"forms": {
"DotToSnake": {
"identifier": "replace",
"pattern": "\\.",
"replacement": "_"
}
}
} and in several content files I have
That after using the template looks like
I tested the regex and it properly replaces Is there something I'm doing wrong? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
just tried a different approach and it worked, but not sure why the forms approach isn't working using a regex generator approach: "symbols": {
"nameUpper": {
"description": "replaces content matching 'MYWEBAPP' to the uppercased '{sourceName}', e.g. sourceName 'Foo.Bar' becomes 'FOO.BAR'",
"type": "generated",
"generator": "casing",
"replaces": "MYWEBAPP",
"parameters": {
"source": "name",
"toLower": false
}
},
"nameUpperSnake": {
"description": "replaces content matching 'MY_WEB_APP' to the uppercased and underscored '{sourceName}', e.g. sourceName 'Foo.Bar.Baz' becomes 'FOO_BAR_BAZ'",
"type": "generated",
"generator": "regex",
"replaces": "MY_WEB_APP",
"parameters": {
"source": "nameUpper",
"steps": [
{
"regex": "\\.",
"replacement": "_"
}
]
}
}
} |
Beta Was this translation helpful? Give feedback.
-
I made an investigation to find out that generated symbols cannot be used as source for derived, due to processing order: derived symbols are processed before generated. Opened #5115 to improve that. Alternative way to do the same might be using forms only "symbols": {
"nameUpperSnake": {
"type": "derived",
"valueSource": "name",
"valueTransform": "identity", //avoids initial transformation
"replaces": "My.Web.App",
"forms": {
"global": [ "UpperCaseForm", "UpperCaseSnake" ]
}
}
},
"forms": {
"DotToSnake": {
"identifier": "replace",
"pattern": "\\.",
"replacement": "_"
},
"UpperCaseForm": {
"identifier": "upperCase"
},
"UpperCaseSnake": {
"identifier": "chain",
"steps": [ "UpperCaseForm", "DotToSnake" ]
}
}
For full example refer to the template in https://github.com/dotnet/templating/pull/5116/files |
Beta Was this translation helpful? Give feedback.
I made an investigation to find out that generated symbols cannot be used as source for derived, due to processing order: derived symbols are processed before generated. Opened #5115 to improve that.
Alternative way to do the same might be using forms only