Skip to content

Commit

Permalink
supporting code for issue google#221
Browse files Browse the repository at this point in the history
  • Loading branch information
Rob Figueiredo committed Dec 1, 2020
1 parent 6223fef commit caaba74
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 0 deletions.
14 changes: 14 additions & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,17 @@ package_group(
"//...",
],
)

java_binary(
name = "CompileSoy",
srcs = ["CompileSoy.java"],
main_class = "main.CompileSoy",
deps = [
"//java/src/com/google/template/soy",
"//java/src/com/google/template/soy/error",
"//java/src/com/google/template/soy/error:soy_error_api",
"@maven//:com_google_guava_guava",
"@maven//:com_google_inject_extensions_guice_multibindings",
"@maven//:com_google_inject_guice",
],
)
28 changes: 28 additions & 0 deletions CompileSoy.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package main;

import java.io.File;

import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.template.soy.SoyFileSet;
import com.google.template.soy.SoyModule;
import com.google.template.soy.error.SoyCompilationException;
import com.google.template.soy.error.SoyError;

public class CompileSoy {
public static void main(String[] args) throws Exception {
Injector injector = Guice.createInjector(new SoyModule());
SoyFileSet.Builder fsBuilder =
injector
.getInstance(SoyFileSet.Builder.class)
.setAllowExternalCalls(false)
.add(new File(args[0]));
try {
fsBuilder.build().compileTemplates();
} catch (SoyCompilationException e) {
for (SoyError err : e.getErrors()) {
System.out.println(err);
}
}
}
}
8 changes: 8 additions & 0 deletions test.soy
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{namespace main}

{template .main}
{@param appName: string}
<link rel="stylesheet"
type="text/css"
href="/{$appName}/public/stylesheets/styles.css">
{/template}

0 comments on commit caaba74

Please sign in to comment.