Packages

o

laika.directive

Templates

object Templates extends BuilderContext[TemplateSpan]

The API for declaring directives that can be used in templates.

Linear Supertypes
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. Templates
  2. BuilderContext
  3. AnyRef
  4. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Type Members

  1. sealed trait BodyContent extends AnyRef

    The content of a directive part, either an attribute or the body.

    The content of a directive part, either an attribute or the body.

    Definition Classes
    BuilderContext
  2. trait Combinators extends AnyRef

    Provides combinators to describe the expected structure of a specific directive.

    Provides combinators to describe the expected structure of a specific directive.

    Definition Classes
    BuilderContext
  3. class Directive extends AnyRef

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

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

    Definition Classes
    BuilderContext
  4. case class DirectiveContent(attributes: Config, body: Option[BodyContent]) extends Product with Serializable

    The content of a parsed directive with the HOCON attributes captured in a Config instance.

    The content of a parsed directive with the HOCON attributes captured in a Config instance.

    Definition Classes
    BuilderContext
  5. case class DirectiveContext(content: DirectiveContent, parser: Parser, cursor: DocumentCursor, source: SourceFragment) extends Product with Serializable

    The context of a directive during execution.

    The context of a directive during execution.

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

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

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

    Definition Classes
    BuilderContext
  7. case class Multipart[T](mainBody: Seq[E], children: Seq[T]) extends Product with Serializable

    The content of a body element divided by separator directives.

    The content of a body element divided by separator directives.

    Definition Classes
    BuilderContext
  8. class SeparatorDirective[+T] extends AnyRef

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

    Represents a separator directive, its name and its (combined) parts. It also allows to specify requirements for the minimum and maximum number of occurrences allowed for this directive. The default is unbounded, with 0 or more instances allowed.

    Definition Classes
    BuilderContext
  9. case class DirectiveInstance(directive: Option[Templates.Directive], parsedResult: ParsedDirective, parser: RecursiveSpanParsers, source: SourceFragment, options: Options = NoOpt) extends Element with SpanResolver with TemplateSpan with DirectiveInstanceBase with Product with Serializable
  10. type Parser = RecursiveSpanParsers

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

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

    Definition Classes
    TemplatesBuilderContext
  11. type Result[+A] = Either[Seq[String], A]
    Definition Classes
    BuilderContext
  12. case class SeparatorInstance(parsedResult: ParsedDirective, source: SourceFragment, options: Options = NoOpt) extends Element with TemplateSpan with SeparatorInstanceBase with SpanResolver with Product with Serializable

Value Members

  1. object BodyContent
    Definition Classes
    BuilderContext
  2. object DirectivePart
    Definition Classes
    BuilderContext
  3. object dsl extends Combinators

    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 attributes 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 attributes, followed 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.

    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[Block], options: Options = NoOpt)
                                                        extends Block with BlockContainer[Note]
    
    object MyDirectives extends DirectiveRegistry {
      val blockDirectives = Seq(
        Blocks.create("note") {
          (defaultAttribute.as[String], parsedBody).mapN(Note(_,_))
        }
      )
      val spanDirectives = Seq()
    }
    
    val transformer = Transformer.from(Markdown).to(HTML).using(MyDirectives)

    The defaultAttribute combinator specifies a required attribute of type String and without a name. The parsedBody combinator specifies standard block content (any block elements that are supported in normal markup, too) which results in a parsed value of type Seq[Block].

    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 block directive the final result has to be of type Block 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 of attributes is required it can be performed with the as[T] method:

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

    In the example above the built-in Int decoder gets passed to the defaultAttribute combinator, but you can easily create and use your own instances of ConfigDecoder[T].

    If required attributes or bodies are missing or any type conversion fails, an instance of InvalidBlock containing the error 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.

    Finally attributes 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") {
        (defaultAttribute.as[Int].optional, blockContent).mapN {
          (severity, content) => Message(severity.getOrElse(0), content)
        }
      }
    )

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

    Definition Classes
    BuilderContext
  4. final def !=(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  5. final def ##(): Int
    Definition Classes
    AnyRef → Any
  6. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  7. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  8. def clone(): AnyRef
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... ) @native()
  9. def create(name: String)(part: DirectivePart[TemplateSpan]): Directive

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

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

    Definition Classes
    BuilderContext
  10. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  11. def equals(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  12. def eval(name: String)(part: DirectivePart[Either[String, TemplateSpan]]): Directive

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

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

    When the result of the directive is a Left, the directive will produce an invalid AST element with the string as the error message.

    Definition Classes
    BuilderContext
  13. def finalize(): Unit
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  14. final def getClass(): Class[_]
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  15. def hashCode(): Int
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  16. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  17. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  18. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  19. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  20. def parse(parser: Parser, src: SourceFragment): Result[Seq[TemplateSpan]]
    Attributes
    protected
    Definition Classes
    TemplatesBuilderContext
  21. def separator[T](name: String, min: Int = 0, max: Int = Int.MaxValue)(part: DirectivePart[T]): SeparatorDirective[T]

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

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

    Definition Classes
    BuilderContext
  22. final def synchronized[T0](arg0: ⇒ T0): T0
    Definition Classes
    AnyRef
  23. def toMap(directives: Iterable[Directive]): Map[String, Directive]

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

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

    Definition Classes
    BuilderContext
  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( ... ) @native()

Inherited from BuilderContext[TemplateSpan]

Inherited from AnyRef

Inherited from Any

Ungrouped