pluie-yaml is a vala shared library managing yaml files and yaml nodes in vala language.
Go to file
2018-08-03 00:19:25 +02:00
bin add samples json & yaml + fix flow entries + update build.sh 2018-08-01 14:55:10 +02:00
build initial commit 2018-07-30 18:30:11 +02:00
resources finish ^imports 2018-08-03 00:19:25 +02:00
samples finish ^imports 2018-08-03 00:19:25 +02:00
src finish ^imports 2018-08-03 00:19:25 +02:00
.gitignore add samples json & yaml + fix flow entries + update build.sh 2018-08-01 14:55:10 +02:00
build.sh finish ^imports 2018-08-03 00:19:25 +02:00
install.vala.in adding header & update readme 2018-08-01 15:10:12 +02:00
LICENSE initial commit 2018-07-30 18:30:11 +02:00
meson.build adding Yaml.Config 2018-08-01 17:55:26 +02:00
README.md finish ^imports 2018-08-03 00:19:25 +02:00

pluie-yaml

pluie-yaml is a vala shared library managing yaml files (v 1.2) and yaml nodes in vala language.
As json is now a valid subset of yaml, you can use this lib to load json files too.

The purpose of this project is to make vala able to load and deal with yaml configuration files.
So, currently the lib deal only with one yaml document, but you can use a special ^imports clause (nodemap)
to load a subset of yaml files in the main yaml document.

the lib does not manage yet tag directives and tag values.
pluie-yaml use the libyaml c library (License MIT, many thanks to Kirill Simonov) to parse and retriew related yaml events.

License

GNU GPL v3

Prerequisites

valac meson ninja glib gee gobject pluie-echo

Install

git clone the project then cd to project directory and do :

meson --prefix=/usr ./ build
sudo ninja install -C build

Compilation

valac --pkg gee-0.8 --pkg pluie-echo-0.2 --pkg pluie-yaml-0.3 main.vala

see https://git.pluie.org/pluie/libpluie-echo in order to install pluie-echo-0.2 pkg

you can use ./build.sh to rebuild/install the pluie-yaml lib and compile samples files

Api / Documentation

https://pluie.org/pluie-yaml-0.3/index.htm
(comming soon)

Docker

a demo image will be available soon on docker hub. you will be able to run a container with :

docker run --rm -it pluie/libyaml

Usage


config


    var config = new Yaml.Config (path);
    var node   = config.get ("ship-to.address.city{0}");
    if (node != null) {
        of.echo (node.data)
    }


config with ^imports clause

# |  use special key word '^imports' to import other yaml config files in 
# |  current yaml document
# |  '^imports' must be uniq and a direct child of root node
# |  imported files are injected as mapping nodes at top document level
# |  so you cannot use keys that already exists in the document
^imports :
    # you can redefine default import path with the special key '^path'
    # if you do not use it, the default path value will be the current directory
    # redefined path values are relative to the current directory (if a relative path 
    # is provided)
    ^path : ./config
    # you can also define any other var by prefixing key with ^
    ^dir  : subdir
    # and use it enclosed by ^
    # here final test path will be "./config/subdir/test.yml"
    test  : ^dir^/test.yml 
    # here final db path will be "./config/db.yml"
    db    : db.yml

loader

load a single document.
^imports clause is out of effects here.

    var path   = "./config/main.yml";
    // uncomment to enable debug
    // Pluie.Yaml.Scanner.DEBUG = true;
    var loader = new Yaml.Loader (path /* , displayFile, displayNode */);
    if ((done = loader.done)) {
        Yaml.NodeRoot root = loader.get_nodes ();
        root.display_childs ();
    }

finder

lib-yaml provide a Yaml.Finder to easily retriew a particular yaml node.
Search path definition has two mode.
The default mode is Yaml.FIND_MODE.DOT

  • child mapping node are separated by dot
  • sequence entry must be enclosed in curly brace

ex : grandfather.father.son{2}.age

The Other mode is Yaml.FIND_MODE.SQUARE_BRACKETS

  • node's key name must be enclosed in square brackets
  • sequence entry must be enclosed in curly brace

ex : [grandfather][father][son]{2}[age]

with singlepair node, you can retriew corresponding scalar node with {0}

ex yaml file :

product:
    - sku         : BL394D
      quantity    : 4
      description : Basketball

vala code :

    ...
    Yaml.NodeRoot root = loader.get_nodes ();
    Yaml.Node?    node = null;
    if ((node = finder.find ("product{0}.description")) != null) {
        var val = node.val ();
    }

more samples

see samples files in ./samples directory


todo

  • imports clause
  • fix nodes traversing
  • dumper
  • manage tag directives & tag