continue imports
This commit is contained in:
parent
a191a385cf
commit
3043b5ef88
|
@ -35,13 +35,13 @@ int main (string[] args)
|
|||
{
|
||||
Echo.init(false);
|
||||
|
||||
var path = "resources/test.yml";
|
||||
var path = "resources/config/db.yml";
|
||||
var done = false;
|
||||
|
||||
of.title ("Pluie Yaml Library", Pluie.Yaml.VERSION, "a-sansara");
|
||||
|
||||
var config = new Yaml.Config (path);
|
||||
var spath = "ship-to.address.city{0}";
|
||||
var spath = "bo.host{0}";
|
||||
var node = config.get (spath);
|
||||
if ((done = node != null)) {
|
||||
of.action ("retriew node from Yaml.Config", spath);
|
||||
|
|
|
@ -42,7 +42,7 @@ int main (string[] args)
|
|||
|
||||
of.title ("Pluie Yaml Library", Pluie.Yaml.VERSION, "a-sansara");
|
||||
|
||||
Pluie.Yaml.Scanner.DEBUG = true;
|
||||
Pluie.Yaml.Scanner.DEBUG = false;
|
||||
var config = new Yaml.Config (path);
|
||||
var spath = "^imports";
|
||||
var node = config.get (spath);
|
||||
|
@ -52,8 +52,15 @@ int main (string[] args)
|
|||
of.echo ((node as Yaml.NodeMap).map["^path"].to_string (false));
|
||||
}
|
||||
of.echo (node.to_string (false));
|
||||
spath = "therapy.dbname{0}";
|
||||
of.action ("retriew imported node from Yaml.Config", spath);
|
||||
var inode = config.get (spath);
|
||||
if ((done = node != null)) {
|
||||
of.echo (inode.to_string (false));
|
||||
}
|
||||
}
|
||||
|
||||
var root = config.root_node ();
|
||||
root.display_childs ();
|
||||
of.rs (done);
|
||||
of.echo ();
|
||||
|
||||
|
|
|
@ -7,12 +7,12 @@ public class Pluie.Yaml.Config
|
|||
/**
|
||||
* current path
|
||||
*/
|
||||
public string? path { get; internal set; default = null; }
|
||||
public string? path { get; internal set; default = null; }
|
||||
|
||||
/**
|
||||
* Yaml Loader
|
||||
*/
|
||||
public Yaml.Loader loader { internal get; internal set; }
|
||||
public Yaml.Loader loader { internal get; internal set; }
|
||||
|
||||
/**
|
||||
* Yaml Finder
|
||||
|
@ -37,7 +37,7 @@ public class Pluie.Yaml.Config
|
|||
Yaml.BaseNode.mode = mode;
|
||||
this.path = path;
|
||||
if (this.path != null) {
|
||||
this.loader = new Yaml.Loader (this.path, true, true);
|
||||
this.loader = new Yaml.Loader (this.path, false, false);
|
||||
this.finder = new Yaml.Finder(this.loader.get_nodes ());
|
||||
this.get_imports ();
|
||||
}
|
||||
|
@ -55,12 +55,18 @@ public class Pluie.Yaml.Config
|
|||
return node;
|
||||
}
|
||||
|
||||
public Yaml.NodeRoot root_node ()
|
||||
{
|
||||
return this.finder.context as Yaml.NodeRoot;
|
||||
}
|
||||
|
||||
/**
|
||||
* find node matching specifiyed keyPath
|
||||
*/
|
||||
public void get_imports ()
|
||||
{
|
||||
var node = this.get("^imports") as Yaml.NodeMap;
|
||||
var root = node.parent as Yaml.NodeRoot;
|
||||
if (node != null) {
|
||||
this.get_imports_var(node);
|
||||
var dir = this.strip_path(Path.get_dirname (this.path));
|
||||
|
@ -70,8 +76,19 @@ public class Pluie.Yaml.Config
|
|||
dir = Path.is_absolute(p) ? p : Path.build_filename(dir, p);
|
||||
}
|
||||
}
|
||||
of.keyval ("import path", dir);
|
||||
this.update_var (node, dir);
|
||||
foreach(var entry in this.paths.entries) {
|
||||
var config = new Yaml.Config(entry.value);
|
||||
Yaml.NodeMap sub = config.loader.get_nodes ();
|
||||
Yaml.NodeMap n = new Yaml.NodeMap (root, 0, entry.key);
|
||||
|
||||
foreach(var subnode in sub.map.values) {
|
||||
subnode.parent = null;
|
||||
|
||||
n.add(subnode);
|
||||
}
|
||||
root.add (n);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -84,30 +101,20 @@ public class Pluie.Yaml.Config
|
|||
string? file = null;
|
||||
foreach (var entry in node.map.entries) {
|
||||
if (entry.key[0] != IMPORTS_SPE) {
|
||||
message (entry.key);
|
||||
var val = entry.value.val ();
|
||||
message ("%s = %s", entry.key, val);
|
||||
if (!Path.is_absolute (val)) {
|
||||
val = Path.build_filename(path, val);
|
||||
message ("new relative %s", val);
|
||||
}
|
||||
message (" == update var == ");
|
||||
// update var
|
||||
foreach (var v in this.varmap.entries) {
|
||||
if (v.key != "path") {
|
||||
message ("-- var %s", v.key);
|
||||
entry.value.data = val.replace ("^%s^".printf (v.key), v.value);
|
||||
node.map[entry.key] = entry.value;
|
||||
of.echo ("%s : %s".printf (entry.key, node.map[entry.key].val () ));
|
||||
|
||||
this.paths[entry.key] = entry.value.data;
|
||||
of.keyval (entry.key, entry.value.data);
|
||||
//~ this.paths[entry.key] = entry.value.data;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
foreach (var entry in this.paths.entries) {
|
||||
of.keyval (entry.key, entry.value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -122,14 +129,11 @@ public class Pluie.Yaml.Config
|
|||
this.varmap.set (entry.key.substring (1), entry.value.val ());
|
||||
}
|
||||
}
|
||||
of.echo ("");
|
||||
foreach (var entry in this.varmap.entries) {
|
||||
of.keyval (entry.key, entry.value);
|
||||
}
|
||||
of.echo ("");
|
||||
of.echo ("");
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private string? strip_path(string? path)
|
||||
{
|
||||
string? s = path;
|
||||
|
|
|
@ -40,7 +40,7 @@ public class Pluie.Yaml.Finder : Object
|
|||
/**
|
||||
* Context node
|
||||
*/
|
||||
private Yaml.Node? context { get; internal set; }
|
||||
public Yaml.Node? context { get; internal set; }
|
||||
|
||||
/**
|
||||
* default Yaml.Node constructor
|
||||
|
|
Loading…
Reference in New Issue
Block a user