CSS Preprocessing for Lift

14 views
Skip to first unread message

jori

unread,
Jun 19, 2010, 1:00:38 AM6/19/10
to Lift
hi,

Is there any sort of special CSS preprocessing ability in Lift that
can take HTML5 CSS code written like:

.foo {
border-radius:8px;
box-shadow:3px 3px 3px #888;
}

And translate it to the following for Webkit:

.foo {
-webkit-border-radius:8px;
-webkit-border-radius:3px 3px 3px #888;
}

And other equivalents for Mozilla, Opera, and so on based on which
browser is detected?

thank you

Marius

unread,
Jun 19, 2010, 3:17:29 AM6/19/10
to Lift
We have a fixCSS in LiftRules that adds the context path to root
relative paths, but that's it.

What you could do is to have different CSS versions for different
browsers. Using ResourceServer.rewrite you can rewrite the request
path thus you can serve the css based on the UA. Personally I prefer
it because even the standard properties are not always interpreted in
the same way by different browsers.

Br's,
Marius

David Pollak

unread,
Jun 19, 2010, 9:37:52 AM6/19/10
to lif...@googlegroups.com
I'd do it differently ;-)

import net.liftweb.http.rest._

object MyCSSMorpher extends RestHelper {
  serve {
    case r @ Req("dynocss" :: file :: _, "css", GetRequest) =>
      for {
        convertFunc <- findConvertFunc(r)
        fileContents <- readFile(file+".css")
        converted <- convertFunc(fileContents)
      } yield CSSResponse(converted)
  }

  // based on the browser detected, return a function 
  // that will convert HTML5 css into CSS for that browser
  def findConvertFunc(req: Req): Box[String => Box[String]] =
    Empty

  // load the file from the specific location...
  // are you going put the CSS templates in
  // resources, etc.
  def readFile(name: String): Box[String] = Empty
}

Then in Boot.scala:

LiftRules.statelessDispatchTable.append(MyCSSMorpher)

Thanks,

David


--
You received this message because you are subscribed to the Google Groups "Lift" group.
To post to this group, send email to lif...@googlegroups.com.
To unsubscribe from this group, send email to liftweb+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/liftweb?hl=en.




--
Lift, the simply functional web framework http://liftweb.net
Beginning Scala http://www.apress.com/book/view/1430219890
Follow me: http://twitter.com/dpp
Blog: http://goodstuff.im
Surf the harmonics

Eduardo Saltelli

unread,
Jun 22, 2010, 1:30:23 AM6/22/10
to lif...@googlegroups.com, David Pollak
My inquiring mind wants to know...

Would you do this for dynamic types/classes in the CSS, or because it feels more natural to do the mapping in Scala?

If the CSS types are more static ( HTML elements) I would lean towards Marius' response.  Although I see the value in having a dynamic, application response based on the perceived type.  Very close to micro-formats especially if the class selectors are based on dynamic types.

Just trying to extract a little more insight on the _differently ;-)_

cheers!

eduardo
Reply all
Reply to author
Forward
0 new messages