dhall-lang / dhall-haskell

Maintainable configuration files
https://dhall-lang.org/
BSD 3-Clause "New" or "Revised" License
911 stars 211 forks source link

`to-directory-tree` JSON support? #2073

Open SiriusStarr opened 3 years ago

SiriusStarr commented 3 years ago

Unsure if it would be useful for anyone else, but I find myself wishing that dhall to-directory-tree supported file content other than Text. What are people's thoughts on rendering files using dhall-to-json? The biggest issue I foresee would be determining when to "terminate", i.e. when to stop treating records as directories and render them out as JSON instead.

Currently the only way to go about this is to use the JSON rendering in the Prelude, but that requires doing all the work to turn whatever are your terminal file contents into JSON/Type, which is tedious if you have any non-trivial structure.

Gabriella439 commented 3 years ago

@SiriusStarr: I think the latter issue about converting things to JSON/Type could be resolved by adding a toJSON keyword as suggested in https://github.com/dhall-lang/dhall-lang/issues/336

SiriusStarr commented 3 years ago

I completely agree that that would solve the usecase as well and would probably be less cumbersome, since the current nice, unambiguous nature of to-directory-tree would still apply then.

(On an unrelated note, is there a way to render JSON compactly rather than "pretty" that I'm missing? I went ahead and did the tedious work, but that's the one thing I haven't figured out.)

Gabriella439 commented 3 years ago

@SiriusStarr: The old JSON renderer used to render compactly before we changed it to pretty-print. The algorithm is pretty simple:

https://github.com/dhall-lang/dhall-lang/blob/v11.0.0/Prelude/JSON/render

SiriusStarr commented 3 years ago

@SiriusStarr: The old JSON renderer used to render compactly before we changed it to pretty-print. The algorithm is pretty simple:

https://github.com/dhall-lang/dhall-lang/blob/v11.0.0/Prelude/JSON/render

Thanks, just wanted to make sure there wasn't a canonical way to do it with the current Prelude before I resorted to something along these lines. :-)

Gabriella439 commented 3 years ago

We could always add back the simpler renderer to the Prelude if desired

SiriusStarr commented 3 years ago

I think it would be a good option to have, though it's easy enough to work around as is. I am generally in favor of making more functionality available in the Prelude, since I abhor boilerplate. "Pretty" is the more sensible default, of course.

Gabriella439 commented 3 years ago

I have a pull request up for restoring the compact rendering logic here: https://github.com/dhall-lang/dhall-lang/pull/1087