I'm getting a line error on line 49, I'm not sure what I have done wrong, I'd appreciate any advice.
--
---
You received this message because you are subscribed to the Google Groups "Iowa City Ruby Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ic-ruby+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
You received this message because you are subscribed to a topic in the Google Groups "Iowa City Ruby Group" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ic-ruby/xbzhKcrHg2I/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ic-ruby+u...@googlegroups.com.
As someone who works with YAML a lot (and rather likes it despite its, er, hazards), I have some unsolicited advice for everyone who uses YAML:
It’s not JSON. Don’t use quotation marks.
In my opinion YAML values should almost never be wrapped in quotation marks. In addition to adding line noise, as William discovered they can actually cause errors when you don’t match them up. There are only three situations in which your value should be wrapped in quotation marks (off the top of my head):
:
) character. This is because colons separate mapping keys from their values, e.g. foo: 3
. YAML doesn’t know what to do if it sees foo: bar: 3
.[
or {
. Those characters indicate the beginning of a flow (inline) sequence or mapping, respectively.%
, &
or *
, which indicate a directive, anchor or alias, respectively.“But wait,” you cry, “what about values that span multiple lines?” A good question, but in fact one of YAML’s best features is its features for dealing with this very thing. I’m going to use a little bit of William’s YAML to demonstrate; I hope he doesn’t mind:
dashboard_user_settings:
# ...
account_subtitle_html: "We need the below to make a financial transfer ..."
I’ve trimmed this so it won’t stretch anyone’s email window, but as it turns out we do need quotation marks around this value because there’s a colon later on. That’s a bummer, and it’s also a bummer that the value will scroll way off the side of our text editor.
But wait! We can express the same thing like this:
dashboard_user_settings:
# ...
account_subtitle_html: >
We need the below to make a financial transfer date for successful
projects. <b>ATENÇÃO: The tax details listed in the registration
information and bank details must be the same.</b>
The >
is the folded scalar indicator. “Scalar” is YAML-speak for “string.”. “Folded” means that every subsequent line with the same or greater level of indentation as the very next line will be “folded” into a single string with indentation and newlines removed. There is one slight difference, though: This string will end in a newline. If you want to strip the newline as well, use >-
instead of >
. (The -
is a “block chomping indicator,” which you can read about in the YAML spec.)
“But wait,” you say, “what if I don’t want my string “folded”? What if, say, I have HTML with indentation I want to keep?” YAML has that covered, too. Instead of >
, use |
(pipe), which is the literal scalar indicator:
explanation_html: |
<div class='fontsize-base u-marginbottom-40 card card-terciary'>
<p class='fontweight-bold'>
With the campaign published, some information may no longer
be edited
</p>
...
</div>
The literal scalar indicator will leave interior newlines and indentation intact. What I mean by “interior” is that in the above code the whole block is indented two spaces, but YAML will “unindent” it, so the first and last lines have no leading spaces, the second line has two leading spaces instead of four, and so on. The same “chomping” rules apply, though, so if you don’t want a trailing newline, us |-
instead of |
.
As an exercise I’ve reformatted William’s YAML with these features in mind and put it in a Gist here: https://gist.github.com/jrunning/54ce15459c0a3985a8df If you click on “Revisions” on the right you can see a diff between the original and new versions.
Two final bits of advice: 1. Bookmark this online YAML parser, which will show you the result of your YAML as you type, which is great for learning and experimentation; and 2. Read the YAML spec. Okay, don’t read the whole thing, but do read sections 2, 6, 7 and 8.
Jordan
Chef Software, Inc.
...