Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
valse
valse
Commits
b511bce6
Commit
b511bce6
authored
Nov 01, 2016
by
Bat
Browse files
Merge branch 'master' into 'master'
fix
#56
See merge request
!15
parents
8184512b
d2199649
Pipeline
#9429
passed with stage
in 4 minutes
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
tests/views/user/list.wala
View file @
b511bce6
...
...
@@ -9,11 +9,11 @@ All users
There is {{ mod.users.count }} users.
</p>
<ul>
{% for user in mod.users %}
<li>{{ user.pseudo }}</li>
{% for user
, i
in mod.users %}
<li>
<a href="/user/profile/{{ i|inc }}">
{{ user.pseudo }}</
a></
li>
{% endfor %}
</ul>
<a href="create">Create a new account</a>
<a href="
/user/
create">Create a new account</a>
<div class="debug">
<h2>Debug infos</h2>
{{ debug:model }}
...
...
valse/wala/wala.vala
View file @
b511bce6
...
...
@@ -122,6 +122,30 @@ namespace Valse {
}
return
res
;
});
add_filter
(
"inc"
,
(
ref
input
,
args
)
=>
{
int
inc
=
0
;
foreach
(
string
arg
in
args
)
{
inc
+=
int
.
parse
(
arg
);
}
if
(
inc
==
0
)
{
inc
=
1
;
}
return
(
int
.
parse
(
input
)
+
inc
).
to_string
();
});
add_filter
(
"dec"
,
(
ref
input
,
args
)
=>
{
int
dec
=
0
;
foreach
(
string
arg
in
args
)
{
dec
+=
int
.
parse
(
arg
);
}
if
(
dec
==
0
)
{
dec
=
1
;
}
return
(
int
.
parse
(
input
)
-
dec
).
to_string
();
});
}
/**
...
...
@@ -149,15 +173,16 @@ namespace Valse {
model_dump
+=
"</p>"
;
}
var
stre
=
"{% *for (?P<item>([A-Za-z0-9_]|\\.)*?) in "
+
model_keyword
+
"\\.(?P<coll>[[:graph:]]*?) *%}(?P<content>(.|\\R)+?){% *endfor *%}"
;
Regex
for_re
=
new
Regex
(
stre
);
Regex
for_re
=
new
Regex
(
"{% *for (?P<item>[\\w_.]+?)(, *(?P<index>[\\w]+))? in "
+
model_keyword
+
"\\.(?P<coll>[[:graph:]]*?) *%}(?P<content>(.|\\R)+?){% *endfor *%}"
);
MatchInfo
for_info
;
bool
for_go
=
for_re
.
match
(
result
,
RegexMatchFlags
.
NEWLINE_ANY
,
out
for_info
);
int
for_count
=
0
;
while
(
for_go
)
{
string
item
=
for_info
.
fetch_named
(
"item"
);
string
coll
=
for_info
.
fetch_named
(
"coll"
);
string
content
=
for_info
.
fetch_named
(
"content"
);
string
?
index_var
=
for_info
.
fetch_named
(
"index"
);
string
generated
=
""
;
...
...
@@ -167,12 +192,25 @@ namespace Valse {
while
(
index
<
coll_length
)
{
// for each element of the collection
// we insert the pattern (= content of the for loop)
Regex
item_re
=
new
Regex
(
"{{ *
(
%s
)*
(?P<prop>[[:graph:]]+) *}}"
.
printf
(
item
));
Regex
item_re
=
new
Regex
(
"{{ *%s(?P<prop>[[:graph:]]+) *}}"
.
printf
(
item
));
generated
+=
item_re
.
replace_eval
(
content
,
content
.
length
,
0
,
0
,
(
info
,
res
)
=>
{
string
?
elem_prop
=
info
.
fetch_named
(
"prop"
);
res
.
append
(
"{{ "
+
model_keyword
+
"."
+
coll
+
"["
+
index
.
to_string
()
+
"]"
+
elem_prop
+
" }}"
);
return
false
;
});
if
(
index_var
!=
null
)
{
// interpreting index variables
Regex
index_re
=
new
Regex
(
"{{ %s(?P<filters>.*?) }}"
.
printf
(
index_var
));
generated
=
index_re
.
replace_eval
(
generated
,
generated
.
length
,
0
,
0
,
(
info
,
res
)
=>
{
// we don't put index directly to make it possible to apply filters
string
mdl_index_var
=
"__for__%d__index__%d__"
.
printf
(
for_count
,
index
);
mdl
[
mdl_index_var
]
=
index
.
to_string
();
res
.
append
(
"{{ %s.%s%s }}"
.
printf
(
model_keyword
,
mdl_index_var
,
info
.
fetch_named
(
"filters"
)
==
null
?
""
:
info
.
fetch_named
(
"filters"
)));
return
false
;
});
}
index
++;
}
...
...
@@ -182,7 +220,7 @@ namespace Valse {
});
for_go
=
for_info
.
next
();
for_count
++;
}
// Model variables
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment