Minute Two: Blocks Sequences

In YamlInFiveMinutes, you briefly learned about blocks. There's another way to use folded blocks, though, that wasn't mentioned. You can use a folded block as a sequence if you want, not just as a mapping. Here's an example.

---
- More about "Jim O'Connor"
- >
  Your patience in dealing with Jim has been
  much appreciated. As a token of our gratitude
  please accept this gift.

Well, that's very nice of them, but what does it come out to? Remembering that a folded block takes each line seperated by a single newline and concatenates it into one line, we can see that it becomes:

"Your patience in dealing with Jim has been much
appreciated. As a token of our gratitude please
accept this gift.\n"

Note also that the final newline is preserved, while all the previous ones are converted to a single space.

Even better yet, you can also use a literal block with a sequence. Here's a quick example.

---
- RE: More about "Jim O'Connor"
- |
  I thank you for your wonderful gift of a towel.
  It dries quickly, and it is as soft as down.

Now remember in a literal block, each newline after a sentance is preserved. So, this becomes:

"I thank you for your wonderful gift of a towel.\n"
"It dries quickly, and it is as soft as down.\n"


Without further ado, you can now move on to more secrets of the YAML blocks.

MinuteEight

Last edited Jan 20, 2009 at 6:47 PM by BurtHarris, version 1

Comments

No comments yet.