Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow for customisation of the field names that are generated #129

Closed
silky opened this issue Mar 15, 2023 · 6 comments
Closed

Allow for customisation of the field names that are generated #129

silky opened this issue Mar 15, 2023 · 6 comments

Comments

@silky
Copy link

silky commented Mar 15, 2023

Following a conversation in #20 it would be convenient to be able to customise the field-name-generation rules when emitting elm code.

In particular, the main culprit is the places this function - https://github.com/Holmusk/elm-street/blob/master/src/Elm/Generic.hs#L291- is used.

If that function could instead live in the Settings - https://hackage.haskell.org/package/elm-street-0.2.0.0/docs/Elm-Generate.html#t:Settings - then we'd get to customise that :)

@jhrcek
Copy link
Contributor

jhrcek commented Mar 15, 2023

Having the function in Settings is probably not a good idea, because settings are meant to be shared across multiple types potentially. We'd have to make this configurable on per-type basis.

@turboMaCk
Copy link
Member

turboMaCk commented Mar 15, 2023

just a note from my side: I think with new record dot syntax this issue will become only more relevant since a need for current implicit prefix striping will become less relevant.

Also I second @jhrcek's opinion on allowing configuration per type. That IMO at least should be the underlying philosophy.

@silky
Copy link
Author

silky commented Mar 15, 2023

it's a hack, but to avoid extreme configuration doom, note that the function already depends on the type name, so you could always check that as a string

@silky
Copy link
Author

silky commented Mar 15, 2023

( fwiw, for my use case i'm happy with a change for all types )

@jhrcek
Copy link
Contributor

jhrcek commented Mar 25, 2023

@silky please check this PR #131 and let us know if this change is sufficient for your purposes.

I wanted to keep the old behavior (stripping type name prefix) so as not to break dozens of instances our codebase at work uses. Yet to provide way to override that default behavior in a way that is not too hacky or inconvenient.

This screenshot from updated haddock tells you how you could use the new capability:

Screenshot from 2023-03-25 09-41-47

@jhrcek
Copy link
Contributor

jhrcek commented Aug 4, 2023

The abovementioned PR was merged and released as part of 0.2.1.1 release.
See https://hackage.haskell.org/package/elm-street-0.2.1.1/docs/Elm-Generic.html#t:CodeGenOptions for example of how to use it

@jhrcek jhrcek closed this as completed Aug 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants