Change all foreach loops in Soy templates to use for loop syntax

Soy supports 2 kinds of loops:
 * foreach- for iterating over items in a collection,
   e.g. {foreach $item in $list}...{/foreach}
 * for - for indexed iteration,
   e.g. {for $i in range(0, 10)}...{/for}

The reason Soy has 2 different loops is an accident of history, Soy
didn’t use to have a proper grammar for expressions and so the alternate
'for...range' syntax was added to make it possible to write indexed
loops. As the grammar has improved having the two syntaxes is no longer
necessary and so we are eliminating one of them.

As of [1] or mvn release "2018-01-03" the two forms are actually aliases
for one another, so the only difference is the keyword ('for' vs
'foreach'), and while the foreach loop is more popular the 'for'
terminology is more standard so upstream recommends switching everything
to that.

[1] 4a7373333f

PiperOrigin-RevId: 180807358
Change-Id: I6f6416b4265d7fb1a7f933bc9ed24466b3637d40
This commit is contained in:
Luke Sandberg 2018-01-04 13:08:51 -05:00 committed by Jonathan Nieder
parent 843ea31dce
commit 57073ffd9d
10 changed files with 34 additions and 34 deletions

View File

@ -38,18 +38,18 @@
{\n}
{/if}
{foreach $group in $commentFiles}
{for $group in $commentFiles}
{$group.link}{\n}
{$group.title}:{\n}
{\n}
{foreach $comment in $group.comments}
{for $comment in $group.comments}
{if $comment.isRobotComment}
Robot Comment from {$comment.robotId} (run ID {$comment.robotRunId}):
{\n}
{/if}
{foreach $line in $comment.lines}
{for $line in $comment.lines}
{if isFirst($line)}
{if $comment.startLine != 0}
{$comment.link}
@ -59,7 +59,7 @@
{$comment.linePrefixEmpty}
{/if}
{$line}{\n}
{/foreach}
{/for}
{if length($comment.lines) == 0}
{$comment.linePrefix}{\n}
{/if}
@ -70,7 +70,7 @@
{$comment.message}{\n}
{\n}
{\n}
{/foreach}
{/foreach}
{/for}
{/for}
{\n}
{/template}

View File

@ -79,7 +79,7 @@
{if length($labels) > 0}
<p>
Patch set {$patchSet.patchSetId}:
{foreach $label in $labels}
{for $label in $labels}
{if $label.value > 0}
<span style="{$positiveVoteStyle}">
{$label.label}{sp}+{$label.value}
@ -93,7 +93,7 @@
-{$label.label}
</span>
{/if}
{/foreach}
{/for}
</p>
{/if}
@ -110,14 +110,14 @@
{/if}
<ul style="{$ulStyle}">
{foreach $group in $commentFiles}
{for $group in $commentFiles}
<li style="{$fileLiStyle}">
<p>
<a href="{$group.link}">{$group.title}:</a>
</p>
<ul style="{$ulStyle}">
{foreach $comment in $group.comments}
{for $comment in $group.comments}
<li style="{$commentLiStyle}">
{if $comment.isRobotComment}
<p style="{$commentHeaderStyle}">
@ -149,9 +149,9 @@
<p>
<blockquote style="{$blockquoteStyle}">
{call .Pre}{param content kind="html"}
{foreach $line in $comment.lines}
{for $line in $comment.lines}
{$line}{\n}
{/foreach}
{/for}
{/param}{/call}
</blockquote>
</p>
@ -167,9 +167,9 @@
{call .WikiFormat}{param content: $comment.messageBlocks /}{/call}
</li>
{/foreach}
{/for}
</ul>
</li>
{/foreach}
{/for}
</ul>
{/template}

View File

@ -26,10 +26,10 @@
*/
{template .DeleteReviewer kind="text"}
{$fromName} has removed{sp}
{foreach $reviewerName in $email.reviewerNames}
{for $reviewerName in $email.reviewerNames}
{if not isFirst($reviewerName)},{sp}{/if}
{$reviewerName}
{/foreach}{sp}
{/for}{sp}
from this change.{sp}
{if $email.changeUrl} ( {$email.changeUrl} ){/if}{\n}
{\n}

View File

@ -25,12 +25,12 @@
{$fromName}{sp}
<strong>
removed{sp}
{foreach $reviewerName in $email.reviewerNames}
{for $reviewerName in $email.reviewerNames}
{if not isFirst($reviewerName)}
{if isLast($reviewerName)}{sp}and{else},{/if}{sp}
{/if}
{$reviewerName}
{/foreach}
{/for}
</strong>{sp}
from this change.
</p>

View File

@ -23,7 +23,7 @@
* @param footers
*/
{template .Footer kind="text"}
{foreach $footer in $footers}
{for $footer in $footers}
{$footer}{\n}
{/foreach}
{/for}
{/template}

View File

@ -22,8 +22,8 @@
{template .FooterHtml}
{\n}
{\n}
{foreach $footer in $footers}
{for $footer in $footers}
<div style="display:none">{sp}{$footer}{sp}</div>{\n}
{/foreach}
{/for}
{\n}
{/template}

View File

@ -28,10 +28,10 @@
{template .NewChange kind="text"}
{if $email.reviewerNames}
Hello{sp}
{foreach $reviewerName in $email.reviewerNames}
{for $reviewerName in $email.reviewerNames}
{if not isFirst($reviewerName)},{sp}{/if}
{$reviewerName}
{/foreach},
{/for},
{\n}
{\n}

View File

@ -28,12 +28,12 @@
<p>
{if $email.reviewerNames}
{$fromName} would like{sp}
{foreach $reviewerName in $email.reviewerNames}
{for $reviewerName in $email.reviewerNames}
{if not isFirst($reviewerName)}
{if isLast($reviewerName)}{sp}and{else},{/if}{sp}
{/if}
{$reviewerName}
{/foreach}{sp}
{/for}{sp}
to <strong>review</strong> this change.
{else}
{$ownerName} has uploaded this change for <strong>review</strong>.

View File

@ -68,7 +68,7 @@
word-wrap: break-word;
{/let}
{foreach $block in $content}
{for $block in $content}
{if $block.type == 'paragraph'}
<p style="{$pStyle}">{$block.text|changeNewlineToBr}</p>
{elseif $block.type == 'quote'}
@ -79,12 +79,12 @@
{call .Pre}{param content: $block.text /}{/call}
{elseif $block.type == 'list'}
<ul>
{foreach $item in $block.items}
{for $item in $block.items}
<li>{$item}</li>
{/foreach}
{/for}
</ul>
{/if}
{/foreach}
{/for}
{/template}
/**
@ -106,7 +106,7 @@
{/let}
<pre style="{$preStyle}">
{foreach $line in $diffLines}
{for $line in $diffLines}
{if $line.type == 'add'}
<span style="{$addStyle}">
{elseif $line.type == 'remove'}
@ -116,6 +116,6 @@
{/if}
{$line.text}
</span><br>
{/foreach}
{/for}
</pre>
{/template}

View File

@ -29,9 +29,9 @@
{template .ReplacePatchSet kind="text"}
{if $email.reviewerNames and $fromEmail == $change.ownerEmail}
Hello{sp}
{foreach $reviewerName in $email.reviewerNames}
{for $reviewerName in $email.reviewerNames}
{$reviewerName},{sp}
{/foreach}{\n}
{/for}{\n}
{\n}
I'd like you to reexamine a change.
{if $email.changeUrl}