Options
All
  • Public
  • Public/Protected
  • All
Menu

Class DirectivesParser

Finds all the directives in the html code passed as fileContents and calls the executers on each. This acts also as the executer for the component directive. In this way the component directive is executed recursively on each component before all other directives.

Hierarchy

  • DirectivesParser

Index

Constructors

constructor

  • new DirectivesParser(fileFullPath: string, fileContents: string, lang: string, config: YassbConfig, keepFrontMatterData?: boolean): DirectivesParser
  • Creates an instance of DirectivesParser.

    Parameters

    • fileFullPath: string

      the full path to the file being processed.

    • fileContents: string

      The HTML code of the file being analyzed.

    • lang: string

      The current language if i18n is enabled.

    • config: YassbConfig

      The YASSB configuration object.

    • Default value keepFrontMatterData: boolean = false

      Tells DirectivesParser whether to clean or not the static property frontMatterData.

    Returns DirectivesParser

Properties

Private config

config: YassbConfig

The YASSB configuration object.

Private fileContents

fileContents: string

The HTML code of the file being analyzed.

Private fileFullPath

fileFullPath: string

the full path to the file being processed.

Private keepFrontMatterData

keepFrontMatterData: boolean

Tells DirectivesParser whether to clean or not the static property frontMatterData.

Private lang

lang: string

The current language if i18n is enabled.

Static frontMatterData

frontMatterData: FrontMatterData

Store for all the data retrieved in Front Matter. Static so data persists between child instances of DirectiveParser parsing nested components of the same parent file.

Static regex

regex: RegExp = /<!--\s*component\s*=\s*".+\..+"\s*-->/g

Regex to match the comments to invoke the directive.

Methods

Private componentDirective

  • componentDirective(): void
  • Loops all component directives and injects the content in current fileContents. Inside the loop a new instance of DirectivesParser is initiated for each nested components found. In this way when the top level loop ends, the whole page is already available for the following directives

    Returns void

Private handleComponent

  • handleComponent(componentFullString: string): string
  • Analyzes the component directive, gets the content of the directive. After retrieving the contents it initializes a new DirectivesParser on the content of the component to look for nested directives. The loop repeats until there are no more nested components.

    remarks

    Currently there are no check to prevent infinite loops. It would be nice if there were.

    Parameters

    • componentFullString: string

      full string of the directive to execute

    Returns string

inject

  • inject(): string
  • Finds directives and executes them recursively. The first directives to be executed recursively is the component directive. In this way when the other directives are executed the are presente with the full html code of the page.

    Returns string

Private invokeDirectives

  • invokeDirectives(): void
  • Loops all built-in and custom directives and delegates to the Class the generation of the HTML. Applies the html to filecontents and if any data has been returned it is added in Front Matter.

    see

    DirectivesInvoker

    Returns void