Trait

laika.directive

BuilderContext

Related Doc: package directive

Permalink

trait BuilderContext[E <: Element] extends AnyRef

Provides the basic building blocks for Laika's Directive API. This trait is not used directly, but instead its three subtraits Blocks, Spans and Templates, which represent the concrete implementations for the three directive types.

Linear Supertypes
AnyRef, Any
Known Subclasses
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. BuilderContext
  2. AnyRef
  3. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Type Members

  1. trait Combinators extends AnyRef

    Permalink

    Provides various combinators to describe the expected format of a specific directive.

  2. type Converter[T] = (Parser, String) ⇒ Result[T]

    Permalink
  3. trait Converters extends AnyRef

    Permalink

    Provides various converter functions that can be used with the directive combinators to convert the string value obtained from a directive attribute or body.

  4. class Directive extends AnyRef

    Permalink

    Represents a directive, its name and its (combined) parts.

  5. trait DirectiveContext extends AnyRef

    Permalink

    The context of a directive during execution.

  6. abstract class DirectivePart[+A] extends (DirectiveContext) ⇒ Result[A]

    Permalink

    Represents a single part (attribute or body) of a directive or a combination of multiple parts.

  7. trait IdBuilders extends AnyRef

    Permalink
  8. abstract type Parser <: (String) ⇒ Seq[E]

    Permalink

    The parser API in case a directive function needs to manually parse one of the directive parts.

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. implicit object CanBuildDirectivePart extends CanBuild[DirectivePart]

    Permalink

    Type class required for using the generic Builders API with directives.

  5. final def asInstanceOf[T0]: T0

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

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  7. def create(name: String)(part: DirectivePart[E]): Directive

    Permalink

    Creates a new directive with the specified name and part specification.

  8. object dsl extends Combinators with Converters with IdBuilders with Implicits

    Permalink

    Provides the basic building blocks for defining directives, Laika's extension mechanism for creating custom tags for both, templates or text markup.

    Provides the basic building blocks for defining directives, Laika's extension mechanism for creating custom tags for both, templates or text markup.

    This object is used as part of the concrete objects Blocks.dsl, Spans.dsl and Templates.dsl respectively.

    It contains several simple combinators that allow to specify the expected attributes and body elements of the directive, optional converters for these elements and the function responsible for producing the final node element.

    In contrast to custom tag hooks in other template engines the result of a directive is not a string. In the same way as markup documents get transformed into a tree of elements before rendering, a directive produces a node of the tree to render. As a result, the directive can be used independent from the output format.

    Entry points of the API are the Templates, Blocks and Spans objects for the three different directive types.

    A directive may consist of any combination of arguments, fields and body elements:

    @:myDirective arg1=value1 arg2=value2: {
      This is the body of the directive. It may consist of any standard or custom
      block-level and inline markup.
    }

    In the example above arg1 and arg2 are arguments, ollowed by a body element enclosed in curly braces.

    For each of these directive elements, the API offers a combinator to specify whether the element is required or optional, and an optional function to convert or validate the parsed value.

    Consider the following simple example of a directive with just one argument and a body, for specifying a specially formatted inline note:

    @:note This is the title: { This is the body of the note. }

    The implementation of this directive could look like this:

    case class Note (title: String, content: Seq[Span], options: Options = NoOpt)
                                                        extends Span with SpanContainer[Note]
    
    object MyDirectives extends DirectiveRegistry {
      val spanDirectives = Seq(
        Spans.create("note") {
          (attribute(Default) ~ body(Default)) (Note(_,_))
        }
      )
      val blockDirectives = Seq()
    }
    
    Transform from Markdown to HTML using MyDirectives fromFile "hello.md" toFile "hello.html"

    The attribute(Default) combinator specifies a required attribue of type String (since no conversion function was supplied) and without a name (indicated by passing the Default object instead of a string name). The body combinator specifies standard inline content (any span elements that are supported in normal inline markup, too) which results in a parsed value of type Seq[Span].

    Finally you need to provide a function that accepts the results of the specified directive elements as parameters (of the corresponding type). Here we created a case class with a matching signature so can pass it directly as the target function. For a span directive the final result has to be of type Span which the Note class satisfies. Finally the directive gets registered with the Markdown parser. It can be registered for a reStructuredText parser, too, without any changes.

    If any conversion or validation is required on the individual parts of the directive they can be passed to the corresponding function:

    case class Message (severity: Int,
                        content: Seq[Block],
                        options: Options = NoOpt) extends Block
                                                  with BlockContainer[Message]
    
    val blockDirectives = Seq(
      Blocks.create("message") {
        (attribute(Default, positiveInt) ~ blockContent) (Message(_,_))
      }
    )

    In the example above the built-in positiveInt converter gets passed to the attribute combinator, but you can easily create and use your own functions. The function has to accept a string argument and return a Result[T].

    The Failure subtype of Result will be interpreted as an error by the interpreter with the string being used as the message and an instance of InvalidBlock containing the validator message and the raw source of the directive will be inserted into the document tree. In this case the final function (Message) will never be invoked.

    The Success subtype of Result will be used as an argument to the final function. Note how the case class now expects an Int as the first parameter.

    Finally attributes and body elements can also be optional. In case they are missing, the directive is still considered valid and None will be passed to your function:

    case class Message (severity: Int,
                        content: Seq[Block],
                        options: Options = NoOpt) extends Block
                                                  with BlockContainer[Message]
    
    val blockDirectives = Seq(
      Blocks.create("message") {
        (attribute(Default, positiveInt).optional ~ blockContent) (Message(_,_))
      }
    )

    The attribute may be missing, but if it is present it has to pass the specified validator.

  9. final def eq(arg0: AnyRef): Boolean

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

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

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

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

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

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

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

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

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

    Permalink
    Definition Classes
    AnyRef
  19. def toMap(directives: Iterable[Directive]): Map[String, Directive]

    Permalink

    Turns a collection of directives into a map, using the name of the directive as the key.

  20. def toString(): String

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

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

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

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

Inherited from AnyRef

Inherited from Any

Ungrouped