use of com.google.template.soy.data.SoyMapData in project gerrit by GerritCodeReview.
the class IndexServlet method getTemplateData.
static SoyMapData getTemplateData(String canonicalURL, String cdnPath) throws URISyntaxException {
String canonicalPath = computeCanonicalPath(canonicalURL);
String staticPath = "";
if (cdnPath != null) {
staticPath = cdnPath;
} else if (canonicalPath != null) {
staticPath = canonicalPath;
}
// The resource path must be typed as safe for use in a script src.
// TODO(wyatta): Upgrade this to use an appropriate safe URL type.
SanitizedContent sanitizedStaticPath = UnsafeSanitizedContentOrdainer.ordainAsSafe(staticPath, SanitizedContent.ContentKind.TRUSTED_RESOURCE_URI);
return new SoyMapData("canonicalPath", canonicalPath, "staticResourcePath", sanitizedStaticPath);
}
use of com.google.template.soy.data.SoyMapData in project gerrit by GerritCodeReview.
the class IndexServletTest method noPathAndNoCDN.
@Test
public void noPathAndNoCDN() throws URISyntaxException {
SoyMapData data = IndexServlet.getTemplateData("http://example.com/", null);
assertThat(data.getSingle("canonicalPath").stringValue()).isEqualTo("");
assertThat(data.getSingle("staticResourcePath").stringValue()).isEqualTo("");
}
use of com.google.template.soy.data.SoyMapData in project gerrit by GerritCodeReview.
the class IndexServletTest method pathAndCDN.
@Test
public void pathAndCDN() throws URISyntaxException {
SoyMapData data = IndexServlet.getTemplateData("http://example.com/gerrit", "http://my-cdn.com/foo/bar/");
assertThat(data.getSingle("canonicalPath").stringValue()).isEqualTo("/gerrit");
assertThat(data.getSingle("staticResourcePath").stringValue()).isEqualTo("http://my-cdn.com/foo/bar/");
}
use of com.google.template.soy.data.SoyMapData 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.SoyMapData in project buck by facebook.
the class TemplateHandler method createHtmlForResponse.
@Nullable
String createHtmlForResponse(Request baseRequest) throws IOException {
String template = delegate.getTemplateForRequest(baseRequest);
SoyTofu.Renderer renderer = createAndMaybeCacheSoyTofu().newRenderer(template);
SoyMapData data = delegate.getDataForRequest(baseRequest);
if (data != null) {
renderer.setData(data);
return renderer.render();
} else {
return null;
}
}
Aggregations