Skip to content

lucidsoftware/rules_twirl

Repository files navigation

Twirl Template Rules for Bazel

Status Doc
Build Status Stardoc

Overview

rules_twirl compiles Twirl templates to Scala, so they can be used with bazelbuild/rules_scala and higherkindness/rules_scala.

Simple Core API: twirl_templates

For more information about Twirl templates, see the Play Twirl documentation.

Installation

Create a file called at the top of your repository named WORKSPACE and add the following snippet to it.

# update version as needed
rules_twirl_version = "9ac789845e3a481fe520af57bd47a4261edb684f"
http_archive(
  name = "io_bazel_rules_twirl",
  sha256 = "b1698a2a59b76dc9df233314c2a1ca8cee4a0477665cff5eafd36f92057b2044",
  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_TAG = "3.3"
http_archive(
    name = "rules_jvm_external",
    sha256 = "d85951a92c0908c80bd8551002d66cb23c3434409c814179c0ff026b53544dab",
    strip_prefix = "rules_jvm_external-{}".format(RULES_JVM_EXTERNAL_TAG),
    type = "zip",
    url = "https://github.com/bazelbuild/rules_jvm_external/archive/{}.zip".format(RULES_JVM_EXTERNAL_TAG),
)

load("@io_bazel_rules_twirl//:workspace.bzl", "twirl_repositories")
twirl_repositories()
load("@twirl//:defs.bzl", twirl_pinned_maven_install = "pinned_maven_install")
twirl_pinned_maven_install()

This installs rules_twirl to your WORKSPACE at the specified commit. Update the commit as needed.

Usage

The twirl_templates rule compiles Twirl templates to a source jar that can be used with the rules_scala rules. For example,

twirl_templates(
  name = "twirl-templates",
  source_directory = "app",
  srcs = glob(["app/**/*.scala.html"])
    + glob(["app/**/*.scala.xml"])
    + glob(["app/**/*.scala.js"])
    + glob(["app/**/*.scala.txt"]),
)

scala_binary(
  name = "foo-service",
  srcs = glob(["app/**/*.scala"]) + [":twirl-templates"],
  main_class = "foo.server.RunServer",
  deps = [...]
  )
)

See the Stardoc documentation for the full list of options for twirl_templates.

Use with the Play Framework

twirl_templates