DocLayer provides macro functions that are compile-time helpers designed to enhance type safety and developer experience (DX). These macros perform validation and transformation at build time, enabling powerful configuration patterns and type inference for: component UI, app configuration, and data adapters.
Global Context
All of these macros are auto-imported, globally accessible and can be used with application-based or content-related components without needing to import them. Outside of these contexts, you may need to import them directly from the @vuehouse/dl/exports package.
Bellow you'll find a comprehensive list of these utilities with a brief descriptions of their functionality. Where applicable, with examples that illustrate on how to use each effectively.
defineDoclayerAdapter
Creates an adapter function that utilizes useAsyncData for async data fetching.
Example:
Macro for creating standard DocLayer data adapters. defineDoclayerAdapter takes a factory callback and returns an adapter function that plugs into useAsyncData for type-safe async data fetching, automatic config handling, and consistent, global interface usage. It ensures your adapter always runs inside a Nuxt context, safely managing its configuration and input. Use this macro to quickly scaffold adapters for third-party APIs or internal services, ensuring consistent implementation and great DX across the app.
Everything about building and using adapters you can read here.
defineDoclayerAppConfig
Initializes the AppConfig on top of the pre-configured DocLayer's configuration.
Example:
Macro extends Nuxt's app configuration with DocLayer-specific options. It merges your custom configuration with DocLayer defaults, ensuring type safety and autocomplete for configuration properties. Use this to configure UI features, metadata, static data, and other DocLayer-specific settings alongside your standard Nuxt configuration.
Full AppConfig reference can be found here. Full guide on how to configure your app, along with all the sensible defaults can be found here.
defineDoclayerComponentUi
Builds a class list from an array of Tailwind CSS class names.
Example:
Macro is essential for defining component UI variants with Tailwind CSS. It leverages utilTWC to resolve class combinations and provide full type inference for your component markup. It returns a function that gives readonly access to the resolved UI object, ensuring type safety and full autocompletion throughout your component's HTML structure. Use this to create reusable, type-safe styling for your new and custom components. On how to building and defining a component's UI your can read more here.
defineDoclayerModule
Defines an internal DocLayer module.
Only for internal usage while contributing
This utility is within the experimental phase and not intended for regular application development (yet). Use it for DocLayer internals, especially when runtime and filesystem actions must be coordinated with module setup and lifecycle. It can't be auto-imported.
In the next release, we plan to expose a dedicated API for DocLayer's module system. This will allow you to create and register modules directly from the module configuration, injecting them into the modules pipeline without needing to create a separate modules file.
Example:
This macro standardizes and simplifies internal module runtime handling, utilizing the Nuxt Kit API. Designed exclusively for internal DocLayer module development, it ensures consistent formatting, safe artifact resolution, and controlled instantiation. The macro wraps your module’s setup logic and injects both Nuxt and DocLayer internals, allowing to implement build and runtime features in a single, unified way.
Newly created modules can be initialized using the registerDoclayerModules handler. Support for adding modules directly from the module configuration will be introduced soon.
Available context tooling includes:
| Property | Description |
|---|---|
hook | DocLayer internal hook registration. |
logger | DocLayer-scoped logger instance. |
nuxt | Current Nuxt instance. |
resolvePath | Path resolver bound to |
runtimeLoc | Internal runtime artifacts location. |
options | Resolved DocLayer module options. |
isModule | Async runtime check for module/app execution. |
