Hi all,
Following up on a previous thread about upgrading to Flot 0.6[1], I'd
like to discuss how (or even whether) we handle Javascript
dependencies within Lift. It'd be great to get this in as part of
#322[2] for M3 next week but I acknowledge I've been slow pushing
forward the discussion and that it may be a little tricky to get
right. Hopefully with this discussion we can chart a good course.
The issue of Javascript plugins comes up because the Lift side may
need to know about the additional Javascript files you're using. If
nothing else, ResourceServe.allow needs to be called if you want to
serve the Javascript file from within the Lift app. However, if you're
setting up Javascript calls from Lift (such as with some Ajax or Comet
functionality) you need to do a little more.
The current situation is the simplest: it is up to users to add the
files to the ResourceServer in boot.scala and to add a script tag to
their HTML output, whether in the document head or body. However,
there are various parts of Lift, particularly in lift-widgets, that
make use of additional Javascript files so it would be nice to have a
common, perhaps more abstracted way of doing this.
Here's what I'm thinking:
// at net.liftweb.http.js or something similar
class JsScript(path: List[String]) {
def baseUrl = ""
def allowResource = {
case path => true
}
def toHTML = <script type="text/javascript"
src={ path.mkString(baseUrl, "/", "") }></script>
}
trait JsScriptDependency {
abstract def scripts: List[JsScript];
override lazy val fixedRender: Box[NodeSeq] =
Some(super.fixedRender.getOrElse(scala.xml.Text("")) ++
scripts.map(_.toHTML))
}
// Usage in boot.scala
val myJsScript = new JsScript("flot" :: "jquery.flot.selectable.js" ::
Nil)
ResourceServer.allow(myJsScript.allowResource)
// Usage in a normal snippet
def mySnippet = {
<head>
{ myJsScript.toHTML }
</head>
<div>
The rest of the snippet...
</div>
}
// Usage in a CometActor
class myActor extends CometActor with JsScriptDependency {
override def scripts = List(new JsScript("flot" ::
"jquery.flot.selectable.js" :: Nil));
}
What do you think? It's a really quite basic but I think such an
approach could work well for things like as lift-flot.
Peter
[1]:
http://groups.google.com/group/liftweb/browse_thread/thread/a25a93f55c181475/0d91f4aee1af8977
[2]:
https://www.assembla.com/spaces/liftweb/tickets/322-upgrade-the-flot-lift-widget-to-0-6
--
You received this message because you are subscribed to the Google Groups
"Lift" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/liftweb?hl=en.