Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow environment variables to be passed to the compiler #28

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions compiler-cli/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
java_binary(
name = "compiler-cli",
runtime_deps = ["@twirl//:com_lucidchart_twirl_compiler_cli"],
main_class = "rulestwirl.twirl.CommandLineTwirlTemplateCompiler",
visibility = ["//visibility:public"]
name = "compiler-cli",
main_class = "rulestwirl.twirl.CommandLineTwirlTemplateCompiler",
visibility = ["//visibility:public"],
runtime_deps = ["@twirl//:com_lucidchart_twirl_compiler_cli"],
)
105 changes: 64 additions & 41 deletions test/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -2,54 +2,77 @@ load("@rules_scala_annex//rules:scala.bzl", "scala_test")
load("//twirl:twirl.bzl", "twirl_templates")

twirl_templates(
name = "twirl-test-templates-basic",
visibility = ["//visibility:public"],
source_directory = "twirl-templates",
srcs = [
"twirl-templates/twirl/com/foo/views/hello.scala.html",
"twirl-templates/twirl/com/foo/views/hello.scala.txt",
"twirl-templates/twirl/com/foo/views/hello.scala.xml",
"twirl-templates/twirl/com/foo/views/hello.scala.js",
],
name = "twirl-test-templates-basic",
srcs = [
"twirl-templates/twirl/com/foo/views/hello.scala.html",
"twirl-templates/twirl/com/foo/views/hello.scala.js",
"twirl-templates/twirl/com/foo/views/hello.scala.txt",
"twirl-templates/twirl/com/foo/views/hello.scala.xml",
],
source_directory = "twirl-templates",
visibility = ["//visibility:public"],
)

twirl_templates(
name = "twirl-test-templates-additional-imports",
visibility = ["//visibility:public"],
source_directory = "twirl-templates",
srcs = [
"twirl-templates/twirl/com/foo/views/addImports.scala.txt",
],
additional_imports = ["rulestwirl.test.Person"],
name = "twirl-test-templates-additional-imports",
srcs = [
"twirl-templates/twirl/com/foo/views/addImports.scala.txt",
],
additional_imports = ["rulestwirl.test.Person"],
source_directory = "twirl-templates",
visibility = ["//visibility:public"],
)

twirl_templates(
name = "twirl-test-templates-custom-formatter",
visibility = ["//visibility:public"],
source_directory = "twirl-templates",
srcs = [
"twirl-templates/twirl/com/foo/views/customFormatter.scala.txt",
],
additional_imports = ["rulestwirl.test.Person"],
template_formats = {
"txt": "rulestwirl.test.StrangeTxtFormat"
},
name = "twirl-test-templates-custom-formatter",
srcs = [
"twirl-templates/twirl/com/foo/views/customFormatter.scala.txt",
],
additional_imports = ["rulestwirl.test.Person"],
source_directory = "twirl-templates",
template_formats = {
"txt": "rulestwirl.test.StrangeTxtFormat",
},
visibility = ["//visibility:public"],
)

scala_test(
name = "twirl-compiler-test",
srcs = [
"TwirlCompilerTest.scala",
"Person.scala",
"StrangeTxtFormatter.scala",
":twirl-test-templates-basic",
":twirl-test-templates-additional-imports",
":twirl-test-templates-custom-formatter",
],
deps = [
"@twirl_test//:com_typesafe_play_twirl_api_2_12",
"@twirl_test//:org_specs2_specs2_common_2_12",
"@twirl_test//:org_specs2_specs2_core_2_12",
"@twirl_test//:org_specs2_specs2_matcher_2_12",
],
name = "twirl-compiler-test",
srcs = [
"Person.scala",
"StrangeTxtFormatter.scala",
"TwirlCompilerTest.scala",
":twirl-test-templates-additional-imports",
":twirl-test-templates-basic",
":twirl-test-templates-custom-formatter",
],
deps = [
"@twirl_test//:com_typesafe_play_twirl_api_2_12",
"@twirl_test//:org_specs2_specs2_common_2_12",
"@twirl_test//:org_specs2_specs2_core_2_12",
"@twirl_test//:org_specs2_specs2_matcher_2_12",
],
)

twirl_templates(
name = "twirl-test-templates-utf8",
srcs = [
"twirl-templates/twirl/com/foo/utf8/hello.scala.html",
"twirl-templates/twirl/com/foo/utf8/hello.scala.txt",
],
source_directory = "twirl-templates",
)

scala_test(
name = "twirl-compiler-utf8-test",
srcs = [
"UTF8TwirlCompilerTest.scala",
":twirl-test-templates-utf8",
],
deps = [
"@twirl_test//:com_typesafe_play_twirl_api_2_12",
"@twirl_test//:org_specs2_specs2_common_2_12",
"@twirl_test//:org_specs2_specs2_core_2_12",
"@twirl_test//:org_specs2_specs2_matcher_2_12",
],
)
24 changes: 24 additions & 0 deletions test/UTF8TwirlCompilerTest.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package rulestwirl.test

import org.specs2.mutable.Specification

class UTF8TwirlCompilerTest extends Specification {

"Twirl Template Compiler when run through Bazel with UTF8 encoding set" should {
"Compile html Twirl Templates" in {
import twirl.com.foo.utf8.html.hello
val name = "Fred"
val age = 37
val template = hello.render(name, age)
template.body mustEqual s"<html>’$name’, age: $age</html>"
}

"Compile txt Twirl Templates" in {
import twirl.com.foo.utf8.txt.hello
val name = "Oliver"
val age = 28
val template = hello.render(name, age)
template.body mustEqual s"$name, age – $age"
}
}
}
1 change: 1 addition & 0 deletions test/twirl-templates/twirl/com/foo/utf8/hello.scala.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@(name: String, age: Int = 42)<html>’@name’, age: @age</html>
1 change: 1 addition & 0 deletions test/twirl-templates/twirl/com/foo/utf8/hello.scala.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@(name: String, age: Int = 42)@name, age – @age
3 changes: 3 additions & 0 deletions test/twirl_compiler_bazel_e2e_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@
set -e

bazel test //test:twirl-compiler-test

# Added an extra option of logback.configurationFile just to show that the encoding will be used regardless of other JVM options used.
bazel test --action_env JAVA_TOOL_OPTIONS="-Dlogback.configurationFile=/path/to/config.xml -Dfile.encoding=UTF-8" //test:twirl-compiler-utf8-test
1 change: 1 addition & 0 deletions twirl/twirl.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ def _impl(ctx):
arguments = [args],
mnemonic = "TwirlCompile",
execution_requirements = {"supports-workers": "1"},
use_default_shell_env = True,
progress_message = "Compiling twirl template",
executable = ctx.executable.twirl_compiler,
)
Expand Down