config icon indicating copy to clipboard operation
config copied to clipboard

Render format with formatted HOCON

Open acaly opened this issue 10 years ago • 8 comments
trafficstars

Hi,

I find that in formatted HOCON, entry is rendered like key=value(if value is not an object) or key value(if value is an object). I think for better readability, why not use key = value? The string generated might be prettier in this format.

Besides, I think there are other small improvements that can be made. Such as: remove newline between short entries in a list to make it in a single line (like [0, 1, 2, 3]), and insert an extra newline after a long block.

Thanks!

acaly avatar Jan 16 '15 11:01 acaly

When setFormatted=true (https://typesafehub.github.io/config/latest/api/com/typesafe/config/ConfigRenderOptions.html#setFormatted%28boolean%29 ) this sounds fine to me, except for cases that would require "look-ahead." That is, I think the code would probably get messier than is worthwhile if you have formatting rules that require looking at an entire list or entire object before outputting each field of said list or object. But otherwise, making things prettier is OK with me.

havocp avatar Jan 20 '15 14:01 havocp

I agree with @acaly. I think there should be more render options to control the output.

boformer avatar Feb 15 '15 03:02 boformer

Why is render() a method? How about adding a ConfigRenderer class which implements the operation and open this type for extension. That would also solve issuse #145

You would also have to make ConfigRenderOptions extensible to allow custom renderers to add their options.

digulla avatar Jan 27 '16 09:01 digulla

The main thing to figure out there is what else would have to be public to implement render yourself. I think it uses some private API. We could see about adding what you need, though removing the method wouldn't be compatible, you don't have to use it.

It's a method primarily to use polymorphism (each ConfigValue knows how to render itself).

havocp avatar Jan 27 '16 12:01 havocp

I was thinking that the method in ConfigImpl should simply use the new renderer class while the other types should implement an interface RenderableConfigValue which would give the renderer a clue or the renderer could offer methods to render different parts of config values and you could add a new render(renderer) method just like you currently have the methods which take StringBuilder and indentand the like.

That way, the code would be very similar to what it is right now but a lot of the hidden parts of the renderer (like whether JSON emits spaces around the colon) could be exposed for customization. Ideally, the new renderer should use fields for all strings with sensible defaults. Specific renderers could then overwrite them. So there is just a single keyValueSeparator field) which is = or _:_ (_ = space), depending on the formatting options.

digulla avatar Jan 28 '16 10:01 digulla

Would also help to solve issue #372

digulla avatar Jan 28 '16 10:01 digulla

+1 for adding more rendering options.

What I would need is ConfigRenderOptions.dotNotation(true) that would write all nested objects using dot notation whenever possible.

jmullo avatar Apr 12 '16 13:04 jmullo

I propose a setting to disable reordering entries. Now I believe entries are in alphabetical order. The origin comments are already implemented, so keeping the original order should be easy to implement.

kastoestoramadus avatar Apr 09 '25 13:04 kastoestoramadus