Lifty

Lifty is a plugin that adds scaffolding to sbt. By telling Lifty about Recipes you teach it to generate files. The hope is that the Scala community will create recipes for all the different libraries and frameworks to make it easy to get started and be productive whenever your’re working with Scala.

If you have any questions then drop by the Google Group and if you want to have a look at the implementation or open an issue then go to Github.

Installing The Plugin

Add lifty as a global plugin so you can use it in all of your sbt projects. You do so by adding the following line to your ~/.sbt/plugins/build.sbt file

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

addSbtPlugin("org.lifty" % "lifty" % "1.7.4")

Or if you want to try the SNAPSHOT version

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

addSbtPlugin("org.lifty" % "lifty" % "1.7.5-SNAPSHOT")

and then add the following to your ~/.sbt/build.sbt file

seq( Lifty.liftySettings : _*)

Whenever you’re in a SBT session you now have the lifty command avaiable. The lifty command has tab-completion enabled to make it faster/easier to use. Try typing lifty and hit tab in an SBT session.

Teaching Lifty Recipes

Now that you have Lifty installed you need to teach it how to generate different files for you. You do so by pointing lifty to a recipe. Here’s what you would have to type to teach Lifty about Lift projects and templates

> lifty learn lift https://raw.github.com/Lifty/lifty/master/lifty-recipe/lifty.json

This tells lifty that you want to add a new recipe and give it the name lift and that lifty can find the description of the recipe at the given url.

Now you can create a fresh Lift webapp and start it simply by typing the following in an sbt session:

> lifty create lift project
> reload          
> container:start
> container:stop

Now point your browser to http://localhost:8080

Making Your Own Recipe

I have claimed that:

It’s easy to teach Lifty about new scaffolding templates, you just have to give it the url to recipe and it will download the templates and you’re set.

To creat your own recipes you have to follow two steps

Creating Your Description File

In this section I’ll describe the .json file you have to write. You can find a detailed example here or check out the case classes that I use to parse the json file here.

Top level

At the top level you have an object the the properties

Example:

{
	"origin"  : "url of where the recipe is stored",
	"version" : 1.3,
	"sources" : [ ... ],
	"arguments" : [ ... ],
	"templates" : [ ... ]
}

sources

As explained, this has to be an array of objects. Each object needs to have the following properties:

arguments

As explained, this has to be an array of objects. Each object needs to have the following properties:

templates

As explained, this has to be an array of objects. Each object represents something that Lifty can create. Each template can render many source templates if needed (i.e. if you wanted to create an entire project for example). Each object needs to have the following properties:

Creating Your Templates

Templates are just plain text files with .ssp extensions. You have to use the .ssp extension for legacy reasons right now. Templates are quite simple, you can define placeholders for argument values that will be substituted when the template is rendered and you can define injection points. The injection points are places in the template where other templates might want to inject something when the template is rendered.

Here’s a very simple example showing placeholder values (the ones in ${x} where x is the name of the argument it’s a placeholder for):

package ${snippetpack}

import scala.xml.{NodeSeq}
import net.liftweb.util.Helpers._

class ${snippetName} {
  def render = "*" #> <strong>hello world!</strong>
}

and here’s an example using injection points, the syntax is //#inject point: nameOfInjectionPoint:

name := "${projectName}"

scalaVersion := "${scalaVersion}"

libraryDependencies += "net.liftweb" %% "lift-webkit" % "${liftversion}" % "compile->default"

//#inject point: dependencies

resolvers += "Java.net Maven2 Repository" at "http://download.java.net/maven/2/"

seq(webSettings :_*)

libraryDependencies += "org.mortbay.jetty" % "jetty" % "6.1.22" % "test,container"

libraryDependencies += "org.scala-tools.testing" %% "specs" % "1.6.9" % "test"

Existing Recipes

This a list of known recipes for Lifty

Lifty

Lifty generates files associated with the Lift framework. It lets you get started with Lift in less than a minute - depending on your internet connection ;) and helps you be more productive in your daily Lift activities.

Changelog

Lifty 1.7.4 is out - 12th of December 2011

Notice You will have to re-install the lift recipe because I changed to JSON description and it’s no longer able to parse the old file. Sorry.

To use the new version change your ~/.sbt/plugins/build.sbt so it has

> addSbtPlugin("org.lifty" % "lifty" % "1.7.4")

and then start an SBT session and run

> lifty delete lift
> lifty learn lift https://raw.github.com/Lifty/lifty/master/lifty-recipe/lifty.json

Changes

Lifty 1.7.3 is out - 24th of November 2011

Bug fix for windows users

Lifty 1.7.2 is out - 17th of November 2011

Bug fix

Lifty 1.7.1 is out - 16th of November 2011

Bug fixes

Lifty 1.7 is out - 16th of November 2011

This has a been a big rewrite of Lifty. It’s now works with SBT 0.11.x and templates/descriptions are hosted online so it’s easier for the community to help maintain the templates

Lifty 1.6.1 is out - 20th of March 2011

Lifty 1.6.1 has just been published. This version includes the following:

Lifty 1.6 is out - 11th of March 2011

Lifty 1.6 has just been published. This version includes the following

Announcing Lifty - 9th of August 2010

Initial release

Fork me on GitHub