Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: eta-dev/eta
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: main
Choose a base ref
...
head repository: nhaef/eta
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
Can’t automatically merge. Don’t worry, you can still create the pull request.
  • 6 commits
  • 3 files changed
  • 1 contributor

Commits on Dec 8, 2022

  1. Add PartialAsyncConfig

    nhaef committed Dec 8, 2022

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    3afb467 View commit details
  2. Copy the full SHA
    721332e View commit details
  3. Copy the full SHA
    0bfcd44 View commit details

Commits on Dec 15, 2022

  1. Copy the full SHA
    72f2fdf View commit details
  2. remove semi

    nhaef committed Dec 15, 2022
    Copy the full SHA
    0c19c15 View commit details

Commits on Jan 9, 2023

  1. Copy the full SHA
    eb8d6ab View commit details
Showing with 153 additions and 3 deletions.
  1. +1 −0 src/config.ts
  2. +28 −2 src/file-handlers.ts
  3. +124 −1 src/render.ts
1 change: 1 addition & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
@@ -90,6 +90,7 @@ export interface EtaConfigWithFilename extends EtaConfig {
}

export type PartialConfig = Partial<EtaConfig>
export type PartialAsyncConfig = PartialConfig & { async: true }

/* END TYPES */

30 changes: 28 additions & 2 deletions src/file-handlers.ts
Original file line number Diff line number Diff line change
@@ -170,14 +170,27 @@ function includeFile(path: string, options: EtaConfig): [TemplateFunction, EtaCo
* ```
*/

function renderFile(
filename: string,
data: DataObj,
config?: PartialConfig,
): Promise<string>

function renderFile(
filename: string,
data: DataObj,
config: PartialConfig,
cb: CallbackFn
): void

function renderFile(
filename: string,
data: DataObj,
config?: PartialConfig,
cb?: CallbackFn
): Promise<string> | void

function renderFile(filename: string, data: DataObj, cb?: CallbackFn): Promise<string> | void
function renderFile(filename: string, data: DataObj, cb: CallbackFn): void

function renderFile(
filename: string,
@@ -268,14 +281,27 @@ function renderFile(
* ```
*/

function renderFileAsync(
filename: string,
data: DataObj,
config?: PartialConfig
): Promise<string>

function renderFileAsync(
filename: string,
data: DataObj,
config: PartialConfig,
cb: CallbackFn
): void

function renderFileAsync(
filename: string,
data: DataObj,
config?: PartialConfig,
cb?: CallbackFn
): Promise<string> | void

function renderFileAsync(filename: string, data: DataObj, cb?: CallbackFn): Promise<string> | void
function renderFileAsync(filename: string, data: DataObj, cb: CallbackFn): void

function renderFileAsync(
filename: string,
125 changes: 124 additions & 1 deletion src/render.ts
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@ import EtaErr from './err'

/* TYPES */

import type { EtaConfig, PartialConfig } from './config'
import type { EtaConfig, PartialConfig, PartialAsyncConfig } from './config'
import type { TemplateFunction } from './compile'
import type { CallbackFn } from './file-handlers'

@@ -45,6 +45,83 @@ function handleCache(template: string | TemplateFunction, options: EtaConfig): T
* @param config Optional config options
* @param cb Callback function
*/
export default function render(
template: string | TemplateFunction,
data: object,
config: PartialAsyncConfig,
cb: CallbackFn
): void

/**
* Render a template
*
* If `template` is a string, Eta will compile it to a function and then call it with the provided data.
* If `template` is a template function, Eta will call it with the provided data.
*
* If `config.async` is `false`, Eta will return the rendered template.
*
* If `config.async` is `true` and there's a callback function, Eta will call the callback with `(err, renderedTemplate)`.
* If `config.async` is `true` and there's not a callback function, Eta will return a Promise that resolves to the rendered template.
*
* If `config.cache` is `true` and `config` has a `name` or `filename` property, Eta will cache the template on the first render and use the cached template for all subsequent renders.
*
* @param template Template string or template function
* @param data Data to render the template with
* @param config Optional config options
*/
export default function render(
template: string | TemplateFunction,
data: object,
config: PartialAsyncConfig
): Promise<string>

/**
* Render a template
*
* If `template` is a string, Eta will compile it to a function and then call it with the provided data.
* If `template` is a template function, Eta will call it with the provided data.
*
* If `config.async` is `false`, Eta will return the rendered template.
*
* If `config.async` is `true` and there's a callback function, Eta will call the callback with `(err, renderedTemplate)`.
* If `config.async` is `true` and there's not a callback function, Eta will return a Promise that resolves to the rendered template.
*
* If `config.cache` is `true` and `config` has a `name` or `filename` property, Eta will cache the template on the first render and use the cached template for all subsequent renders.
*
* @param template Template string or template function
* @param data Data to render the template with
* @param config Optional config options
*/
export default function render(
template: string | TemplateFunction,
data: object,
config?: PartialConfig
): string

/**
* Render a template
*
* If `template` is a string, Eta will compile it to a function and then call it with the provided data.
* If `template` is a template function, Eta will call it with the provided data.
*
* If `config.async` is `false`, Eta will return the rendered template.
*
* If `config.async` is `true` and there's a callback function, Eta will call the callback with `(err, renderedTemplate)`.
* If `config.async` is `true` and there's not a callback function, Eta will return a Promise that resolves to the rendered template.
*
* If `config.cache` is `true` and `config` has a `name` or `filename` property, Eta will cache the template on the first render and use the cached template for all subsequent renders.
*
* @param template Template string or template function
* @param data Data to render the template with
* @param config Optional config options
* @param cb Callback function
*/
export default function render(
template: string | TemplateFunction,
data: object,
config?: PartialConfig,
cb?: CallbackFn
): string | Promise<string> | void

export default function render(
template: string | TemplateFunction,
@@ -84,6 +161,46 @@ export default function render(
}
}

/**
* Render a template asynchronously
*
* If `template` is a string, Eta will compile it to a function and call it with the provided data.
* If `template` is a function, Eta will call it with the provided data.
*
* If there is a callback function, Eta will call it with `(err, renderedTemplate)`.
* If there is not a callback function, Eta will return a Promise that resolves to the rendered template
*
* @param template Template string or template function
* @param data Data to render the template with
* @param config Optional config options
*/
export function renderAsync(
template: string | TemplateFunction,
data: object,
config?: PartialConfig
): Promise<string>

/**
* Render a template asynchronously
*
* If `template` is a string, Eta will compile it to a function and call it with the provided data.
* If `template` is a function, Eta will call it with the provided data.
*
* If there is a callback function, Eta will call it with `(err, renderedTemplate)`.
* If there is not a callback function, Eta will return a Promise that resolves to the rendered template
*
* @param template Template string or template function
* @param data Data to render the template with
* @param config Optional config options
* @param cb Callback function
*/
export function renderAsync(
template: string | TemplateFunction,
data: object,
config: PartialConfig,
cb: CallbackFn
): void

/**
* Render a template asynchronously
*
@@ -98,6 +215,12 @@ export default function render(
* @param config Optional config options
* @param cb Callback function
*/
export function renderAsync(
template: string | TemplateFunction,
data: object,
config?: PartialConfig,
cb?: CallbackFn
): string | Promise<string> | void

export function renderAsync(
template: string | TemplateFunction,