-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Added pipe for multiline string, which makes them much more readable #17391
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
Conversation
ping @xabbuh |
@mercmobily Can you give an example of how this makes your use case easier? I am not sure I understand what you mean. |
Well, it depends whether you want to end up with something like thiis:
OR like this:
Which one would you rather edit by hand with a text editor? Merc. |
(I hope it makes sense... I realise that if you are strictly interested in "formally compliant" YaML then you might see this patch as useless. However, to be true to the spirit of YaML... |
Sorry for the delay since my last comment here @mercmobily. I can see why you want to be able to dump strings more readable. With #17578 we will now (starting in Symfony 3.1) be able to customise the dumped YAML string to options that are passed to the dumper as a bit field. Would you like to create a new pull request (as you cannot push to @fabpot's fork) and introduce a new option in the dumper that would allow people to switch to the new way to dump strings? |
Three questions!
Thanks! |
|
Hi,
Please note that I no longer need this for myself but will submit the patch Merc.
|
One option I see is to return the lines of the block as an array in |
I nearly gave up on this -- twice. Actually, three times. About the PR... I tried the path of returning an array. However, it got messy very quickly. The main issue I had with that approach is that while the The approach I took in the end was to add a parameter to
The key point of this is:
Basically the problem I was having is that whenever a non-array was found, the field was going to be inlined -- and therefore, the tab was zeroed. I needed another tab indicator, something that would always be current and correct. So, I added one. As I said, I am not a PHP person. So I had to do this without any debugging tools -- and without any real current knowledge of PHP. I did my best to follow the coding styles... hopefully it will work! Also, I didn't do any unit-tests. Since I don't know anything about unit testing with PHP, and I have already spent 3.5 hours on something I will never, ever use nor need... I was hoping you could 💃 Thank you! |
I just realised I need to create a new PR on my own fork to actually submit a PR. |
…cks (xabbuh) This PR was merged into the 3.1-dev branch. Discussion ---------- [Yaml] option to dump multi line strings as scalar blocks | Q | A | ------------- | --- | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #16236, #16604, #17912, #17391 | License | MIT | Doc PR | TODO Commits ------- eff6902 option to dump multi line strings as scalar blocks
This PR was submitted on the symfony/yaml read-only repository by @mercmobily and moved automatically to the main Symfony repository (closes symfony/yaml#15).
I made this little change because I am converting a LOT of data into Yaml from a database, and I wanted to make sure that the data as as user-friendly as possible.
I asked this on SO: http://stackoverflow.com/questions/34805558/phps-yaml-deciding-how-to-generate-multiline-strings
Then I discovered your wonderful YAML module, which makes much better YAML than PHP's (at least in terms of user readibility) AND it was reallllyyyy easy to hack to add this simple feature (this tells you something about the quality of your code).
Disclaimer: I don't even know PHP. I am a nodeJS boy. But, I think the patch works, and I think it's worthwhile having.
Note: I am not sure how it should deal with
\n
so that it's actually compatible with any Windows etc. If you feel this is a good addition, let me know and I will try and make it more generic...