💄 styled-yaml
A Psych extension to enable choosing output styles for specific objects.
Usage
require 'styled_yaml'
require 'yaml'
recipe = {
'name' => StyledYAML.double_quoted(+'Fruit Salad'),
'link' => StyledYAML.single_quoted(+'http://bad.recipes/salad'),
'ingredients' => StyledYAML.inline(%w[apple pear orange]),
'steps' => StyledYAML.literal(+<<~STEPS
1. Dice the fruit into bit size pieces.
1. Combine the fruit in a bowl.
1. Enjoy!
STEPS
)
}
puts YAML.dump(recipe)
puts StyledYAML.dump(recipe)
---
name: Fruit Salad
link: http://bad.recipes/salad
ingredients:
- apple
- pear
- orange
steps: |
1. Dice the fruit into bit size pieces.
1. Combine the fruit in a bowl.
1. Enjoy!
---
name: "Fruit Salad"
link: 'http://bad.recipes/salad'
ingredients: [apple, pear, orange]
steps: |
1. Dice the fruit into bit size pieces.
1. Combine the fruit in a bowl.
1. Enjoy!
Acknowledgments
- @mislav for the original implementation and @tenderlove for the help
- @jirkuta for improvements