{"id":13665260,"url":"https://github.com/michaeldfallen/sbt-mustache","last_synced_at":"2026-01-10T09:45:26.545Z","repository":{"id":19058963,"uuid":"22285471","full_name":"michaeldfallen/sbt-mustache","owner":"michaeldfallen","description":"SBT plugin for using mustache.java in scala projects","archived":false,"fork":false,"pushed_at":"2014-08-24T22:35:28.000Z","size":1424,"stargazers_count":16,"open_issues_count":0,"forks_count":4,"subscribers_count":6,"default_branch":"master","last_synced_at":"2024-08-02T06:01:48.591Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Scala","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/michaeldfallen.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-07-26T11:44:56.000Z","updated_at":"2019-08-13T15:47:03.000Z","dependencies_parsed_at":"2022-09-14T13:32:08.755Z","dependency_job_id":null,"html_url":"https://github.com/michaeldfallen/sbt-mustache","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/michaeldfallen%2Fsbt-mustache","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/michaeldfallen%2Fsbt-mustache/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/michaeldfallen%2Fsbt-mustache/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/michaeldfallen%2Fsbt-mustache/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/michaeldfallen","download_url":"https://codeload.github.com/michaeldfallen/sbt-mustache/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224031926,"owners_count":17244361,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-02T06:00:31.053Z","updated_at":"2026-01-10T09:45:26.473Z","avatar_url":"https://github.com/michaeldfallen.png","language":"Scala","funding_links":[],"categories":["DOCUMENTATION"],"sub_categories":[],"readme":"#SBT {{mustache}}\n\n[![Build Status]](https://travis-ci.org/michaeldfallen/sbt-mustache)\n[![Bintray Release]](https://bintray.com/michaelallen/sbt-plugins/sbt-mustache/0.2)\n\n[Build Status]: https://travis-ci.org/michaeldfallen/sbt-mustache.svg?branch=master\n[Bintray Release]: http://img.shields.io/badge/bintray-v0.2-blue.svg \n\nAn SBT plugin for integrating Mustache templates into Scala projects.\n\nWe take the same philosophy as the Play Frameworks [Twirl] plugin, generating\nScala sources that are preconfigured to access your templates during compile.\n\nThis plugin was inspired by [@julienba]'s [play2-mustache] plugin, which we used\non the [Register to vote] exemplar project. Sadly since Play migrated to\n[SBT-Web], in it's recent [play-2.3], the [play2-mustache] plugin has been\ndeprecated.\n\n##Installation\n\nTo your projects `plugins.sbt` add the following:\n\n```\nresolvers += Resolver.url(\n  \"bintray-sbt-plugin-michaelallen\",\n  url(\"https://dl.bintray.com/michaelallen/sbt-plugins/\")\n)(Resolver.ivyStylePatterns)\n\nresolvers += \"bintray-maven-michaelallen\" at \"https://dl.bintray.com/michaelallen/maven/\"\n\naddSbtPlugin(\"io.michaelallen.mustache\" %% \"sbt-mustache\" % \"0.2\")\n```\n\nDone. SBT 0.13 added AutoPlugins which allows plugins to handle their default\nconfiguration themselves.\n\n##Usage\n\nThere's two ways to use this plugin, which I'll call *The Hogan way* and *The\nTwirl way*. Whichever you choose is up to you.\n\n####Source Directories\n\nIn most Scala apps Mustache templates are stored in `src/main/mustache`.\nIn Play apps you should put your templates in `app/mustache`.\n\nIf you would like to add further directories to look for Mustache templates you\ncan edit the key `sourceDirectories in mustacheTemplate`.\n\nAdding a new source directory for Mustache templates:\n```\nlazy val root = (project in file(\".\")).settings(\n  sourceDirectories in mustacheTemplate :+ baseDirectory / \"mySpecialMustaches\"\n)\n```\n\n####The Hogan way\n\nIn Hogan.js you call off to a Mustache compiler to compile your template then\nrender that template with a set of data. This can be done in Sbt-Mustache.\n\nOn compile Sbt-Mustache will generate a few source files. One of them is the\n`io.michaelallen.mustache.MustacheFactory` object, which is configured to look\nfor the Mustache templates in your source directories.\n\nYou can simply call `MustacheFactory.compile` to ask the factory to compile you\na template, like you would in Hogan.js\n\nWith a template sitting in `src/main/mustache/foo/bar.mustache`:\n```\n\u003ch1\u003e{{message}}\u003c/h1\u003e\n```\n\nWe can ask the MustacheFactory to compile it:\n\n```\nval template = MustacheFactory.compile(\"foo/bar.mustache\")\n```\n\nThen execute the template to render it's html:\n\n```\nval writer = new StringWriter()\ntemplate.execute(writer, Map(\"message\" -\u003e \"Hello World!\"))\n\nwriter.flush().toString == \"\u003ch1\u003eHello World!\u003c/h1\u003e\"\n```\n\n####The Twirl way\n\nTwirl models your templates as Scala files, by generating Scala objects that\nunderstand how to render the html of the template.\n\nThis is a nice feature and something I wanted to bring to Sbt-Mustache.\n\nIf you have a template at `src/main/mustache/foo/bar.mustache`:\n```\n\u003ch1\u003e{{message}}\u003c/h1\u003e\n```\n\nThen Sbt-Mustache will generate a Scala trait at `mustache.foo.bar` which\nunderstands how to render the `bar.mustache` template.\n\nWe can then mix that trait into a class or case class to provide the backing\nobject to render based off:\n\n```\ncase class Bar(message:String) extends mustache.foo.bar\n```\n\nThen newing that class up and calling render will generate our html:\n\n```\nBar(message = \"Hello World!\").render == \"\u003ch1\u003eHello World!\u003c/h1\u003e\"\n```\n\n####Play Support\n\nThe plugin provides native support for Play Frameworks [custom content types].\nWe do this by generating a trait into source_managed that provides the implicit\n`Writeable` and `ContentType` that play Results need to render arbitrary types\nas HTML. We then piggy back off your version of the Play Framework jars to compile\nthose sources.\n\nTo turn on Play support set `MustacheKeys.playSupport` in your build.sbt:\n\n```\nlazy val root = (project in file(\".\"))\n  .enablePlugins(PlayScala)\n  .settings(MustacheKeys.playSupport := true)\n```\n\nAssuming you have a Presenter in views.Foo:\n\n```\npackage views\n\ncase class Foo() extends mustache.foo\n```\n\nThen mix in the PlayImplicits trait in your controller:\n\n```\nimport io.michaelallen.mustache.PlayImplicits\n\nobject MyController extends Controller with PlayImplicits {\n  def index = Ok(views.Foo())\n}\n```\n\n##Work in progress\n\nThis plugin is a work in progress. Currently you can checkout the code, build it\n, publish it locally and make use of it to do basic Mustache compilation and\nrendering.\n\n [SBT-Web]: https://github.com/sbt/sbt-web\n [Twirl]: https://github.com/playframework/twirl\n [@julienba]: https://github.com/julienba\n [play2-mustache]: https://github.com/julienba/play2-mustache\n [Register to vote]: https://www.gov.uk/transformation/register-to-vote\n [play-2.3]: http://www.playframework.com/documentation/2.3.x/Highlights23\n [custom content types]: http://www.playframework.com/documentation/2.3.x/ScalaCustomTemplateFormat\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmichaeldfallen%2Fsbt-mustache","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmichaeldfallen%2Fsbt-mustache","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmichaeldfallen%2Fsbt-mustache/lists"}