Trait

net.liftweb.util

AttrHelper

Related Doc: package util

Permalink

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

    Permalink

Abstract Value Members

  1. abstract def convert[T](in: Option[T]): Holder[T]

    Permalink
    Attributes
    protected
  2. abstract def findAttr(prefix: String, key: String): Option[Info]

    Permalink
    Attributes
    protected
  3. abstract def findAttr(key: String): Option[Info]

    Permalink
    Attributes
    protected

Concrete Value Members

  1. final def !=(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  4. def apply[T](prefix: String, key: String, f: (Info) ⇒ T, default: ⇒ T): T

    Permalink
  5. def apply[T](key: String, f: (Info) ⇒ T, default: ⇒ T): T

    Permalink
  6. def apply[T](prefix: String, key: String, f: (Info) ⇒ T): Holder[T]

    Permalink
  7. def apply[T](key: String, f: (Info) ⇒ T): Holder[T]

    Permalink
  8. def apply(prefix: String, key: String, default: ⇒ Info): Info

    Permalink
  9. def apply(key: String, default: ⇒ Info): Info

    Permalink
  10. def apply(prefix: String, key: String): Holder[Info]

    Permalink
  11. def apply(key: String): Holder[Info]

    Permalink
  12. final def asInstanceOf[T0]: T0

    Permalink
    Definition Classes
    Any
  13. def clone(): AnyRef

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  14. final def eq(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  15. def equals(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  16. def finalize(): Unit

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  17. final def getClass(): Class[_]

    Permalink
    Definition Classes
    AnyRef → Any
  18. def hashCode(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  19. final def isInstanceOf[T0]: Boolean

    Permalink
    Definition Classes
    Any
  20. final def ne(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  21. final def notify(): Unit

    Permalink
    Definition Classes
    AnyRef
  22. final def notifyAll(): Unit

    Permalink
    Definition Classes
    AnyRef
  23. final def synchronized[T0](arg0: ⇒ T0): T0

    Permalink
    Definition Classes
    AnyRef
  24. def toString(): String

    Permalink
    Definition Classes
    AnyRef → Any
  25. final def wait(): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  26. final def wait(arg0: Long, arg1: Int): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  27. final def wait(arg0: Long): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )

Inherited from AnyRef

Inherited from Any

Ungrouped