Coralite library

The Coralite library is used for processing and rendering HTML documents with custom elements, templates, and plugins. It provides a structured way to manage document metadata, template paths, plugin configurations, and ignored attributes during rendering.

Coralite constructor

Parameters

Name Type Attribute Description
options Object Required Configuration options for the `Coralite` constructor.
options.templates string Required The absolute or relative path to the directory containing Coralite templates.
options.pages string Required The absolute or relative path to the directory containing pages to be rendered with the provided templates.
options.plugins CoralitePluginInstance[] Optional An array of plugin instances that extend Coralite's functionality.
options.ignoreByAttribute IgnoreByAttribute[] Optional An array of objects specifying attribute name-value pairs to ignore during document processing. Each object must have a name and value property.

Example useabe

JavaScript
Code copied!
const coralite = new Coralite({
  templates: './src/templates',
  pages: './src/pages',
  plugins: [myCustomPlugin],
  ignoreByAttribute: [
    { name: 'data-ignore', value: 'true' },
    { name: 'aria-hidden', value: 'true' }
  ]
});

Coralite compile method

The compile method is used to compile and render HTML pages into final output documents. It processes page content, replaces custom elements with corresponding components, and returns compiled results along with performance metrics such as rendering duration.

Name Type Attribute Description
path string | string[] Optional The path or array of paths to the HTML files relative to the project's pages directory. If omitted, compiles all pages in the pages directory.

Example usage

Compile a single page by providing its file path:

JavaScript
Code copied!
coralite.compile('pages/home/index.html')
  .then(documents => {
    console.log('Compilation result:', documents);
  })
  .catch(error => {
    console.error('Error during compilation:', error);
  });

Compiling multiple pages using an array of paths

JavaScript
Code copied!
coralite.compile(['pages/home/index.html', 'pages/about/index.html'])
  .then(documents => {
    documents.forEach((document, index) => {
      console.log(`Result for page ${index + 1}:`, document);
    });
  })
  .catch(error => {
    console.error('Error during compilation:', error);
  });

Compiling all pages by omitting the path parameter:

JavaScript
Code copied!
coralite.compile()
  .then(documents => {
    console.log('All compiled documents:', documents)
  })
  .catch(error => {
    console.error('Error compiling all pages:', error)
  });

Coralite compile method

The compile method is used to compile and render HTML pages into final output documents. It processes page content, replaces custom elements with corresponding components, and returns compiled results along with performance metrics such as rendering duration.

Name Type Attribute Description
documents Array<CoraliteResult> Required An array of CoraliteResult objects containing rendered document data.
output string Required The base directory path where HTML files will be saved. Must exist on disk.

Example usage

JavaScript
Code copied!
coralite.compile()
  .then(async (documents) => {
    // save documents to disk
    await coralite.save(documents, './output')
  })
  .catch(error => {
    console.error('Error compiling all pages:', error)
  })