continue imports

This commit is contained in:
a-sansara 2018-08-02 18:57:16 +02:00
parent a191a385cf
commit 3043b5ef88
4 changed files with 38 additions and 27 deletions

View File

@ -35,13 +35,13 @@ int main (string[] args)
{ {
Echo.init(false); Echo.init(false);
var path = "resources/test.yml"; var path = "resources/config/db.yml";
var done = false; var done = false;
of.title ("Pluie Yaml Library", Pluie.Yaml.VERSION, "a-sansara"); of.title ("Pluie Yaml Library", Pluie.Yaml.VERSION, "a-sansara");
var config = new Yaml.Config (path); var config = new Yaml.Config (path);
var spath = "ship-to.address.city{0}"; var spath = "bo.host{0}";
var node = config.get (spath); var node = config.get (spath);
if ((done = node != null)) { if ((done = node != null)) {
of.action ("retriew node from Yaml.Config", spath); of.action ("retriew node from Yaml.Config", spath);

View File

@ -42,7 +42,7 @@ int main (string[] args)
of.title ("Pluie Yaml Library", Pluie.Yaml.VERSION, "a-sansara"); 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 config = new Yaml.Config (path);
var spath = "^imports"; var spath = "^imports";
var node = config.get (spath); 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 as Yaml.NodeMap).map["^path"].to_string (false));
} }
of.echo (node.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.rs (done);
of.echo (); of.echo ();

View File

@ -37,7 +37,7 @@ public class Pluie.Yaml.Config
Yaml.BaseNode.mode = mode; Yaml.BaseNode.mode = mode;
this.path = path; this.path = path;
if (this.path != null) { 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.finder = new Yaml.Finder(this.loader.get_nodes ());
this.get_imports (); this.get_imports ();
} }
@ -55,12 +55,18 @@ public class Pluie.Yaml.Config
return node; return node;
} }
public Yaml.NodeRoot root_node ()
{
return this.finder.context as Yaml.NodeRoot;
}
/** /**
* find node matching specifiyed keyPath * find node matching specifiyed keyPath
*/ */
public void get_imports () public void get_imports ()
{ {
var node = this.get("^imports") as Yaml.NodeMap; var node = this.get("^imports") as Yaml.NodeMap;
var root = node.parent as Yaml.NodeRoot;
if (node != null) { if (node != null) {
this.get_imports_var(node); this.get_imports_var(node);
var dir = this.strip_path(Path.get_dirname (this.path)); 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); dir = Path.is_absolute(p) ? p : Path.build_filename(dir, p);
} }
} }
of.keyval ("import path", dir);
this.update_var (node, 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; string? file = null;
foreach (var entry in node.map.entries) { foreach (var entry in node.map.entries) {
if (entry.key[0] != IMPORTS_SPE) { if (entry.key[0] != IMPORTS_SPE) {
message (entry.key);
var val = entry.value.val (); var val = entry.value.val ();
message ("%s = %s", entry.key, val);
if (!Path.is_absolute (val)) { if (!Path.is_absolute (val)) {
val = Path.build_filename(path, val); val = Path.build_filename(path, val);
message ("new relative %s", val);
} }
message (" == update var == "); // update var
foreach (var v in this.varmap.entries) { foreach (var v in this.varmap.entries) {
if (v.key != "path") { if (v.key != "path") {
message ("-- var %s", v.key);
entry.value.data = val.replace ("^%s^".printf (v.key), v.value); entry.value.data = val.replace ("^%s^".printf (v.key), v.value);
node.map[entry.key] = entry.value; this.paths[entry.key] = entry.value.data;
of.echo ("%s : %s".printf (entry.key, node.map[entry.key].val () ));
of.keyval (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 ()); 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) private string? strip_path(string? path)
{ {
string? s = path; string? s = path;

View File

@ -40,7 +40,7 @@ public class Pluie.Yaml.Finder : Object
/** /**
* Context node * Context node
*/ */
private Yaml.Node? context { get; internal set; } public Yaml.Node? context { get; internal set; }
/** /**
* default Yaml.Node constructor * default Yaml.Node constructor