From 57073ffd9de11d59abb7e533c1b3b5cf3694f2e3 Mon Sep 17 00:00:00 2001
From: Luke Sandberg
Date: Thu, 4 Jan 2018 13:08:51 -0500
Subject: [PATCH] Change all foreach loops in Soy templates to use for loop
syntax
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
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] https://github.com/google/closure-templates/commit/4a7373333fee6c22784b48e29825b9cea3ffaae7
PiperOrigin-RevId: 180807358
Change-Id: I6f6416b4265d7fb1a7f933bc9ed24466b3637d40
---
.../com/google/gerrit/server/mail/Comment.soy | 12 ++++++------
.../google/gerrit/server/mail/CommentHtml.soy | 16 ++++++++--------
.../google/gerrit/server/mail/DeleteReviewer.soy | 4 ++--
.../gerrit/server/mail/DeleteReviewerHtml.soy | 4 ++--
.../com/google/gerrit/server/mail/Footer.soy | 4 ++--
.../com/google/gerrit/server/mail/FooterHtml.soy | 4 ++--
.../com/google/gerrit/server/mail/NewChange.soy | 4 ++--
.../google/gerrit/server/mail/NewChangeHtml.soy | 4 ++--
.../com/google/gerrit/server/mail/Private.soy | 12 ++++++------
.../gerrit/server/mail/ReplacePatchSet.soy | 4 ++--
10 files changed, 34 insertions(+), 34 deletions(-)
diff --git a/resources/com/google/gerrit/server/mail/Comment.soy b/resources/com/google/gerrit/server/mail/Comment.soy
index 7f3062cb4f..31704483ff 100644
--- a/resources/com/google/gerrit/server/mail/Comment.soy
+++ b/resources/com/google/gerrit/server/mail/Comment.soy
@@ -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}
diff --git a/resources/com/google/gerrit/server/mail/CommentHtml.soy b/resources/com/google/gerrit/server/mail/CommentHtml.soy
index 6917736762..d554258c5c 100644
--- a/resources/com/google/gerrit/server/mail/CommentHtml.soy
+++ b/resources/com/google/gerrit/server/mail/CommentHtml.soy
@@ -79,7 +79,7 @@
{if length($labels) > 0}
Patch set {$patchSet.patchSetId}:
- {foreach $label in $labels}
+ {for $label in $labels}
{if $label.value > 0}
{$label.label}{sp}+{$label.value}
@@ -93,7 +93,7 @@
-{$label.label}
{/if}
- {/foreach}
+ {/for}
{/if}
@@ -110,14 +110,14 @@
{/if}
- {foreach $group in $commentFiles}
+ {for $group in $commentFiles}
-
{$group.title}:
- {foreach $comment in $group.comments}
+ {for $comment in $group.comments}
-
{if $comment.isRobotComment}
@@ -149,9 +149,9 @@
{call .Pre}{param content kind="html"}
- {foreach $line in $comment.lines}
+ {for $line in $comment.lines}
{$line}{\n}
- {/foreach}
+ {/for}
{/param}{/call}
@@ -167,9 +167,9 @@
{call .WikiFormat}{param content: $comment.messageBlocks /}{/call}
- {/foreach}
+ {/for}
- {/foreach}
+ {/for}
{/template}
diff --git a/resources/com/google/gerrit/server/mail/DeleteReviewer.soy b/resources/com/google/gerrit/server/mail/DeleteReviewer.soy
index fc1d60f54a..065348ace9 100644
--- a/resources/com/google/gerrit/server/mail/DeleteReviewer.soy
+++ b/resources/com/google/gerrit/server/mail/DeleteReviewer.soy
@@ -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}
diff --git a/resources/com/google/gerrit/server/mail/DeleteReviewerHtml.soy b/resources/com/google/gerrit/server/mail/DeleteReviewerHtml.soy
index f73e3872f3..0599b52480 100644
--- a/resources/com/google/gerrit/server/mail/DeleteReviewerHtml.soy
+++ b/resources/com/google/gerrit/server/mail/DeleteReviewerHtml.soy
@@ -25,12 +25,12 @@
{$fromName}{sp}
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}
{sp}
from this change.
diff --git a/resources/com/google/gerrit/server/mail/Footer.soy b/resources/com/google/gerrit/server/mail/Footer.soy
index 2b146ecf53..e1890a8139 100644
--- a/resources/com/google/gerrit/server/mail/Footer.soy
+++ b/resources/com/google/gerrit/server/mail/Footer.soy
@@ -23,7 +23,7 @@
* @param footers
*/
{template .Footer kind="text"}
- {foreach $footer in $footers}
+ {for $footer in $footers}
{$footer}{\n}
- {/foreach}
+ {/for}
{/template}
diff --git a/resources/com/google/gerrit/server/mail/FooterHtml.soy b/resources/com/google/gerrit/server/mail/FooterHtml.soy
index 22929d1e6f..938655c73d 100644
--- a/resources/com/google/gerrit/server/mail/FooterHtml.soy
+++ b/resources/com/google/gerrit/server/mail/FooterHtml.soy
@@ -22,8 +22,8 @@
{template .FooterHtml}
{\n}
{\n}
- {foreach $footer in $footers}
+ {for $footer in $footers}
{sp}{$footer}{sp}
{\n}
- {/foreach}
+ {/for}
{\n}
{/template}
diff --git a/resources/com/google/gerrit/server/mail/NewChange.soy b/resources/com/google/gerrit/server/mail/NewChange.soy
index ca24d1959b..f11edfee7e 100644
--- a/resources/com/google/gerrit/server/mail/NewChange.soy
+++ b/resources/com/google/gerrit/server/mail/NewChange.soy
@@ -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}
diff --git a/resources/com/google/gerrit/server/mail/NewChangeHtml.soy b/resources/com/google/gerrit/server/mail/NewChangeHtml.soy
index 16b0df4ab3..5bce8065b0 100644
--- a/resources/com/google/gerrit/server/mail/NewChangeHtml.soy
+++ b/resources/com/google/gerrit/server/mail/NewChangeHtml.soy
@@ -28,12 +28,12 @@
{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 review this change.
{else}
{$ownerName} has uploaded this change for review.
diff --git a/resources/com/google/gerrit/server/mail/Private.soy b/resources/com/google/gerrit/server/mail/Private.soy
index 5840223b40..bb32a7e920 100644
--- a/resources/com/google/gerrit/server/mail/Private.soy
+++ b/resources/com/google/gerrit/server/mail/Private.soy
@@ -68,7 +68,7 @@
word-wrap: break-word;
{/let}
- {foreach $block in $content}
+ {for $block in $content}
{if $block.type == 'paragraph'}
{$block.text|changeNewlineToBr}
{elseif $block.type == 'quote'}
@@ -79,12 +79,12 @@
{call .Pre}{param content: $block.text /}{/call}
{elseif $block.type == 'list'}
- {foreach $item in $block.items}
+ {for $item in $block.items}
- {$item}
- {/foreach}
+ {/for}
{/if}
- {/foreach}
+ {/for}
{/template}
/**
@@ -106,7 +106,7 @@
{/let}
- {foreach $line in $diffLines}
+ {for $line in $diffLines}
{if $line.type == 'add'}
{elseif $line.type == 'remove'}
@@ -116,6 +116,6 @@
{/if}
{$line.text}
- {/foreach}
+ {/for}
{/template}
diff --git a/resources/com/google/gerrit/server/mail/ReplacePatchSet.soy b/resources/com/google/gerrit/server/mail/ReplacePatchSet.soy
index 124cdf300c..1cb0110390 100644
--- a/resources/com/google/gerrit/server/mail/ReplacePatchSet.soy
+++ b/resources/com/google/gerrit/server/mail/ReplacePatchSet.soy
@@ -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}