Commit 12790275 authored by Bat's avatar Bat
Browse files

la boucle for ! enfin

parent a1a7aefb
......@@ -10,11 +10,11 @@ public class ZdSModel : Object {
public string greeter {get; set; default = "yey";}
public string message {get; set; default = "yey";}
public string message {get; set; default = "youp";}
public string question {get; set; default = "yey";}
public string question {get; set; default = "hey";}
public string low {get; set; default = "yey";}
public string low {get; set; default = "test";}
public int ze_reponse {get; set; default = 42;}
......
......@@ -9,9 +9,9 @@
<h1>{{ mod.greeter|upper }}</h1>
<img alt="valse" src="valse.png">
<p>Cette page a été rendue avec {{ render_engine }}.</p>
<p>{{ mod.contributors[0] }} a contribué au projet</p>
<p>{{ mod.contributors[1] }} a contribué au projet</p>
<p>{{ mod.contributors[2] }} a contribué au projet</p>
{{ for contrib in mod.contributors }}
<p>{{ contrib }} participe au projet.</p>
{{ endfor }}
<p>{{ mod.zap[0] }} est un int</p>
<p>{{ mod.message|safe }}</p>
<p>{{ mod.question|lower|capitalize :test :retest }}</p>
......
......@@ -108,10 +108,6 @@ namespace Valse {
}
}
foreach (var entry in result.entries) {
print ("model -> %s is %s\n", entry.key, entry.value);
}
return result;
}
......
......@@ -18,13 +18,6 @@ namespace Valse {
public Many.from_arraylist (ArrayList<G> from) {
foreach (G item in from) {
this._arr [this._arr.length] = item;
//print ("added %s \n", (string) this._arr[this._arr.length - 1]);
}
}
public void list () {
foreach (G item in this._arr) {
//print ("list of many : %s\n", (string) item);
}
}
......@@ -33,17 +26,12 @@ namespace Valse {
ArrayList<string> result = new ArrayList<string> ();
Type t = typeof (G);
this.list ();
foreach (G item in this._arr) {
print ("t is %s\n", t.name ());
if (t.is_a (typeof (Object))) {
print ("t is an object.\n");
} else if (t == typeof (string)) {
result.add ((string) item);
} else if (t == typeof (int)) {
result.add (((int) item).to_string ());
print ("t is an int\n");
}
}
return result;
......
......@@ -190,6 +190,58 @@ namespace Valse {
}
}
result = result.replace ("\n", "\r\n");
Regex for_re = new Regex ("{{ *for *(?P<item>[[:graph:]]*) in %s\\.(?P<coll>[[:graph:]]*) *}}(?P<content>(.|\\R)+){{ *endfor *}}".printf (this.model_keyword));
MatchInfo for_info;
bool for_go = for_re.match (result, RegexMatchFlags.NEWLINE_ANY, out for_info);
while (for_go) {
string item = for_info.fetch_named ("item");
string coll = for_info.fetch_named ("coll");
string content = for_info.fetch_named ("content");
bool coll_end = false;
string generated = "";
// tant qu'on a pas fini de passer tous les éléments
int index = 0;
while (!coll_end) {
string element_name = coll + "[" + index.to_string () + "]";
if (view.model.has_key (element_name)) {
// on récupère la valeur de l'élémet actuel
string cur_elem = view.model [element_name];
Regex item_re = new Regex ("{{ *(?P<elem>(%s)*) *}}".printf (item));
generated += item_re.replace_eval (content, content.length, 0, 0, (info, res) => {
res.append (cur_elem);
return true;
});
/*
result = for_re.replace_eval (content, content.length, 0, 0, (info, res) => {
Regex item_re = ("{{ *(?P<elem>[[:graph:]]*) *}}");
MatchInfo item_info;
bool go_item = item_re.match (content, 0, out item_info);
if (go_item) {
}
res.append (item_re.replace (content));
return true;
});*/
//generated += content.replace (item, cur_elem);
index++;
} else {
coll_end = true;
}
}
result = for_re.replace (result, result.length, 0, generated);
for_go = for_info.next ();
}
return result;
} catch {
return Errors.server_error ("Error while rendering page using Wala.").body;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment