Created
January 20, 2012 01:26
-
-
Save parndt/1644377 to your computer and use it in GitHub Desktop.
Psych outputs a different file than it read in
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'yaml' | |
my_yaml = YAML::load(File.read('en.yml')).to_yaml | |
=begin | |
1.9.3-p0 :002 > YAML::load(File.read('en.yml')).to_yaml | |
=> "---\nen:\n refinery:\n plugins:\n lovelies:\n title: Lovely Profiles\n people:\n admin:\n lovelies:\n actions:\n create_new: Add New Lovely profile\n reorder: Reorder Lovely profiles\n reorder_done: Done Reordering Lovely profiles\n records:\n title: Lovely\n sorry_no_results: Sorry! There are no results found.\n no_items_yet: There are no Lovely profiles yet. Click \"Add New Lovely\n profile\" to add one.\n lovely:\n view_live_html: View the lovely area live <br/><em>(opens in a new window)</em>\n edit: Edit this lovely profile\n delete: Remove this lovely profile forever\n lovelies:\n show:\n other: Other Lovely profiles\n activerecord:\n attributes:\n refinery/things/lovely:\n name: Name\n title: Title\n photo: Photo\n bio: Bio\n" | |
=end | |
# the problem is this: no_items_yet: There are no Lovely profiles yet. Click \"Add New Lovely\n profile\" to add one. | |
# Note how after \"Add New Lovely there is a \n as is demonstrated in en_after.yml | |
File.open('en_after.yml', 'w+') {|f| f.puts my_yaml } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
en: | |
refinery: | |
plugins: | |
lovelies: | |
title: Lovely Profiles | |
people: | |
admin: | |
lovelies: | |
actions: | |
create_new: Add New Lovely profile | |
reorder: Reorder Lovely profiles | |
reorder_done: Done Reordering Lovely profiles | |
records: | |
title: Lovely | |
sorry_no_results: Sorry! There are no results found. | |
no_items_yet: There are no Lovely profiles yet. Click "Add New Lovely profile" to add one. | |
lovely: | |
view_live_html: View the lovely area live <br/><em>(opens in a new window)</em> | |
edit: Edit this lovely profile | |
delete: Remove this lovely profile forever | |
lovelies: | |
show: | |
other: Other Lovely profiles | |
activerecord: | |
attributes: | |
'refinery/things/lovely': | |
name: Name | |
title: Title | |
photo: Photo | |
bio: Bio |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
en: | |
refinery: | |
plugins: | |
lovelies: | |
title: Lovely Profiles | |
people: | |
admin: | |
lovelies: | |
actions: | |
create_new: Add New Lovely profile | |
reorder: Reorder Lovely profiles | |
reorder_done: Done Reordering Lovely profiles | |
records: | |
title: Lovely | |
sorry_no_results: Sorry! There are no results found. | |
no_items_yet: There are no Lovely profiles yet. Click "Add New Lovely | |
profile" to add one. | |
lovely: | |
view_live_html: View the lovely area live <br/><em>(opens in a new window)</em> | |
edit: Edit this lovely profile | |
delete: Remove this lovely profile forever | |
lovelies: | |
show: | |
other: Other Lovely profiles | |
activerecord: | |
attributes: | |
refinery/things/lovely: | |
name: Name | |
title: Title | |
photo: Photo | |
bio: Bio |
Thanks Aaron! I'll have to live with "it's valid" :-)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I can't seem to get libyaml to stop wrapping that string. It's definitely a behavior of libyaml and not psych (the ruby wrapper). Is there a reason you need to prevent wrapping? Libyaml will roundtrip the data structures correctly. Even though a newline is added, when you read the YAML back in, the data will be exactly the same.
Here is an example test to show what I mean:
Note that even though the output yaml is different than the original file, the ruby data structures are exactly the same. I hope this was helpful. :(