Tag Archives: lift

Lift and Configgy

Robey wrote Configgy, and summarizes it as:

Configgy is a library for handling config files and logging for a scala daemon. The idea is that it should be simple and straightforward, allowing you to plug it in and get started quickly, writing small useful daemons without entering the shadowy world of java frameworks.

Simple and straight forward indeed. To add it to my Lift app I did the following:
1. Added this to my pom.xml

<repository>
<id>http://www.lag.net/repo/</id>
<name>http://www.lag.net/repo/</name>
<url>http://www.lag.net/repo/</url>
</repository>

And
<dependency>
<groupid>net.lag</groupid>
<artifactid>configgy</artifactid>
<version>1.2</version>
</dependency>

2. Wrote this conf file (it’s in the same dir as the pom.xml file and so is the log directory which you’ll need permissions on)
<log>
filename = "log/pca.log"
roll = "daily"
level = "debug"
</log>
hostname = "localhost"
port = 8080

3. Added this to Boot.scala

...
import net.lag.configgy.Configgy
import net.lag.logging.Logger
...
Configgy.configure("pca.conf")
val log = Logger.get
log.info("Configgy up")
log.info("Bootstrap up")

4. And a quick test, in one of my snippets I added:

...
import net.lag.logging.Logger
...
log.info("Super Awesome Form rendered")

5. The output is:

INF [20081119-14:11:15.085] liftweb: Configgy up
INF [20081119-14:11:15.088] liftweb: Bootstrap up
INF [20081119-14:11:22.144] snippet: Super Awesome Form rendered

Make with the nice nice.

Logo Contest for Lift

We kicked off a logo contest for lift.

You can find it here: http://99designs.com/contests/10209

Liftweb + ctags + vim

This is how I set up /Lift/, ctags, and vim (on OS X and Ubuntu):

Add some scala definition to ctags:

ty@Astra:~$ cat /home/ty/.ctags
--langdef=scala
--langmap=scala:.scala
--regex-scala=/^[ \t]*class[ \t]+([a-zA-Z0-9_]+)/\1/c,classes/
--regex-scala=/^[ \t]*trait[ \t]+([a-zA-Z0-9_]+)/\1/t,traits/
--regex-scala=/^[ \t]*type[ \t]+([a-zA-Z0-9_]+)/\1/T,types/
--regex-scala=/^[ \t]*def[ \t]+([a-zA-Z0-9_]+)/\1/m,methods/
--regex-scala=/^[ \t]*val[ \t]+([a-zA-Z0-9_]+)/\1/C,constants/
--regex-scala=/^[ \t]*var[ \t]+([a-zA-Z0-9_]+)/\1/l,local variables/
--regex-scala=/^[ \t]*package[ \t]+([a-zA-Z0-9_.]+)/\1/p,packages/
--regex-scala=/^[ \t]*case class[ \t]+([a-zA-Z0-9_]+)/\1/c,case classes/
--regex-scala=/^[ \t]*object[ \t]+([a-zA-Z0-9_]+)/\1/o,objects/

Build the tags file:

ty@Astra:~$ ctags -h [".scala"] -R -f liftags \
/home/ty/liftweb-read-only/liftweb/

I prefer to keep the tags file, in this case liftags, in the root of home. Put it where you want.

Add the tags location to ~/.vimrc

set tags=/home/ty/liftags

Now you can open a file and execute

:tag LiftSession

and jump to the file.

Getting my nerd on.

I will be attending ScalaLiftOff on Saturday May 10th, 2008 from 9am to 5pm.

What’s ScalaLiftOff?

The Scala lift off is a great place for members of the Scala and lift communities to get together, learn about Scala, learn about lift and get to know each other face to face. There will be Scala tracks going all day long and lift tracks to suits everyone’s interests.

New Lift App

Working on another /lift/ app for fun.
itwasbetter

Gravatars and Liftweb.

Liftweb and Gravatars together at last.

Here’s the snippet:
package net.liftweb.example.snippet

import net.liftweb.example.model._
import scala.xml.{NodeSeq, Text, Group, Node, Elem}
import net.liftweb.http._
import net.liftweb.http.S
import net.liftweb.mapper._
import net.liftweb.http.S._
import net.liftweb.util.Helpers._
import net.liftweb.util._
import java.util.Locale
import net.liftweb.sitemap._
import net.liftweb.sitemap.Loc._
import java.security._

// gravatar_id - MD5 sum of your email address
// size - image size
// rating - rating of the image, let's start with "G" which is also the default

class Gravatar {
val theUser: User = User.currentUser.openOr(new User)

private def getMD5(s: String): String = {
val m = MessageDigest.getInstance("MD5")
m.update(s.getBytes(),0,s.length())
BigInt(1,m.digest()).toString(16)
}

def getGravatar(xhtml: NodeSeq): NodeSeq = {
var src = "http://www.gravatar.com/avatar.php?gravatar_id=" + getMD5(S.attr("e").openOr(theUser.email))
src = src + "&size=" + S.attr("s").openOr("42")
src = src + "&rating=" + S.attr("r").openOr("G")

<img src={src}/>
}

And here’s how to use it in your templates:

<lift :Gravatar.getGravatar e="email address" s="80" r="G" />

Lift and BlueprintCSS

I mooshed BluePrintCSS into /lift/ as you can see here:
lift + blueprintCSS

It was ridiculously easy using this tutorial.

Using MySql with Lift

I need to use MySQL with my Lift webapp and here’s how I did it. In Boot.scala I replaced the Derby DBVendor object with a MySQL object. Hope that helps.

Add this to your pom.xml:

        <dependency>
          <groupid>mysql</groupid>
          <artifactid>mysql-connector-java</artifactid>
          <version>5.0.41</version>
        </dependency>

object DBVendor extends ConnectionManager {
def newConnection(name: ConnectionIdentifier): Can[Connection] = {
try
{
Class.forName(”com.mysql.jdbc.Driver”)
val dm = DriverManager.getConnection(”jdbc:mysql://localhost:3306/database_name”, “user”, “password”)
Full(dm)
}
catch
{
case e : Exception => e.printStackTrace; Empty
}
}
def releaseConnection(conn: Connection)
{
conn.close
}
}

Next up is learning how to set up my domain objects properly.