1 |
--- %YAML:1.0 |
2 |
test: Simple Sequence |
3 |
brief: | |
4 |
You can specify a list in YAML by placing each |
5 |
member of the list on a new line with an opening |
6 |
dash. These lists are called sequences. |
7 |
yaml: | |
8 |
- apple |
9 |
- banana |
10 |
- carrot |
11 |
php: | |
12 |
array('apple', 'banana', 'carrot') |
13 |
--- |
14 |
test: Nested Sequences |
15 |
brief: | |
16 |
You can include a sequence within another |
17 |
sequence by giving the sequence an empty |
18 |
dash, followed by an indented list. |
19 |
yaml: | |
20 |
- |
21 |
- foo |
22 |
- bar |
23 |
- baz |
24 |
php: | |
25 |
array(array('foo', 'bar', 'baz')) |
26 |
--- |
27 |
test: Mixed Sequences |
28 |
brief: | |
29 |
Sequences can contain any YAML data, |
30 |
including strings and other sequences. |
31 |
yaml: | |
32 |
- apple |
33 |
- |
34 |
- foo |
35 |
- bar |
36 |
- x123 |
37 |
- banana |
38 |
- carrot |
39 |
php: | |
40 |
array('apple', array('foo', 'bar', 'x123'), 'banana', 'carrot') |
41 |
--- |
42 |
test: Deeply Nested Sequences |
43 |
brief: | |
44 |
Sequences can be nested even deeper, with each |
45 |
level of indentation representing a level of |
46 |
depth. |
47 |
yaml: | |
48 |
- |
49 |
- |
50 |
- uno |
51 |
- dos |
52 |
php: | |
53 |
array(array(array('uno', 'dos'))) |
54 |
--- |
55 |
test: Simple Mapping |
56 |
brief: | |
57 |
You can add a keyed list (also known as a dictionary or |
58 |
hash) to your document by placing each member of the |
59 |
list on a new line, with a colon seperating the key |
60 |
from its value. In YAML, this type of list is called |
61 |
a mapping. |
62 |
yaml: | |
63 |
foo: whatever |
64 |
bar: stuff |
65 |
php: | |
66 |
array('foo' => 'whatever', 'bar' => 'stuff') |
67 |
--- |
68 |
test: Sequence in a Mapping |
69 |
brief: | |
70 |
A value in a mapping can be a sequence. |
71 |
yaml: | |
72 |
foo: whatever |
73 |
bar: |
74 |
- uno |
75 |
- dos |
76 |
php: | |
77 |
array('foo' => 'whatever', 'bar' => array('uno', 'dos')) |
78 |
--- |
79 |
test: Nested Mappings |
80 |
brief: | |
81 |
A value in a mapping can be another mapping. |
82 |
yaml: | |
83 |
foo: whatever |
84 |
bar: |
85 |
fruit: apple |
86 |
name: steve |
87 |
sport: baseball |
88 |
php: | |
89 |
array( |
90 |
'foo' => 'whatever', |
91 |
'bar' => array( |
92 |
'fruit' => 'apple', |
93 |
'name' => 'steve', |
94 |
'sport' => 'baseball' |
95 |
) |
96 |
) |
97 |
--- |
98 |
test: Mixed Mapping |
99 |
brief: | |
100 |
A mapping can contain any assortment |
101 |
of mappings and sequences as values. |
102 |
yaml: | |
103 |
foo: whatever |
104 |
bar: |
105 |
- |
106 |
fruit: apple |
107 |
name: steve |
108 |
sport: baseball |
109 |
- more |
110 |
- |
111 |
python: rocks |
112 |
perl: papers |
113 |
ruby: scissorses |
114 |
php: | |
115 |
array( |
116 |
'foo' => 'whatever', |
117 |
'bar' => array( |
118 |
array( |
119 |
'fruit' => 'apple', |
120 |
'name' => 'steve', |
121 |
'sport' => 'baseball' |
122 |
), |
123 |
'more', |
124 |
array( |
125 |
'python' => 'rocks', |
126 |
'perl' => 'papers', |
127 |
'ruby' => 'scissorses' |
128 |
) |
129 |
) |
130 |
) |
131 |
--- |
132 |
test: Mapping-in-Sequence Shortcut |
133 |
todo: true |
134 |
brief: | |
135 |
If you are adding a mapping to a sequence, you |
136 |
can place the mapping on the same line as the |
137 |
dash as a shortcut. |
138 |
yaml: | |
139 |
- work on YAML.py: |
140 |
- work on Store |
141 |
php: | |
142 |
array(array('work on YAML.py' => array('work on Store'))) |
143 |
--- |
144 |
test: Sequence-in-Mapping Shortcut |
145 |
todo: true |
146 |
brief: | |
147 |
The dash in a sequence counts as indentation, so |
148 |
you can add a sequence inside of a mapping without |
149 |
needing spaces as indentation. |
150 |
yaml: | |
151 |
allow: |
152 |
- 'localhost' |
153 |
- '%.sourceforge.net' |
154 |
- '%.freepan.org' |
155 |
php: | |
156 |
array('allow' => array('localhost', '%.sourceforge.net', '%.freepan.org')) |
157 |
--- |
158 |
todo: true |
159 |
test: Merge key |
160 |
brief: | |
161 |
A merge key ('<<') can be used in a mapping to insert other mappings. If |
162 |
the value associated with the merge key is a mapping, each of its key/value |
163 |
pairs is inserted into the current mapping. |
164 |
yaml: | |
165 |
mapping: |
166 |
name: Joe |
167 |
job: Accountant |
168 |
<<: |
169 |
age: 38 |
170 |
php: | |
171 |
array( |
172 |
'mapping' => |
173 |
array( |
174 |
'name' => 'Joe', |
175 |
'job' => 'Accountant', |
176 |
'age' => 38 |
177 |
) |
178 |
) |