| author | Tomas Zeman <tzeman@volny.cz> |
| Wed, 30 Nov 2011 16:59:10 +0100 | |
| changeset 22 | 6b1a7f3429ca |
| parent 7 | 6e3d323f9ec5 |
| permissions | -rw-r--r-- |
| 2 | 1 |
/* |
2 |
* Copyright 2011 Tomas Zeman <tzeman@volny.cz> |
|
3 |
* |
|
4 |
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
5 |
* you may not use this file except in compliance with the License. |
|
6 |
* You may obtain a copy of the License at |
|
7 |
* |
|
8 |
* http://www.apache.org/licenses/LICENSE-2.0 |
|
9 |
* |
|
10 |
* Unless required by applicable law or agreed to in writing, software |
|
11 |
* distributed under the License is distributed on an "AS IS" BASIS, |
|
12 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
13 |
* See the License for the specific language governing permissions and |
|
14 |
* limitations under the License. |
|
15 |
*/ |
|
16 |
package net.tz.lift.snippet |
|
17 |
||
18 |
import net.liftweb.http._ |
|
19 |
import scala.xml.{NodeSeq, Text}
|
|
20 |
||
21 |
trait SnippetHelpers {
|
|
22 |
def mkPath(prefix: String, l: String*) = |
|
23 |
(prefix :: l.toList) mkString ("/", "/", "")
|
|
|
22
6b1a7f3429ca
ca1737768512bd36 Search by dynamic IP address, IP assignment history list
Tomas Zeman <tzeman@volny.cz>
parents:
7
diff
changeset
|
24 |
|
|
6b1a7f3429ca
ca1737768512bd36 Search by dynamic IP address, IP assignment history list
Tomas Zeman <tzeman@volny.cz>
parents:
7
diff
changeset
|
25 |
type CssTr = (NodeSeq => NodeSeq) |
| 2 | 26 |
} |
27 |
||
28 |
class A(href: => String) extends Function1[NodeSeq, NodeSeq] {
|
|
29 |
def apply(in: NodeSeq): NodeSeq = <a href={href}>{in}</a>
|
|
30 |
} |
|
31 |
||
32 |
object A {
|
|
|
7
6e3d323f9ec5
d6a28603feb67d4d CDR table columns
Tomas Zeman <tzeman@volny.cz>
parents:
2
diff
changeset
|
33 |
def apply(href: String, in: NodeSeq): NodeSeq = (new A(href))(in) |
| 2 | 34 |
def apply(href: String): A = new A(href) |
35 |
def apply(href: String, cnt: String): NodeSeq = (new A(href))(Text(cnt)) |
|
36 |
} |
|
37 |
||
38 |
object ActionLinks extends DispatchSnippet {
|
|
39 |
def dispatch: DispatchIt = {
|
|
40 |
case "are" => { xhtml => if (links.is.isEmpty) NodeSeq.Empty else xhtml }
|
|
41 |
case _ => render _ |
|
42 |
} |
|
43 |
||
44 |
import scala.collection.mutable.{BufferLike, ListBuffer}
|
|
45 |
||
46 |
private object links extends RequestVar[ListBuffer[Either[Function0[NodeSeq], Function1[NodeSeq, NodeSeq]]]](new ListBuffer()) |
|
47 |
||
48 |
def render(in: NodeSeq): NodeSeq = links.is.flatMap { _.fold( _(), _(in) ) ++
|
|
49 |
Text(" ") }
|
|
50 |
||
51 |
def append(l: NodeSeq) = links.is.append(Left( { () => l } ))
|
|
52 |
def append(l: () => NodeSeq) = links.is.append(Left(l)) |
|
53 |
def append(l: NodeSeq => NodeSeq) = links.is.append(Right(l)) |
|
54 |
} |
|
55 |
||
56 |
object SimpleForm {
|
|
57 |
def apply(l: Iterable[AttrRow], submitVal: String, onSubmit: () => Any): |
|
58 |
(NodeSeq => NodeSeq) = {
|
|
59 |
val curS = S.currentSnippet |
|
60 |
def doit() = {
|
|
61 |
onSubmit() |
|
62 |
curS foreach { S.mapSnippet(_, loop) }
|
|
63 |
} |
|
64 |
||
65 |
def loop: (NodeSeq => NodeSeq) = {
|
|
66 |
Panel(l ++ List(AttrRow.submitRow(SHtml.submit(submitVal, doit)))) |
|
67 |
} |
|
68 |
||
69 |
loop |
|
70 |
} |
|
71 |
||
72 |
def apply(l: Iterable[AttrRow], submitVal: String): (NodeSeq => NodeSeq) = |
|
73 |
apply(l, submitVal, () => ()) |
|
74 |
} |
|
75 |
||
76 |
// vim: set ts=2 sw=2 et: |