kolloch / sbt-html-js-wrap

SBT plugin to convert HTML files to JavaScript files including the HTML.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

sbt-html-js-wrap

sbt-web plugin for converting HTML files to JavaScript files wrapping the HTML.

You can use this plugin in combination with sbt-uglify to combine all project JavaScript and template files to one big file.

Build Status

Add plugin

Add the plugin to project/plugins.sbt. For example:

resolvers += "Typesafe repository" at "http://repo.typesafe.com/typesafe/releases/"

addSbtPlugin("net.eigenvalue" % "sbt-html-js-wrap" % "1.0.0")

Your project's build file also needs to enable sbt-web plugins. For example with build.sbt:

lazy val root = (project.in file(".")).enablePlugins(SbtWeb)

As with all sbt-web asset pipeline plugins you must declare their order of execution e.g.:

pipelineStages := Seq(htmlJsWrap)

Configuration

Template

By default the code generated is suitable for angular:

angular.module("templates").run(["$templateCache", function($templateCache) {
  $templateCache.put("some.html","<html><body>BODY</body></html>");
}]);

The module name can be customized by:

htmlJsAngularModule := "myModule"

The complete template can be changed like this:

htmlJsTemplate := { (quotedFileName: String, quotedHtmlContent: String) =>
      s"""
         |angular.module(${JsString(htmlJsAngularModule.value)}).run(["$$templateCache", function($$templateCache) {
         |  $$templateCache.put($quotedFileName,$quotedHtmlContent);
         |}]);
      """.stripMargin
    }

You need to import spray.json.JsString for the JSON quoting like this

import spray.json.JsString

If you generally useful templates, I like to include them as easily available alternative settings. Please send me an email/message.

Filters

Include and exclude filters can be provided. For example to only include *Template.html files:

includeFilter in htmlJsWrap := "*Template.html"

Or to exclude a vendor vendor.html file:

excludeFilter in htmlJsWrap := "vendor.html"

The default filter is to include all .html files:

includeFilter in htmlJsWrap := "*.html"

License

This code is licensed under the Apache 2.0 License.

About

SBT plugin to convert HTML files to JavaScript files including the HTML.


Languages

Language:Scala 96.8%Language:JavaScript 3.2%