use of com.google.template.soy.data.SoyListData in project buck by facebook.
the class TracesHandlerDelegate method getTraces.
@VisibleForTesting
SoyListData getTraces() throws IOException {
List<Path> traceFiles = buildTraces.listTraceFilesByLastModified();
SoyListData traces = new SoyListData();
for (Path path : traceFiles) {
String name = path.getFileName().toString();
Matcher matcher = TRACE_FILE_NAME_PATTERN.matcher(name);
if (!matcher.matches()) {
// Could be build.trace or launch.xxx.trace.
continue;
}
SoyMapData trace = new SoyMapData();
trace.put("name", name);
trace.put("id", matcher.group(1));
TraceAttributes traceAttributes = buildTraces.getTraceAttributesFor(path);
trace.put("dateTime", traceAttributes.getFormattedDateTime());
if (traceAttributes.getCommand().isPresent()) {
trace.put("command", traceAttributes.getCommand().get());
} else {
trace.put("command", "");
}
traces.add(trace);
}
return traces;
}
use of com.google.template.soy.data.SoyListData in project gitiles by GerritCodeReview.
the class BlobSoyData method prettify.
private SoyListData prettify(String path, String content) {
List<ParseResult> results = parse(path, content);
SoyListData lines = new SoyListData();
SoyListData line = new SoyListData();
lines.add(line);
int last = 0;
for (ParseResult r : results) {
checkState(r.getOffset() >= last, "out-of-order ParseResult, expected %s >= %s", r.getOffset(), last);
writeResult(lines, null, content, last, r.getOffset());
last = r.getOffset() + r.getLength();
writeResult(lines, r.getStyleKeysString(), content, r.getOffset(), last);
}
if (last < content.length()) {
writeResult(lines, null, content, last, content.length());
}
return lines;
}
use of com.google.template.soy.data.SoyListData in project gitiles by GerritCodeReview.
the class HostIndexServlet method doGetHtml.
@Override
protected void doGetHtml(HttpServletRequest req, HttpServletResponse res) throws IOException {
GitilesView view = ViewFilter.getView(req);
String prefix = view.getRepositoryPrefix();
Map<String, RepositoryDescription> descs = list(req, res, prefix, parseShowBranch(req));
if (descs == null) {
return;
}
SoyListData repos = new SoyListData();
for (RepositoryDescription desc : descs.values()) {
if (prefix == null || desc.name.startsWith(prefix)) {
repos.add(toSoyMapData(desc, prefix, view));
}
}
String hostName = urls.getHostName(req);
List<Map<String, String>> breadcrumbs = null;
if (prefix != null) {
hostName = hostName + '/' + prefix;
breadcrumbs = view.getBreadcrumbs();
}
renderHtml(req, res, "gitiles.hostIndex", ImmutableMap.of("hostName", hostName, "breadcrumbs", breadcrumbs != null ? new SoyListData(breadcrumbs) : NullData.INSTANCE, "prefix", prefix != null ? prefix + '/' : "", "repositories", repos));
}
use of com.google.template.soy.data.SoyListData in project gitiles by GerritCodeReview.
the class BlameServlet method toSoyData.
private static SoyListData toSoyData(GitilesView view, ObjectReader reader, List<Region> regions, DateFormatter df) throws IOException {
Map<ObjectId, String> abbrevShas = Maps.newHashMap();
SoyListData result = new SoyListData();
for (int i = 0; i < regions.size(); i++) {
Region r = regions.get(i);
int c = i % CLASSES.size();
if (r.getSourceCommit() == null) {
// JGit bug may fail to blame some regions. We should fix this
// upstream, but handle it for now.
result.add(NULLS.get(c));
} else {
String abbrevSha = abbrevShas.get(r.getSourceCommit());
if (abbrevSha == null) {
abbrevSha = reader.abbreviate(r.getSourceCommit()).name();
abbrevShas.put(r.getSourceCommit(), abbrevSha);
}
Map<String, Object> e = Maps.newHashMapWithExpectedSize(6);
e.put("abbrevSha", abbrevSha);
String blameParent = "";
String blameText = "blame";
if (view.getRevision().getName().equals(r.getSourceCommit().name())) {
blameParent = "^";
blameText = "blame^";
}
e.put("blameUrl", GitilesView.blame().copyFrom(view).setRevision(r.getSourceCommit().name() + blameParent).setPathPart(r.getSourcePath()).toUrl());
e.put("blameText", blameText);
e.put("commitUrl", GitilesView.revision().copyFrom(view).setRevision(r.getSourceCommit().name()).toUrl());
e.put("diffUrl", GitilesView.diff().copyFrom(view).setRevision(r.getSourceCommit().name()).setPathPart(r.getSourcePath()).toUrl());
e.put("author", CommitSoyData.toSoyData(r.getSourceAuthor(), df));
e.put("class", CLASSES.get(c));
result.add(e);
}
// single block.
for (int j = 0; j < r.getCount() - 1; j++) {
result.add(NULLS.get(c));
}
}
return result;
}
use of com.google.template.soy.data.SoyListData in project gitiles by GerritCodeReview.
the class HostIndexServletTest method rootHtml.
@Test
public void rootHtml() throws Exception {
Map<String, ?> data = buildData("/");
assertThat(data).containsEntry("hostName", URLS.getHostName(null));
assertThat(data).containsEntry("breadcrumbs", NullData.INSTANCE);
assertThat(data).containsEntry("prefix", "");
SoyListData repos = (SoyListData) data.get("repositories");
assertThat(repos).hasSize(1);
SoyMapData ent = (SoyMapData) repos.get(0);
assertThat(ent.get("name").toString()).isEqualTo(NAME);
assertThat(ent.get("url").toString()).isEqualTo("/b/" + NAME + "/");
}
Aggregations