src/main/scala/net/tz/lift/snippet/DataTable.scala
author Tomas Zeman <tzeman@volny.cz>
Mon, 02 Apr 2012 00:06:52 +0200
changeset 21 641c7190c566
parent 15 995184977e9b
child 42 7c811cdfa4c3
permissions -rw-r--r--
Upgrade of sbt, lift et al.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
15
995184977e9b a3e3bd30f0d19526 Contact UI
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
     1
/*
21
641c7190c566 Upgrade of sbt, lift et al.
Tomas Zeman <tzeman@volny.cz>
parents: 15
diff changeset
     2
 * Copyright 2011-2012 Tomas Zeman <tzeman@volny.cz>
15
995184977e9b a3e3bd30f0d19526 Contact UI
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
     3
 *
995184977e9b a3e3bd30f0d19526 Contact UI
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
     4
 * Licensed under the Apache License, Version 2.0 (the "License");
995184977e9b a3e3bd30f0d19526 Contact UI
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
     5
 * you may not use this file except in compliance with the License.
995184977e9b a3e3bd30f0d19526 Contact UI
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
     6
 * You may obtain a copy of the License at
995184977e9b a3e3bd30f0d19526 Contact UI
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
     7
 *
995184977e9b a3e3bd30f0d19526 Contact UI
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
     8
 *     http://www.apache.org/licenses/LICENSE-2.0
995184977e9b a3e3bd30f0d19526 Contact UI
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
     9
 *
995184977e9b a3e3bd30f0d19526 Contact UI
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    10
 * Unless required by applicable law or agreed to in writing, software
995184977e9b a3e3bd30f0d19526 Contact UI
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    11
 * distributed under the License is distributed on an "AS IS" BASIS,
995184977e9b a3e3bd30f0d19526 Contact UI
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
995184977e9b a3e3bd30f0d19526 Contact UI
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    13
 * See the License for the specific language governing permissions and
995184977e9b a3e3bd30f0d19526 Contact UI
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    14
 * limitations under the License.
995184977e9b a3e3bd30f0d19526 Contact UI
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    15
 */
995184977e9b a3e3bd30f0d19526 Contact UI
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    16
package net.tz.lift.snippet
995184977e9b a3e3bd30f0d19526 Contact UI
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    17
21
641c7190c566 Upgrade of sbt, lift et al.
Tomas Zeman <tzeman@volny.cz>
parents: 15
diff changeset
    18
import net.liftweb.http.Templates
15
995184977e9b a3e3bd30f0d19526 Contact UI
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    19
import net.liftweb.util.Helpers._ // CSS transforms
995184977e9b a3e3bd30f0d19526 Contact UI
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    20
import scala.xml.NodeSeq
995184977e9b a3e3bd30f0d19526 Contact UI
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    21
995184977e9b a3e3bd30f0d19526 Contact UI
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    22
/**
995184977e9b a3e3bd30f0d19526 Contact UI
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    23
 * Template driven table, compatible w/ datatables.net.
995184977e9b a3e3bd30f0d19526 Contact UI
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    24
 * Template location: <code>/templates-hidden/datatable</code>.
995184977e9b a3e3bd30f0d19526 Contact UI
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    25
 */
995184977e9b a3e3bd30f0d19526 Contact UI
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    26
class DataTable(cols: List[String], cells: List[List[NodeSeq]]) extends CssTr {
21
641c7190c566 Upgrade of sbt, lift et al.
Tomas Zeman <tzeman@volny.cz>
parents: 15
diff changeset
    27
  def apply(in: NodeSeq): NodeSeq = Templates(
15
995184977e9b a3e3bd30f0d19526 Contact UI
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    28
    List("templates-hidden", "datatable")) map { xml =>
995184977e9b a3e3bd30f0d19526 Contact UI
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    29
    (".field-name *" #> cols &
995184977e9b a3e3bd30f0d19526 Contact UI
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    30
    ".row *" #> cells.map { vals => "td *" #> vals })(xml)
995184977e9b a3e3bd30f0d19526 Contact UI
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    31
  } openOr NodeSeq.Empty
995184977e9b a3e3bd30f0d19526 Contact UI
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    32
}
995184977e9b a3e3bd30f0d19526 Contact UI
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    33
995184977e9b a3e3bd30f0d19526 Contact UI
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    34
// vim: set ts=2 sw=2 et: