src/main/scala/net/tz/lift/snippet/Loc.scala
author Tomas Zeman <tzeman@volny.cz>
Mon, 02 Apr 2012 00:06:52 +0200
changeset 21 641c7190c566
parent 15 995184977e9b
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.sitemap.Loc._
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
 * Helper object for custom Loc template based on template path, eg.
995184977e9b a3e3bd30f0d19526 Contact UI
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    24
 * <code>item/view</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
object LocTpl {
995184977e9b a3e3bd30f0d19526 Contact UI
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    27
995184977e9b a3e3bd30f0d19526 Contact UI
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    28
  def apply(path: String): Template = Template(() =>
21
641c7190c566 Upgrade of sbt, lift et al.
Tomas Zeman <tzeman@volny.cz>
parents: 15
diff changeset
    29
    Templates(path split "/" toList) openOr NodeSeq.Empty)
15
995184977e9b a3e3bd30f0d19526 Contact UI
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    30
995184977e9b a3e3bd30f0d19526 Contact UI
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    31
  def apply[T](f: T => String): ValueTemplate[T] = ValueTemplate[T](
21
641c7190c566 Upgrade of sbt, lift et al.
Tomas Zeman <tzeman@volny.cz>
parents: 15
diff changeset
    32
    _.flatMap { v => Templates(f(v) split "/" toList)
15
995184977e9b a3e3bd30f0d19526 Contact UI
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    33
    } openOr NodeSeq.Empty)
995184977e9b a3e3bd30f0d19526 Contact UI
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    34
}
995184977e9b a3e3bd30f0d19526 Contact UI
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    35
995184977e9b a3e3bd30f0d19526 Contact UI
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    36
// vim: set ts=2 sw=2 et: