> S.attr("columns") = Full("2") > > When a Snippet is invoked, the attributes of the <lift:...> tag are made > available in S.attr() > Two major questions of mine are finally solved :-). I'm off to make widgets!
On Thu, Sep 4, 2008 at 6:53 PM, David Pollak <[EMAIL PROTECTED]> wrote: > S.attr("columns") = Full("2") > > When a Snippet is invoked, the attributes of the <lift:...> tag are made > available in S.attr() > > Daniel Green wrote: > > Because Elem is a subclass of NodeSeq, NodeSeq => NodeSeq and Elem => > NodeSeq mean the same thing. > > > > This is at the heart of my misunderstanding. I had wrongfully assumed > that the function was being passed a sequence of the children, which > seemed strange to me so I asked. I was looking for the baz attribute. > > However, I try to do this as a snippet and the method does not pickup > the columns attribute: > > <lift:PanelGrid.grid columns="2"> > <label>foo</label><input/> > <label>bar</label><input/> > <label>qux</label><input/> > <label>quux</label><input/> > </lift:PanelGrid.grid> > > class PanelGrid { > def grid(node: NodeSeq) = { > val columns = (node \ "@columns").toString.toInt > val children = node.toList > > require(children.length % columns == 0) > > def buildRows(ns: NodeSeq, i: Int): NodeSeq = i match { > case i if !children.isDefinedAt(i) => ns > case i => > val lastId = i + columns > buildRows(ns ++ <tr> {children.slice(i, lastId).map( > x => <td>{x}</td>)}</tr>, lastId + 1) > } > > <table>{buildRows(Nil, 0)}</table> > } > } > > java.lang.NumberFormatException: For input string: "" > at > java.lang.NumberFormatException.forInputString(NumberFormatException.java:48) > at java.lang.Integer.parseInt(Integer.java:468) > at java.lang.Integer.parseInt(Integer.java:497) > at scala.runtime.RichString.toInt(RichString.scala:213) > at com.cianaidan.aws.web.snippet.PanelGrid.grid(PanelGrid.scala:8) > > > > > > > > On Thu, Sep 4, 2008 at 9:58 AM, David Pollak > <[EMAIL PROTECTED]> wrote: > > > On Thu, Sep 4, 2008 at 6:43 AM, Daniel Green <[EMAIL PROTECTED]> wrote: > > > Well, not exactly. I'm looking for this but on the top level. Instead > of getting <input ..> getting the attributes of its parent. > > so if there's <foo attribute1="blah"/> I want access to attribute1, > while binding. Right now you can pass a (NodeSeq)=>NodeSeq, I guess > what I desire is a (Elem)=>NodeSeq. More useful would to be able to > have this support with snippet lookup. For example > > > Because Elem is a subclass of NodeSeq, NodeSeq => NodeSeq and Elem => > NodeSeq mean the same thing. > > As I pointed out before, you can access 'attribute1' on <foo > attribute1="blah"/> with <foo attribute1="blah"/> \ "@attribute1" > > So, let's try again, please put together an entire example of what you want > to do. What does the code that invokes the Snippet look like. For example: > > <lift:Foo.bar baz="slog"> > Hello <snip:hello/><br/> > Goodbye <snip:bye foo="3/><br/> > </lift:Foo.bar> > > The NodeSeq that's passed to your snippet is: > Hello <snip:hello/><br/> > Goodbye <snip:bye foo="3/><br/> > In a bind call, you'd do something like: > bind("snip", xhtml, "hello" -> ..., "bye" -> ...) > > So, what attribute are you looking to get? the "foo" attribute on <snip:bye > /> or the "baz" attribute on the <lift:Foo.bar /> tag? Or some other > attribute? > > > > > > > You may be familiar with JSF's PanelGrid. Basically, you specify the > number of columns you want and it creates a table of rows based on the > number of tags within the tag. I took a stab at this in lift: > > class Custom { > def panelGrid(node: Elem) = { > val columns = (node \ "@columns").toString.toInt > val children = node.child.toList > > require(children.length % columns == 0) > > def buildRows(ns: NodeSeq, i: Int): NodeSeq = i match { > case i if !children.isDefinedAt(i) => ns > case i => > val lastId = i + columns > buildRows(ns ++ <tr> {children.slice(i, lastId).map( > x => <td>{x}</td>)}</tr>, lastId + 1) > } > > <table>{buildRows(Nil, 0)}</table> > } > } > > I would like to be able to reference Custom.panelGrid like a snippet > without having to add an extra parent tag to collect the attributes. > > On Thu, Sep 4, 2008 at 7:18 AM, Daniel Green <[EMAIL PROTECTED]> wrote: > > > I was more or less trying to describe the issue outlined here: > > http://groups.google.com/group/liftweb/browse_thread/thread/1a601c402deebecf > > I'll follow up in that thread. > > > On Tue, Sep 2, 2008 at 1:05 PM, David Pollak > <[EMAIL PROTECTED]> wrote: > > > Please provide a complete example including how you're invoking the > Snippet, > the body that's passed to the snippet and the specific attribute you're > looking for. > > On Tue, Sep 2, 2008 at 10:03 AM, Daniel Green <[EMAIL PROTECTED]> > wrote: > > > <foo:bar size="3"/> \ "@size" > > > > Understood. However, I was wondering about how I could get a hold of > the size attribute when binding. > > On Tue, Sep 2, 2008 at 12:58 PM, David Pollak <[EMAIL PROTECTED]> wrote: > > > <foo:bar size="3"/> \ "@size" > > Daniel Green wrote: > > > When binding names to NodeSeq, is there a way to get a hold of the > attributes of the node being rendered? > > For example, say I have > > <foo:bar size="3"/> > > how would I retrieve the size of bar? > > bind("foo", <foo:bar size="3"/>, "bar" -> ....) > > I know you can get a NodeSeq of its children if you provide a > (NodeSeq) => NodeSeq, but that seems to only contain its children. > How > would I get a hold of the parent? This would be useful in widget > making/use. > > > > > > > > -- > Lift, the simply functional web framework http://liftweb.net > Collaborative Task Management http://much4.us > Follow me: http://twitter.com/dpp > Git some: http://github.com/dpp > > > > > > -- > Lift, the simply functional web framework http://liftweb.net > Collaborative Task Management http://much4.us > Follow me: http://twitter.com/dpp > Git some: http://github.com/dpp > > > > > > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Lift" group. To post to this group, send email to liftweb@googlegroups.com 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 -~----------~----~----~----~------~----~------~--~---