scalate-generator


License

License

MIT
Categories

Categories

Scala Languages
GroupId

GroupId

com.mojolly.scalate
ArtifactId

ArtifactId

scalate-generator_2.9.1
Last Version

Last Version

0.5.0
Release Date

Release Date

Type

Type

jar
Description

Description

scalate-generator
scalate-generator
Project URL

Project URL

http://github.com/backchatio/xsbt-scalate-generate
Project Organization

Project Organization

com.mojolly.scalate
Source Code Management

Source Code Management

https://github.com/backchatio/xsbt-scalate-generate.git

Download scalate-generator_2.9.1

How to add to project

<!-- https://jarcasting.com/artifacts/com.mojolly.scalate/scalate-generator_2.9.1/ -->
<dependency>
    <groupId>com.mojolly.scalate</groupId>
    <artifactId>scalate-generator_2.9.1</artifactId>
    <version>0.5.0</version>
</dependency>
// https://jarcasting.com/artifacts/com.mojolly.scalate/scalate-generator_2.9.1/
implementation 'com.mojolly.scalate:scalate-generator_2.9.1:0.5.0'
// https://jarcasting.com/artifacts/com.mojolly.scalate/scalate-generator_2.9.1/
implementation ("com.mojolly.scalate:scalate-generator_2.9.1:0.5.0")
'com.mojolly.scalate:scalate-generator_2.9.1:jar:0.5.0'
<dependency org="com.mojolly.scalate" name="scalate-generator_2.9.1" rev="0.5.0">
  <artifact name="scalate-generator_2.9.1" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.mojolly.scalate', module='scalate-generator_2.9.1', version='0.5.0')
)
libraryDependencies += "com.mojolly.scalate" % "scalate-generator_2.9.1" % "0.5.0"
[com.mojolly.scalate/scalate-generator_2.9.1 "0.5.0"]

Dependencies

compile (2)

Group / Artifact Type Version
org.scala-lang : scala-library jar 2.9.1
org.fusesource.scalate : scalate-core_2.9 jar 1.6.1

Project Modules

There are no modules declared in this project.

Scalate support for SBT 0.1x.x

Integration for SBT that lets you generate sources for your Scalate templates and precompile them as part of the normal compilation process. This plugin is published to scala-tools.org.

Usage

Getting the plugin

Include the plugin in project/plugins.sbt:

For sbt 0.12.x, 0.13.x:

addSbtPlugin("com.mojolly.scalate" % "xsbt-scalate-generator" % "0.5.0")

For sbt 0.11.3:

resolvers += Resolver.url("sbt-plugin-releases",
  new URL("http://scalasbt.artifactoryonline.com/scalasbt/sbt-plugin-releases/"))(
    Resolver.ivyStylePatterns)

addSbtPlugin("com.mojolly.scalate" % "xsbt-scalate-generator" % "0.2.0")

for sbt 0.11.2: (maven central)

libraryDependencies <+= sbtVersion(v => "com.mojolly.scalate" %% "xsbt-scalate-generator" % (v + "-0.1.6"))

or as a git dependency in project/project/build.scala:

import sbt._
import Keys._

object PluginsBuild extends Build {
  lazy val root = Project("plugins", file(".")) dependsOn (scalateGenerate) settings (scalacOptions += "-deprecation")
  lazy val scalateGenerate = ProjectRef(uri("git://github.com/mojolly/xsbt-scalate-generate.git"), "xsbt-scalate-generator")
}

Configuring the plugin in build.sbt

Configure the plugin in build.sbt:

import ScalateKeys._

seq(scalateSettings:_*)
      
// Scalate Precompilation and Bindings
scalateTemplateConfig in Compile <<= (sourceDirectory in Compile){ base =>
  Seq(
    TemplateConfig(
      base / "webapp" / "WEB-INF" / "webTmpl",
      Seq(
        "import org.myapp.scalate.Helpers._",
        "import org.myapp.model._",
        "import net.liftweb.common._",
        "import org.joda.time._",
        "import org.scalatra.UrlGenerator"
      ),
      Seq(
        Binding("context", "_root_.org.scalatra.scalate.ScalatraRenderContext", importMembers = true, isImplicit = true),
        Binding("messageTranslatorModel", "org.myapp.model.mongo.MessageTranslator", importMembers = true, isImplicit = true, defaultValue = null),
        Binding("userSession", "org.myapp.auth.UserSession", importMembers = true, defaultValue = null),
        Binding("env", "org.myapp.util.Environment")
      ),
      Some("webTmpl")
    ),
    TemplateConfig(
      base / "webapp" / "WEB-INF" / "mailTmpl",
      Seq(
        "import org.myapp.scalate.Helpers._",
        "import org.myapp.model._",
        "import net.liftweb.common._",
        "import org.joda.time._"
      ),
      Seq(
        Binding("i18n", "org.myapp.model.mongo.MessageTranslator", true, isImplicit = true, defaultValue = null),
        Binding("user", "User", false, defaultValue = null),
        Binding("config", "com.typesafe.config.Config", false, defaultValue = null),
        Binding("assets", "org.myapp.model.mongo.fields.AssetPaths", false, isImplicit = true, defaultValue = null),
        Binding("geonames", "org.myapp.model.Geonames", false, isImplicit = true, defaultValue = null)
      ),
      Some("mailTmpl")
    )
  )
}

Configuring the plugin in project/build.scala

Configure the plugin in project/build.scala:

import sbt._
import sbt.Keys._
import com.mojolly.scalate.ScalatePlugin._
import ScalateKeys._

object build extends Build {  
  val templateSettings = scalateSettings ++ Seq(
    /**
     * Sets the behavior of recompiling template files.
     * Always template files are recompiled when this setting is true.
     * When you set it to false, they are recompiled only when the modified time of
     * a template file is newer than that of a scala file generated by compilation
     * or a compiled scala file corresponding to a template file doesn't exist yet.
     */
    scalateOverwrite := true,
    scalateTemplateConfig in Compile <<= (baseDirectory) { base =>
      Seq(
        /**
         * A minimal template configuration example.
         * "scalate" is used as a package prefix(the 4th argument of TemplateConfig.apply)
         * if not specified.
         *
         * An example of a scalate usage is as bellow if you have templates/index.ssp.
         *
         * val engine = new TemplateEngine
         * engine.layout("/scalate/index.ssp")
         */
        TemplateConfig(
          base / "templates",
          Nil,
          Nil
        )
      )
    }
  )

  lazy val root = Project("root", file(".")).settings(templateSettings:_*)
}

Trigger recompilation on save

From version 0.2.2 onwards the plugin detects when sources are changed and will trigger a recompilation. Older versions can add this to their build.sbt:

watchSources <++= (scalateTemplateDirectory in Compile) map (d => (d ** "*").get)

To use multiiple template directories with scalatra you'll need to make some changes too:

trait YourScalateSupport extends ScalateSupport {
 
  override protected def defaultTemplatePath: List[String] = List("/webTmpl/views")
 
  override protected def createTemplateEngine(config: ConfigT) = {
    val engine = super.createTemplateEngine(config)
 
    engine.layoutStrategy = new DefaultLayoutStrategy(engine,
      TemplateEngine.templateTypes.map("/webTmpl/layouts/default." + _): _*)
 
    engine.packagePrefix = "webTmpl"
    engine
  }
 
}

Patches

Patches are gladly accepted from their original author. Along with any patches, please state that the patch is your original work and that you license the work to the xsbt-scalate-generate project under the MIT License.

License

MIT licensed. Check the LICENSE file.

com.mojolly.scalate

Mojolly Ltd.

Versions

Version
0.5.0
0.4.2
0.4.1
0.4.0
0.3.0
0.2.2
0.2.1
0.2.0
0.1.11
0.1.10
0.1.8
0.1.7
0.1.6
0.1.5
0.1.4
0.1.1
0.1.0
0.0.9
0.0.8
0.0.1