Skip to content
This repository has been archived by the owner on Jul 17, 2023. It is now read-only.

Commit

Permalink
feat(templates): add typings
Browse files Browse the repository at this point in the history
  • Loading branch information
robertrossmann committed Dec 6, 2018
1 parent 2f190a7 commit 80f4f40
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 5 deletions.
10 changes: 5 additions & 5 deletions packages/templates/src/action.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ export default class Templates extends Action {
/**
* Render a template into HTML
*
* @param {String} name The template's name. This is the relative path to the
* template's location in the `templates` directory,
* without file extension
* @param {Object} [locals={}] Locals to be sent to the template engine
* @return {Promise<String>} The rendered HTML string
* @param {String} name The template's name. This is the relative path to the
* template's location in the `templates` directory, without file
* extension
* @param {Object} locals Locals to be sent to the template engine
* @return {Promise<String>} The rendered HTML string
*/
render(name, locals = {}) {
// Location of the template on filesystem, relative to Atlas root and templates directories
Expand Down
70 changes: 70 additions & 0 deletions packages/templates/src/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
declare module '@atlas.js/templates' {
import AtlasAction from '@atlas.js/action'

/**
* This component allows you to render a wide range of templating languages into the final HTML
*
* Under the hood, the [_consolidate.js_](https://github.com/tj/consolidate.js) project is used
* for the actual rendering, so any template language supported by that project is also supported
* here.
*/
class Action extends AtlasAction {
/** Action runtime configuration values */
config: Action.Config

/**
* Render a template with the specified name into HTML
*
* The template name must match the template's filename, relative to the location of the
* templates directory specified in this component's configuration.
*
* @param template The template's filename, relative to the templates' directory
* @param locals Optional variables to be provided to the template
* @return {Promise<string>} The rendered HTML string
*/
render(template: string, locals?: object): Promise<string>
}

namespace Action {
/** Configuration schema available to this action */
interface Config {
/**
* Filesystem location, relative to `atlas.root`, where the templates are located
* @default templates
*/
templates?: string

/**
* File extension to look for when resolving template names into actual files
* @default .pug
*/
extension?: string

/**
* Templating engine to use
*
* @see https://github.com/tj/consolidate.js for supported languages
* @default pug
*/
engine?: string

/**
* Local values to be passed directly to the rendering engine as variable replacements
*/
locals?: {
/**
* Some engines support various caching strategies. Set this to `false` to disable this.
*
* @see https://github.com/tj/consolidate.js#caching
* @default true
*/
cache?: boolean
[key: string]: any
}
}
}

export {
Action,
}
}

0 comments on commit 80f4f40

Please sign in to comment.