diff -r 69e26359f2c8 -r cf829ec742b3 src/main/scala/net/tz/lift/snippet/Panel.scala --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/scala/net/tz/lift/snippet/Panel.scala Sun Apr 03 15:55:02 2011 +0200 @@ -0,0 +1,57 @@ +/* + * Copyright 2011 Tomas Zeman + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package net.tz.lift.snippet + +import net.liftweb.mapper.MappedField +import scala.xml.{NodeSeq, Text} + +object AttrRow { + def apply(name: => NodeSeq, value: => NodeSeq) = new AttrRow(name, value, + "attr-name", "attr-value") + def apply(f: MappedField[_, _]) = new AttrRow(Text(f.displayName), f.asHtml, + "attr-name", "attr-value") + def formRow(name: => NodeSeq, input: => NodeSeq) = new AttrRow(name, input, + "form-name", "form-value") + def submitRow(button: => NodeSeq) = new SpanRow(button) +} + +class AttrRow(name: => NodeSeq, value: => NodeSeq, nameCss: String, + valueCss: String) extends Function0[NodeSeq] { + def tdN = {name} + def tdV = {value} + def apply(): NodeSeq = {tdN :: tdV :: Nil} +} + +class SpanRow(value: => NodeSeq) extends AttrRow(NodeSeq.Empty, value, "", "") +{ + override def apply(): NodeSeq = {value} +} + +object Panel { + def apply(attrs: Iterable[AttrRow]) = new Panel(attrs) + def fromFields(fields: Iterable[MappedField[_,_]]) = + new Panel(fields.map(AttrRow(_))) +} + +class Panel(attrs: => Iterable[AttrRow]) extends Function1[NodeSeq, NodeSeq] +{ + def apply(in: NodeSeq): NodeSeq = {attrs.map(_())}
+ def &(other: Function1[NodeSeq, NodeSeq]) = new Function1[NodeSeq, NodeSeq] { + def apply(in: NodeSeq): NodeSeq = List(Panel.this, other) flatMap (_(in)) + } +} + +// vim: set ts=2 sw=2 et: