Atomizer

An utility class for loading/parsing and creating templates.

Remarks

This class is responsible for loading the templates from the template folder. It also provides a function to build the component tree from the HTML string.

Author

Sujal Choudhari <sjlchoudhari.gmail.com>

Hierarchy

  • Atomizer

Properties

templateFolders: [{
    baseDir: string;
    htmlDir: string;
    cssDir: string;
    jsDir: string;
}] = ...

The folder where the templates are stored.

Remarks

Only the templated from this folder will be preloaded loaded. If there are many template folders then those components will have to be loaded manually. or change the template folder and preload the templates again.

Author

Ansh Sharma

templateFilesToInclude: string[] = []
templates: {
    [key: string]: AtomizerTemplate;
}[] = ...

The preloaded templates (the default ones)

Methods

  • Load a template from the template folder

    Returns

    New atomizer template

    Parameters

    • filename: string

      The name of the template file

    • templateFolderIndex: number

    Returns AtomizerTemplate

  • Preload All the templates from the template folder.

    Returns

    A dictionary of all the preloaded templates with their names as keys.

    Returns {
        [key: string]: AtomizerTemplate;
    }[]

  • Build the component tree from the atom.

    Returns

    The root component of the component tree.

    Parameters

    • atom: Atom

      The atom to be parsed and built into a component tree

    Returns Component

  • A static method in the Atomizer class that adds a new template folder to the templateFolders array.

    Remarks

    If the templateFolder object's baseDir property does not already exist in Atomizer.templateFolders, the templateFolder object is pushed into Atomizer.templateFolders. Then, the templates in the newly added folder are preloaded and pushed into Atomizer.templates. If the baseDir already exists in Atomizer.templateFolders, a warning is logged.

    Author

    Ansh Sharma

    Parameters

    • templateFolder: {
          baseDir: string;
          htmlDir: string;
          cssDir: string;
          jsDir: string;
      }

      An object containing the base directory and optional subdirectories for the template folder.

      • baseDir: string

        The base directory for the template folder.

      • htmlDir: string

        Optional subdirectory for HTML templates.

      • cssDir: string

        Optional subdirectory for CSS templates.

      • jsDir: string

        Optional subdirectory for JavaScript templates.

    Returns void

  • A static method in the Atomizer class that retrieves a template with the specified name and index from the templates property.

    Returns

    • The requested template.

    Remarks

    If the template is found in the templates property, it is returned immediately. If the template is not found, this method searches through all template folders for the specified name. If a template is found, it is returned and cached in the templates property for future use. If no template is found, an error message is logged and an empty string is returned.

    Author

    Ansh Sharma

    Parameters

    • templateName: string

      The name of the template to retrieve.

    • Optional templateFolderIndex: 0

      The index of the folder containing the template. Defaults to 0.

    Returns AtomizerTemplate

  • Build the component tree from the HTML string.

    Returns

    The root component of the component tree.

    Parameters

    • html: string

      The HTML string to be parsed and built into a component tree

    Returns Component

Constructors