use of com.google.template.soy.data.SoyListData in project gitiles by GerritCodeReview.
the class PathServletTest method fileHtml.
@Test
public void fileHtml() throws Exception {
repo.branch("master").commit().add("foo", "foo\ncontents\n").create();
Map<String, ?> data = buildData("/repo/+/master/foo");
assertThat(data).containsEntry("type", "REGULAR_FILE");
SoyListData lines = (SoyListData) getBlobData(data).get("lines");
assertThat(lines.length()).isEqualTo(2);
SoyListData spans = lines.getListData(0);
assertThat(spans.length()).isEqualTo(1);
assertThat(spans.getMapData(0).get("classes")).isEqualTo(StringData.forValue("pln"));
assertThat(spans.getMapData(0).get("text")).isEqualTo(StringData.forValue("foo"));
spans = lines.getListData(1);
assertThat(spans.length()).isEqualTo(1);
assertThat(spans.getMapData(0).get("classes")).isEqualTo(StringData.forValue("pln"));
assertThat(spans.getMapData(0).get("text")).isEqualTo(StringData.forValue("contents"));
}
use of com.google.template.soy.data.SoyListData in project gitiles by GerritCodeReview.
the class HostIndexServletTest method fooBarSubdirHtml.
@Test
public void fooBarSubdirHtml() throws Exception {
Map<String, ?> data = buildData("/foo/bar/");
assertThat(data).containsEntry("hostName", URLS.getHostName(null) + "/foo/bar");
assertThat(data).containsEntry("prefix", "foo/bar/");
SoyListData breadcrumbs = (SoyListData) data.get("breadcrumbs");
assertThat(breadcrumbs.length()).isEqualTo(3);
SoyListData repos = (SoyListData) data.get("repositories");
assertThat(repos.length()).isEqualTo(1);
SoyMapData ent = (SoyMapData) repos.get(0);
assertThat(ent.get("name").toString()).isEqualTo("repo");
assertThat(ent.get("url").toString()).isEqualTo("/b/" + NAME + "/");
}
use of com.google.template.soy.data.SoyListData in project gitiles by GerritCodeReview.
the class HostIndexServletTest method fooSubdirHtml.
@Test
public void fooSubdirHtml() throws Exception {
Map<String, ?> data = buildData("/foo/");
assertThat(data).containsEntry("hostName", URLS.getHostName(null) + "/foo");
assertThat(data).containsEntry("prefix", "foo/");
SoyListData breadcrumbs = (SoyListData) data.get("breadcrumbs");
assertThat(breadcrumbs.length()).isEqualTo(2);
SoyListData repos = (SoyListData) data.get("repositories");
assertThat(repos.length()).isEqualTo(1);
SoyMapData ent = (SoyMapData) repos.get(0);
assertThat(ent.get("name").toString()).isEqualTo("bar/repo");
assertThat(ent.get("url").toString()).isEqualTo("/b/" + NAME + "/");
}
use of com.google.template.soy.data.SoyListData in project gerrit by GerritCodeReview.
the class ChangeEmail method getDiffTemplateData.
/**
* Generate a Soy list of maps representing each line of the unified diff. The line maps will have
* a 'type' key which maps to one of 'common', 'add' or 'remove' and a 'text' key which maps to
* the line's content.
*/
private SoyListData getDiffTemplateData() {
SoyListData result = new SoyListData();
Splitter lineSplitter = Splitter.on(System.getProperty("line.separator"));
for (String diffLine : lineSplitter.split(getUnifiedDiff())) {
SoyMapData lineData = new SoyMapData();
lineData.put("text", diffLine);
// Skip empty lines and lines that look like diff headers.
if (diffLine.isEmpty() || diffLine.startsWith("---") || diffLine.startsWith("+++")) {
lineData.put("type", "common");
} else {
switch(diffLine.charAt(0)) {
case '+':
lineData.put("type", "add");
break;
case '-':
lineData.put("type", "remove");
break;
default:
lineData.put("type", "common");
break;
}
}
result.add(lineData);
}
return result;
}
use of com.google.template.soy.data.SoyListData in project gitiles by GerritCodeReview.
the class BlobSoyData method writeResult.
private static void writeResult(SoyListData lines, String classes, String s, int start, int end) {
SoyListData line = lines.getListData(lines.length() - 1);
while (true) {
int nl = nextLineBreak(s, start, end);
if (nl < 0) {
break;
}
addSpan(line, classes, s, start, nl);
start = nl + 1;
if (start == s.length()) {
return;
}
line = new SoyListData();
lines.add(line);
}
addSpan(line, classes, s, start, end);
}
Aggregations