Te Lif Framework for Fun and Proft Peter Robinett - - PowerPoint PPT Presentation

te lif framework for fun and proft
SMART_READER_LITE
LIVE PREVIEW

Te Lif Framework for Fun and Proft Peter Robinett - - PowerPoint PPT Presentation

Te Lif Framework for Fun and Proft Peter Robinett peter@bubblefoundry.com for DUSE VI, 2010-06-30 Who am I? Background in web programming with interpreted languages (PHP, Python, Javascript, etc) Likes long walks on the beaches


slide-1
SLIDE 1

Te Lif Framework for Fun and Proft

Peter Robinett peter@bubblefoundry.com for DUSE VI, 2010-06-30

slide-2
SLIDE 2

Who am I?

slide-3
SLIDE 3
  • Background in web programming with

interpreted languages (PHP, Python, Javascript, etc)

  • Likes long walks on the beaches
  • Lift + Scala programmer for one year
  • Loves both cats AND dogs
  • Lift committer for approx. 6 months BUT only

has minor commit to lift-flot to my name

  • Likes fine wine and smooth jazz
  • BUT active on mailing list and wiki
  • Isn't very good at making funny bullet points
slide-4
SLIDE 4

What i Lif?

slide-5
SLIDE 5

Lift is an expressive and elegant framework for writing web applications. Lift stresses the importance of security, maintainability, scalability and performance, while allowing for high levels of developer productivity. Lift is inspired by Seaside, Rails, Django, Wicket, and beyond.

slide-6
SLIDE 6

Why Fun?

slide-7
SLIDE 7
slide-8
SLIDE 8

Comet

class AskName extends CometActor { def render = ajaxForm(<div>What is your username?</div> ++ text("",name => answer(name.trim)) ++ <input type="submit" value="Enter"/>) } class Chat extends CometActor with CometListener { private var userName = "" private var chats: List[ChatLine] = Nil private lazy val infoId = uniqueId + "_info" private lazy val infoIn = uniqueId + "_in" private lazy val inputArea = findKids(defaultXml, "chat", "input") private lazy val bodyArea = findKids(defaultXml, "chat", "body") private lazy val singleLine = deepFindKids(bodyArea, "chat", "list") // handle an update to the chat lists // by diffing the lists and then sending a partial update // to the browser
  • verride def lowPriority = {
case ChatServerUpdate(value) => val update = (value -- chats).reverse.map(b => AppendHtml(infoId, line(b))) partialUpdate(update) chats = value } // render the input area by binding the // appropriate dynamically generated code to the // view supplied by the template
  • verride lazy val fixedRender: Box[NodeSeq] =
ajaxForm(After(100, SetValueAndFocus(infoIn, "")), bind("chat", inputArea, "input" -> text("", sendMessage _, "id" -> infoIn))) // send a message to the chat server private def sendMessage(msg: String) = ChatServer ! ChatServerMsg(userName, msg.trim) // display a line private def line(c: ChatLine) = bind("list", singleLine, "when" -> hourFormat(c.when), "who" -> c.user, "msg" -> c.msg) // display a list of chats private def displayList(in: NodeSeq): NodeSeq = chats.reverse.flatMap(line) // render the whole list of chats
  • verride def render =
bind("chat", bodyArea, "name" -> userName, AttrBindParam("id", Text(infoId), "id"), "list" -> displayList _) // setup the component
  • verride def localSetup {
askForName super.localSetup } // register as a listener def registerWith = ChatServer // ask for the user's name private def askForName { if (userName.length == 0) { ask(new AskName, "what's your username") { case s: String if (s.trim.length > 2) => userName = s.trim reRender(true) case _ => askForName reRender(false) } } } }
slide-9
SLIDE 9

Te Community

slide-10
SLIDE 10

Why Proftable?

slide-11
SLIDE 11
slide-12
SLIDE 12

Why Scala?

slide-13
SLIDE 13

All the normal reaons, plus...

slide-14
SLIDE 14

<lift:comet type=”Clock”> The time is <clock:time />. </lift:comet> class Clock extends CometActor {

  • verride def defaultPrefix = Full("clock")

// schedule a ping every 10 seconds so we redraw ActorPing.schedule(this, Tick, 10 seconds) private lazy val spanId = uniqueId+"_timespan" def render = { bind("time" -> timeSpan) } def timeSpan = (<span id={spanId}>{timeNow}</span>)

  • verride def lowPriority = {

case Tick => partialUpdate(SetHtml(spanId, Text(timeNow.toString))) ActorPing.schedule(this, Tick, 10 seconds) } } case object Tick

Actors

Allows great AJAX, Comet support.

BUT, there were issues with the EFPL library so David wrote

  • LiftActor. This is actually a proof of Scala's strength.
slide-15
SLIDE 15

XHTML Procesing

Template:

<lift:DuSE.sayHello> Hi <DuSE:name />. It's now <DuSE:datetime />. </lift:DuSE.sayHello>

Snippet:

import java.util.Date import scala.xml.{NodeSeq, Text} import net.liftweb.util.Helpers.bind

  • bject DuSE {

def sayHello(xhtml: NodeSeq): NodeSeq = { User.currentUser.map(user => { bind(“DuSE”, xhtml, “name” -> Text(user.shortName), “datetime” -> Text((new Date).toString) ) }) openOr <div>You didn't log in!</div> } }

slide-16
SLIDE 16

Routing

Routing is done via SiteMap...

LiftRules.statefulRewrite.prepend({ case RewriteRequest(ParsePath("app" :: appID :: "index" :: Nil, _, _,_), GetRequest, _) => RewriteResponse("app":: "view" :: Nil, Map("appID" -> appID) })

... and redirects with partial functions!

val entries = Menu(Loc(“App Page”, “app” :: “view” :: Nil, “App Page”) :: Nil LiftRules.setSiteMap(SiteMap(entries :_*))

Regex Free!

slide-17
SLIDE 17

What i Lif good at?

  • Comet, also AJAX
  • X(HT)ML processing
  • JSON
  • REST
  • As much or as little as you want done for you
  • Secure
  • Fast execution, fast development (IF you

already know Lift)

  • Great code:functionality ratio
slide-18
SLIDE 18

What i Lif bad at?

  • High learning curve
  • Stateless request/response cycle (but is

possible)

  • View-first, not MVC
  • I.E. Does some things differently
  • Statefulness can lead to lots of stuff in memory

if you're not careful

slide-19
SLIDE 19

By Markus Lütkemeyer http://flickr.com/photos/helico/2245863081/

How to get Lifed?

slide-20
SLIDE 20

A Digresion on Versions

slide-21
SLIDE 21

By Alan Sung http://flickr.com/photos/clsung/310886130/

slide-22
SLIDE 22
  • 2.0-SNAPSHOT is quite stable
  • RCs are really stable, only important bug fixes are
  • added. We're at 2.0-RC2.
  • Milestones are very stable. Last one was 2.0-M6.
  • If you have crazy rules requiring that you MUST

use 'official' releases, wait a week for 2.0.

  • Moral of the story: DON'T use 1.x.
  • PS Scala 2.8 support in 280_port_refresh, should

see 3.0-SNAPSHOT after the 2.0 release.

slide-23
SLIDE 23

Join the Google Group

http://groups.google.com/group/liftweb

slide-24
SLIDE 24

Read the Getting Started Guide

http://www.liftweb.net/docs/getting_started.html

slide-25
SLIDE 25

Skim the Wiki

http://www.assembla.com/wiki/show/liftweb/

slide-26
SLIDE 26

Checkout the Scaladocs

http://scala-tools.org/mvnsites-snapshots/liftweb/

slide-27
SLIDE 27

Clone the code

http://github.com/lift/lift *

* Yep, since last night we've been using the new GitHub organizations

  • feature. We're cutting edge like that.
slide-28
SLIDE 28

Use an Archetye

  • lift-archetype-basic
  • lift-archetype-blank
  • lift-archetype-jpa-basic
  • lift-archetyp-jpa-blank-single
  • lift-archetyp-jpa-blank
  • lift-archetyp-sbt
slide-29
SLIDE 29

sbt

simple-build-tool is THE way to do Scala projects. See http://www.assembla.com/wiki/show/liftweb/Using_SBT OR git clone git://github.com/dpp/lift_sbt_prototype.git Then cd into lift_sbt_prototype and type: sbt At the sbt prompt, type: update Then: jetty-run Point your browser to http://localhost:8080/

Mads Hartmann is working on sbt processors for Google Summer of Code. It should be awesome.

slide-30
SLIDE 30

Maven

http://www.assembla.com/wiki/show/liftweb/Using_Maven

mvn archetype:generate \

  • DarchetypeGroupId=net.liftweb \
  • DarchetypeArtifactId=lift-archetype-blank \
  • DarchetypeVersion=2.0-SNAPSHOT \
  • DarchetypeRepository=http://scala-tools.org/repo-snapshots \
  • DremoteRepositories=http://scala-tools.org/repo-snapshots \
  • DgroupId=your.groupId \
  • DartifactId=your.artifactId

mvn jetty:run mvn scala:cc (jRebel license: http://www.zeroturnaround.com/scala-license/)

slide-31
SLIDE 31

Demo and Example

http://demo.liftweb.net/ http://github.com/lift/lift/tree/master/examples/ http://github.com/dpp/lift-samples http://www.liftweb.net

slide-32
SLIDE 32

Quetions?

By Gillian Maniscalco http://flickr.com/photos/gillian_m/448800043/