SwiftGen / StencilSwiftKit

A framework bringing additional nodes & filters to Stencil dedicated to Swift code generation
MIT License
289 stars 55 forks source link

swiftIdentifier converts all caps to title case #133

Closed CraigSiemens closed 1 year ago

CraigSiemens commented 3 years ago

I'm currently using this through SwiftGen for generating localized strings.

If I have the strings PDF-title it returns the identifier PDFTitle, but if it's passed PDF it results in the string Pdf which isn't the correct capitalization for an abbreviation. It seems like there is a difference in behaviour if the passed string has some capitals vs all capitals.

djbe commented 3 years ago

This is by design. The filter has 2 modes: normal and pretty (check the docs). The pretty mode will additionally apply the snakeToCamelCase filter (check the docs), which is giving the behaviour you're seeing here.

The filter can't know this is an "abbreviation". It just sees a fully uppercase string PDF, and tries to prettify it. The same would happen with HELLO. What does happen in the other case, is that the (snakeToCamelCase) filter sees there are multiple "words", and not all of them are fully uppercase. In that case, it'll try to keep the casing for the uppercased elements.

djbe commented 1 year ago

Closing due to inactivity

djbe commented 1 year ago

There's now a new mode valid for the swift identifier filter, where it will not touch the casing in your string.