Skip to content

Commit

Permalink
Remove soy dependency from WebFiles (#629)
Browse files Browse the repository at this point in the history
This is in preparation of removing soy dependency from rules_closure.
  • Loading branch information
gkdn authored Nov 27, 2024
1 parent 5c122e7 commit 1f6bda7
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 101 deletions.
8 changes: 0 additions & 8 deletions java/io/bazel/rules/closure/webfiles/server/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,13 @@ licenses(["notice"])

load("@rules_proto//proto:defs.bzl", "proto_library")
load("@rules_java//java:defs.bzl", "java_binary", "java_library", "java_proto_library")
load("//closure:defs.bzl", "closure_java_template_library")

java_library(
name = "server",
srcs = glob(["*.java"]),
visibility = ["//:__subpackages__"],
deps = [
":build_info_java_proto",
":listing",
"//java/io/bazel/rules/closure:webpath",
"//java/io/bazel/rules/closure/http",
"//java/io/bazel/rules/closure/http/filter",
Expand All @@ -33,7 +31,6 @@ java_library(
"@com_google_dagger",
"@com_google_guava",
"@com_google_protobuf//:protobuf_java",
"@com_google_template_soy",
],
)

Expand All @@ -54,8 +51,3 @@ java_proto_library(
visibility = ["//visibility:public"],
deps = [":build_info_proto"],
)

closure_java_template_library(
name = "listing",
srcs = ["listing.soy"],
)
68 changes: 34 additions & 34 deletions java/io/bazel/rules/closure/webfiles/server/ListingPage.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,8 @@

package io.bazel.rules.closure.webfiles.server;

import static com.google.common.io.Resources.getResource;

import com.google.common.base.Functions;
import com.google.common.base.Predicate;
import com.google.common.collect.FluentIterable;
import com.google.common.collect.ImmutableSet;
import com.google.common.net.MediaType;
import com.google.template.soy.SoyFileSet;
import com.google.template.soy.data.SoyListData;
import com.google.template.soy.data.SoyMapData;
import com.google.template.soy.tofu.SoyTofu;
import io.bazel.rules.closure.Webpath;
import io.bazel.rules.closure.http.HttpResponse;
import java.io.IOException;
Expand All @@ -38,12 +29,6 @@
*/
class ListingPage {

private static final SoyTofu TOFU =
SoyFileSet.builder()
.add(getResource(ListingSoyInfo.class, ListingSoyInfo.getInstance().getFileName()))
.build()
.compileToTofu();

private final HttpResponse response;
private final Metadata.Config config;
private final ImmutableSet<Webpath> webpaths;
Expand All @@ -56,25 +41,40 @@ class ListingPage {
}

void serve(final Webpath webpath) throws IOException {
StringBuilder builder = new StringBuilder();
builder.append("<!doctype html>");
builder.append("<link href='//fonts.googleapis.com/css?family=Roboto' rel='stylesheet'>");
builder.append("<style>");
builder.append("body {");
builder.append(" font-family: 'Roboto', sans-serif;");
builder.append(" margin: 0 auto;");
builder.append(" padding: 0 1em;");
builder.append(" width: 960px;");
builder.append(" color: #333;");
builder.append("}");
builder.append("a {");
builder.append(" text-decoration: none;");
builder.append("}");
builder.append("h1 {");
builder.append(" margin-bottom: 0;");
builder.append("}");
builder.append("h3 {");
builder.append(" margin-top: 0;");
builder.append(" color: #999;");
builder.append("}");
builder.append("</style>");
builder.append("<h1>Bazel Closure Rules</h1>");
builder.append("<h3>").append(config.get().getLabel()).append("</h3>");
builder.append("<p>");
if (webpaths.isEmpty()) {
builder.append("No srcs found in transitive closure with path component prefix matching");
builder.append("request path.");
} else {
webpaths.stream()
.filter(path -> path.startsWith(webpath))
.forEach(path -> builder.append("<a href=\"" + path + "\">" + path + "</a><br>"));
}
response.setContentType(MediaType.HTML_UTF_8);
response.setPayload(
TOFU.newRenderer(ListingSoyInfo.LISTING)
.setData(
new SoyMapData(
ListingSoyInfo.ListingSoyTemplateInfo.LABEL,
config.get().getLabel(),
ListingSoyInfo.ListingSoyTemplateInfo.PATHS,
new SoyListData(
FluentIterable.from(webpaths)
.filter(
new Predicate<Webpath>() {
@Override
public boolean apply(Webpath path) {
return path.startsWith(webpath);
}
})
.transform(Functions.toStringFunction()))))
.render()
.getBytes(StandardCharsets.UTF_8));
response.setPayload(builder.toString().getBytes(StandardCharsets.UTF_8));
}
}
59 changes: 0 additions & 59 deletions java/io/bazel/rules/closure/webfiles/server/listing.soy

This file was deleted.

0 comments on commit 1f6bda7

Please sign in to comment.