Options
All
  • Public
  • Public/Protected
  • All
Menu

A Writer knows how to take a stream of tokens and render them to a string, given a context.

It also maintains a cache of templates to avoid the need to parse the same template twice.

Hierarchy

  • MustacheWriter

Index

Constructors

constructor

  • Initializes a new instance of the MustacheWriter class.

    Returns MustacheWriter

Methods

clearCache

  • clearCache(): void
  • Clears all cached templates in this writer.

    Returns void

parse

  • parse(template: string, tags?: string[]): any
  • Parses and caches the given template and returns the array of tokens that is generated from the parse.

    Parameters

    • template: string

      The template to parse.

    • Optional tags: string[]

      The tags to use.

    Returns any

render

  • render(template: string, view: any | MustacheContext, partials: any, tags?: string[]): string
  • High-level method that is used to render the given template with the given view.

    Parameters

    • template: string

      The template to render.

    • view: any | MustacheContext

      The view to render the template with.

    • partials: any

      Either an object that contains the names and templates of partials that are used in a template

      -- or --

      A function that is used to load partial template on the fly that takes a single argument: the name of the partial.

    • Optional tags: string[]

      The tags to use.

    Returns string

renderTokens

  • renderTokens(tokens: string[], context: MustacheContext, partials: any, originalTemplate: any): string
  • Low-level method that renders the given array of tokens using the given context and partials.

    Parameters

    • tokens: string[]

      The tokens to render.

    • context: MustacheContext

      The context to use for rendering the tokens.

    • partials: any

      The partials to use for rendering the tokens.

    • originalTemplate: any

      An object used to extract the portion of the original template that was contained in a higher-order section.

      If the template doesn't use higher-order sections, this argument may be omitted.

    Returns string

Generated using TypeDoc