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
|
||||
type Mob = object
|
||||
level, experience: int32
|
||||
drops: seq[string]
|
||||
|
||||
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)
|
||||
dump(mob, s)
|
||||
dump(mob, s,
|
||||
options = defineOptions(tagStyle = tsAll))
|
||||
s.close()
|
||||
|
||||
.. raw:: html
|
||||
|
@ -250,8 +254,9 @@ Defining a custom tag uri for a type
|
|||
.. code-block:: yaml
|
||||
%YAML 1.2
|
||||
--- !Mob
|
||||
level: 42
|
||||
experience: 1800
|
||||
!!str level: !nim:system:int32 42
|
||||
!!str experience: !nim:system:int32 1800
|
||||
!!str drops: !Drops [!!str Sword of Mob Slaying]
|
||||
|
||||
.. raw:: html
|
||||
</td></tr></tbody></table>
|
||||
|
@ -274,7 +279,8 @@ Dumping Nim objects as JSON
|
|||
personList.add(Person(name: "Peter Pan", age: 12))
|
||||
|
||||
var s = newFileStream("out.yaml", fmWrite)
|
||||
dump(personList, s, options = defineOptions(style = psJson))
|
||||
dump(personList, s,
|
||||
options = defineOptions(style = psJson))
|
||||
s.close()
|
||||
|
||||
.. raw:: html
|
||||
|
|
Loading…
Reference in New Issue