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