Packages

t

net.liftweb.util

AttrHelper

trait AttrHelper[+Holder[X]] extends AnyRef

A common function-like interface for accessing information about attributes, based on the two core findAttr and convert methods.

Extenders can be fairly flexible. The value of an attribute is specified by the extender as type Info. Possibly-missing attributes are returned in type Holder, which should be parametrizable. For example, you could create an AttrHelper that deals in String attribute values (type Info = String) and returns Options in cases where the attribute may not be found.

Note that you can invoke an AttrHelper with conversion functions to turn an Info into an arbitrary type.

A sample implementation:

case class HtmlAttributes(in: Elem) extends AttrHelper[Box] {
  type Info = String

  def findAttr(key: String): Option[Info] = {
    in.attribute(key).map(_.text)
  }

  def findAttr(prefix: String, key: String): Option[Info] = {
    in.attribute(prefix, key).map(_.text)
  }

  def convert[T](in: Option[T]): Box[T] = Box(in)
}

The helper above takes a scala Elem and provides a series of ways to access the values of its elements. For example:

val attributes = HtmlAttributes(elem)

attributes("class") // class attribute as String, Empty if absent
attributes("lift", "bind") // as above with lift:bind attribute
attributes("class", "nothing") // class attribute, "nothing" if absent
attributes("lift", "bind", "nothing") // as above with lift:bind attribute
attributes("class", _.split(" ")) // class attribute as array, Empty if absent
attributes("lift", "bind", _.split(" ")) // as above with lift:bind attribute
attributes("class", _.split(" "), Array()) // class attribute as array, Array() if absent
attributes("lift", "bind", _.split(" "), Array()) // as above with lift:bind attribute
Linear Supertypes
Known Subclasses
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. AttrHelper
  2. AnyRef
  3. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Type Members

  1. abstract type Info

Abstract Value Members

  1. abstract def convert[T](in: Option[T]): Holder[T]
    Attributes
    protected
  2. abstract def findAttr(prefix: String, key: String): Option[Info]
    Attributes
    protected
  3. abstract def findAttr(key: String): Option[Info]
    Attributes
    protected

Concrete Value Members

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  4. def apply[T](prefix: String, key: String, f: (Info) ⇒ T, default: ⇒ T): T
  5. def apply[T](key: String, f: (Info) ⇒ T, default: ⇒ T): T
  6. def apply[T](prefix: String, key: String, f: (Info) ⇒ T): Holder[T]
  7. def apply[T](key: String, f: (Info) ⇒ T): Holder[T]
  8. def apply(prefix: String, key: String, default: ⇒ Info): Info
  9. def apply(key: String, default: ⇒ Info): Info
  10. def apply(prefix: String, key: String): Holder[Info]
  11. def apply(key: String): Holder[Info]
  12. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  13. def clone(): AnyRef
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  14. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  15. def equals(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  16. def finalize(): Unit
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  17. final def getClass(): Class[_]
    Definition Classes
    AnyRef → Any
  18. def hashCode(): Int
    Definition Classes
    AnyRef → Any
  19. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  20. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  21. final def notify(): Unit
    Definition Classes
    AnyRef
  22. final def notifyAll(): Unit
    Definition Classes
    AnyRef
  23. final def synchronized[T0](arg0: ⇒ T0): T0
    Definition Classes
    AnyRef
  24. def toString(): String
    Definition Classes
    AnyRef → Any
  25. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  26. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  27. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )

Inherited from AnyRef

Inherited from Any

Ungrouped