mirror of https://github.com/status-im/NimYAML.git
Improved quickstart examples
This commit is contained in:
parent
537ba1ca01
commit
d3053f381f
|
@ -236,12 +236,16 @@ Defining a custom tag uri for a type
|
||||||
import yaml
|
import yaml
|
||||||
type Mob = object
|
type Mob = object
|
||||||
level, experience: int32
|
level, experience: int32
|
||||||
|
drops: seq[string]
|
||||||
|
|
||||||
setTagUriForType(Mob, "!Mob")
|
setTagUriForType(Mob, "!Mob")
|
||||||
|
setTagUriForType(seq[string], "!Drops")
|
||||||
|
|
||||||
var mob = Mob(level: 42, experience: 1800)
|
var mob = Mob(level: 42, experience: 1800, drops:
|
||||||
|
@["Sword of Mob Slaying"])
|
||||||
var s = newFileStream("out.yaml", fmWrite)
|
var s = newFileStream("out.yaml", fmWrite)
|
||||||
dump(mob, s)
|
dump(mob, s,
|
||||||
|
options = defineOptions(tagStyle = tsAll))
|
||||||
s.close()
|
s.close()
|
||||||
|
|
||||||
.. raw:: html
|
.. raw:: html
|
||||||
|
@ -250,8 +254,9 @@ Defining a custom tag uri for a type
|
||||||
.. code-block:: yaml
|
.. code-block:: yaml
|
||||||
%YAML 1.2
|
%YAML 1.2
|
||||||
--- !Mob
|
--- !Mob
|
||||||
level: 42
|
!!str level: !nim:system:int32 42
|
||||||
experience: 1800
|
!!str experience: !nim:system:int32 1800
|
||||||
|
!!str drops: !Drops [!!str Sword of Mob Slaying]
|
||||||
|
|
||||||
.. raw:: html
|
.. raw:: html
|
||||||
</td></tr></tbody></table>
|
</td></tr></tbody></table>
|
||||||
|
@ -274,7 +279,8 @@ Dumping Nim objects as JSON
|
||||||
personList.add(Person(name: "Peter Pan", age: 12))
|
personList.add(Person(name: "Peter Pan", age: 12))
|
||||||
|
|
||||||
var s = newFileStream("out.yaml", fmWrite)
|
var s = newFileStream("out.yaml", fmWrite)
|
||||||
dump(personList, s, options = defineOptions(style = psJson))
|
dump(personList, s,
|
||||||
|
options = defineOptions(style = psJson))
|
||||||
s.close()
|
s.close()
|
||||||
|
|
||||||
.. raw:: html
|
.. raw:: html
|
||||||
|
|
Loading…
Reference in New Issue