diff --git a/README.md b/README.md index 7603d68..3bfbf71 100644 --- a/README.md +++ b/README.md @@ -5,65 +5,46 @@ | [![Build Status](https://github.com/lucidsoftware/rules_twirl/workflows/CI/badge.svg)](https://github.com/lucidsoftware/rules_twirl/actions) | [Stardoc](docs/stardoc/twirl.md) | ## Overview -`rules_twirl` compiles [Twirl](https://github.com/playframework/twirl) templates to [Scala](http://www.scala-lang.org/), so they can be used with [`bazelbuild/rules_scala`](https://github.com/bazelbuild/rules_scala) and [`higherkindness/rules_scala`](https://github.com/higherkindness/rules_scala). + +`rules_twirl` compiles [Twirl](https://github.com/playframework/twirl) templates to +[Scala](http://www.scala-lang.org/), so they can be used with +[`bazelbuild/rules_scala`](https://github.com/bazelbuild/rules_scala) and +[`lucidsoftware/rules_scala`](https://github.com/lucidsoftware/rules_scala). Simple Core API: [twirl_templates](docs/stardoc/twirl.md) -For more information about Twirl templates, see [the Play Twirl documentation](https://www.playframework.com/documentation/latest/ScalaTemplates#the-template-engine). +For more information about Twirl templates, see +[the Play Twirl documentation](https://www.playframework.com/documentation/latest/ScalaTemplates#the-template-engine). ## Installation -Create a file called at the top of your repository named `WORKSPACE` and add the following snippet to it. - -```python -# update version as needed -rules_twirl_version = "TODO" -http_archive( - name = "rules_twirl", - sha256 = "TODO", - strip_prefix = "rules_twirl-{}".format(rules_twirl_version), - type = "zip", - url = "https://github.com/lucidsoftware/rules_twirl/archive/{}.zip".format(rules_twirl_version), -) -# rules_jvm_external -rules_jvm_external_version = "6.2" +`rules_twirl` isn't yet on the [Bazel Central Registry](https://registry.bazel.build/), so you'll +need to pull it in via `archive_override`. Be sure to replace `` with latest commit on +`master` and `` with the hash suggested by Bazel after the dependency is first loaded. -http_archive( - name = "rules_jvm_external", - sha256 = "aa39ecd47e16d5870eba817fe71476802bc371fe2724a2ddee565992df55f4af", - strip_prefix = "rules_jvm_external-{}".format(rules_jvm_external_version), - type = "zip", - url = "https://github.com/bazelbuild/rules_jvm_external/archive/{}.zip".format(rules_jvm_external_version), -) +*/MODULE.bazel* -load("@rules_jvm_external//:repositories.bzl", "rules_jvm_external_deps") -rules_jvm_external_deps() +```starlark +bazel_dep(name = "rules_twirl") -load("@rules_jvm_external//:setup.bzl", "rules_jvm_external_setup") -rules_jvm_external_setup() +rules_twirl_version = "" -load( - "@rules_twirl//:workspace.bzl", - "twirl_compiler_cli_2_13_repositories", - "twirl_compiler_cli_3_repositories", +archive_override( + module_name = "rules_twirl", + integrity = "", + strip_prefix = "rules_twirl-{}".format(rules_twirl_version), + urls = ["https://github.com/lucidsoftware/rules_twirl/archive/refs/heads/{}.zip".format(rules_twirl_version)], ) -twirl_compiler_cli_3_repositories() -load("@twirl_compiler_cli_3//:defs.bzl", twirl_compiler_cli_3_pinned_maven_install = "pinned_maven_install") -twirl_compiler_cli_3_pinned_maven_install() +``` -twirl_compiler_cli_2_13_repositories() -load("@twirl_compiler_cli_2_13//:defs.bzl", twirl_compiler_cli_2_13_pinned_maven_install = "pinned_maven_install") -twirl_compiler_cli_2_13_pinned_maven_install() +By default, the Scala 3 version of the Twirl compiler will be used. To change the default to +Scala 2.13, add the `--@rules_twirl//twirl-toolchain=twirl-2-13` flag to your `.bazelrc` file. -# Twirl compiler -load("@rules_twirl//twirl-toolchain:register-toolchains.bzl", "twirl_register_toolchains") -twirl_register_toolchains(default_toolchain_name = "twirl-3") -``` +If you want to use a custom Twirl compiler, you can set up a custom toolchain like so: -This installs `rules_twirl` to your `WORKSPACE` and sets up toolchains for a Scala 2.13 and Scala 3 version of the Twirl compiler with Scala 3 being the default. To change the default to Scala 2.13, set `default_toolchain_name = "twirl-2-13"` +*/BUILD.bazel* -If you want to use a custom Twirl compiler, you can set up a custom toolchain in a BUILD.bazel file as follows: -```python +```starlark load("@rules_twirl//twirl-toolchain:create-toolchain.bzl", "create_twirl_toolchain") create_twirl_toolchain( @@ -72,20 +53,29 @@ create_twirl_toolchain( ) ``` -Then change the `twirl_register_toolchains` in the `WORKSPACE` file to use your custom toolchain: -```python -twirl_register_toolchains( - default_toolchain_name = "twirl-custom", - toolchains = ["