Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
Dwoo
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Common
Dwoo
Commits
f0196747
Commit
f0196747
authored
Jun 29, 2009
by
Seldaek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
For can now iterate backwards if you input numbers, it won't work with variables though
git-svn-id:
svn://dwoo.org/dwoo/trunk@262
0598d79b-80c4-4d41-97ba-ac86fbbd088b
parent
ff735e11
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
36 additions
and
9 deletions
+36
-9
CHANGELOG
CHANGELOG
+2
-0
for.php
lib/plugins/builtin/blocks/for.php
+29
-9
BlockTests.php
tests/BlockTests.php
+5
-0
No files found.
CHANGELOG
View file @
f0196747
...
...
@@ -24,6 +24,8 @@
* Objects now act like arrays when you access non-existing properties on
them (i.e. it outputs a notice only if it'
s
output
straight
,
and
none
when
passed
to
a
function
)
*
For
can
now
iterate
backwards
if
you
input
numbers
,
it
won
't work with
variables though
* Fixed a bug with parsing AND/OR keywords in conditionals when they were
followed by round brackets
* Fixed assignments not handling multi-line values correctly
...
...
lib/plugins/builtin/blocks/for.php
View file @
f0196747
...
...
@@ -85,16 +85,36 @@ class Dwoo_Plugin_for extends Dwoo_Block_Plugin implements Dwoo_ICompilable_Bloc
$_for'
.
$cnt
.
'_to = is_numeric($_for'
.
$cnt
.
'_to) ? $_for'
.
$cnt
.
'_to - $_for'
.
$cnt
.
'_step : count($_for'
.
$cnt
.
'_from) - 1;
$_for'
.
$cnt
.
'_from = 0;
}'
;
// reverse from and to if needed
$out
.=
"
\n\t
"
.
'if ($_for'
.
$cnt
.
'_from > $_for'
.
$cnt
.
'_to) {
$tmp = $_for'
.
$cnt
.
'_from;
$_for'
.
$cnt
.
'_from = $_for'
.
$cnt
.
'_to;
$_for'
.
$cnt
.
'_to = $tmp;
}
for ($this->scope['
.
$name
.
'] = $_for'
.
$cnt
.
'_from; $this->scope['
.
$name
.
'] <= $_for'
.
$cnt
.
'_to; $this->scope['
.
$name
.
'] += $_for'
.
$cnt
.
'_step)'
.
"
\n\t
{"
;
// if input are pure numbers it shouldn't reorder them, if it's variables it gets too messy though so in that case a counter should be used
$reverse
=
false
;
$condition
=
'<='
;
$incrementer
=
'+'
;
if
(
preg_match
(
'{^(["\']?)([0-9]+)\1$}'
,
$from
,
$mN1
)
&&
preg_match
(
'{^(["\']?)([0-9]+)\1$}'
,
$to
,
$mN2
))
{
$from
=
(
int
)
$mN1
[
2
];
$to
=
(
int
)
$mN2
[
2
];
if
(
$from
>
$to
)
{
$reverse
=
true
;
$condition
=
'>='
;
$incrementer
=
'-'
;
}
}
// reverse from and to if needed
if
(
!
$reverse
)
{
$out
.=
"
\n\t
"
.
'if ($_for'
.
$cnt
.
'_from > $_for'
.
$cnt
.
'_to) {
$tmp = $_for'
.
$cnt
.
'_from;
$_for'
.
$cnt
.
'_from = $_for'
.
$cnt
.
'_to;
$_for'
.
$cnt
.
'_to = $tmp;
}'
;
}
$out
.=
'
for ($this->scope['
.
$name
.
'] = $_for'
.
$cnt
.
'_from; $this->scope['
.
$name
.
'] '
.
$condition
.
' $_for'
.
$cnt
.
'_to; $this->scope['
.
$name
.
'] '
.
$incrementer
.
'= $_for'
.
$cnt
.
'_step)'
.
"
\n\t
{"
;
// updates properties
if
(
$usesIndex
)
{
$out
.=
"
\n\t\t
"
.
'$_for'
.
$cnt
.
'_glob["index"] = $this->scope['
.
$name
.
'];'
;
$out
.=
"
\n\t\t
"
.
'$_for'
.
$cnt
.
'_glob["index"] = $this->scope['
.
$name
.
'];'
;
}
if
(
$usesFirst
)
{
$out
.=
"
\n\t\t
"
.
'$_for'
.
$cnt
.
'_glob["first"] = (string) ($_for'
.
$cnt
.
'_glob["iteration"] === 1);'
;
...
...
@@ -109,7 +129,7 @@ class Dwoo_Plugin_for extends Dwoo_Block_Plugin implements Dwoo_ICompilable_Bloc
$postOut
=
Dwoo_Compiler
::
PHP_OPEN
.
'/* -- for end output */'
;
// update properties
if
(
$usesIteration
)
{
$postOut
.=
"
\n\t\t
"
.
'$_for'
.
$cnt
.
'_glob["iteration"]+=1;'
;
$postOut
.=
"
\n\t\t
"
.
'$_for'
.
$cnt
.
'_glob["iteration"]+=1;'
;
}
// end loop
$postOut
.=
"
\n\t
}
\n
}
\n
"
.
Dwoo_Compiler
::
PHP_CLOSE
;
...
...
tests/BlockTests.php
View file @
f0196747
...
...
@@ -307,6 +307,11 @@ baz"));
$tpl
->
forceCompilation
();
$this
->
assertEquals
(
'-1|-1-2|-1-2-3'
,
$this
->
dwoo
->
get
(
$tpl
,
array
(
'sub'
=>
array
(
'foo'
,
'bar'
,
'baz'
,
'qux'
)),
$this
->
compiler
));
$tpl
=
new
Dwoo_Template_String
(
'{for i 10 7}-{$i}{/for}'
);
$tpl
->
forceCompilation
();
$this
->
assertEquals
(
'-10-9-8-7'
,
$this
->
dwoo
->
get
(
$tpl
,
array
(
'sub'
=>
array
(
'foo'
,
'bar'
,
'baz'
,
'qux'
)),
$this
->
compiler
));
}
public
function
testForElse
()
...
...
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