-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
57 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,5 +6,6 @@ coverage | |
coverage.info | ||
test/fixtures/*/build | ||
node_modules | ||
lib | ||
!lib/*.d.ts | ||
lib/*.map | ||
lib/*.cjs | ||
lib/*.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { Plugin } from 'metalsmith'; | ||
export default initializeInPlace; | ||
export type Render = (source: string, options: any, locals: any) => string; | ||
export type RenderAsync = (source: string, options: any, locals: any, callback: Function) => Promise<string>; | ||
export type Compile = (source: string, options: any) => string; | ||
export type CompileAsync = (source: string, options: any, callback: Function) => Promise<string>; | ||
export type JsTransformer = { | ||
name: string; | ||
inputFormats: string[]; | ||
outputFormat: string; | ||
render?: Render; | ||
renderAsync?: RenderAsync; | ||
compile?: Compile; | ||
compileAsync?: CompileAsync; | ||
[key]?: string; | ||
}; | ||
export type Options = { | ||
/** | ||
* Jstransformer to run: name of a node module or local JS module path (starting with `.`) whose default export is a jstransformer. As a shorthand for existing transformers you can remove the `jstransformer-` prefix: `marked` will be understood as `jstransformer-marked`. Or an actual jstransformer; an object with `name`, `inputFormats`,`outputFormat`, and at least one of the render methods `render`, `renderAsync`, `compile` or `compileAsync` described in the [jstransformer API docs](https://github.com/jstransformers/jstransformer#api) | ||
*/ | ||
transform: string | JsTransformer; | ||
/** | ||
* One or more paths or glob patterns to limit the scope of the transform. | ||
* @default '**\/*.<transform.inputFormats>' | ||
*/ | ||
pattern?: string|string[]; | ||
/** | ||
* Pass options to the jstransformer templating engine that's rendering your files. | ||
* @default {} | ||
*/ | ||
engineOptions?: any; | ||
}; | ||
/** | ||
* A metalsmith plugin for in-place templating | ||
* @example | ||
* import nunjucks from 'jstransformer-nunjucks' | ||
* | ||
* metalsmith | ||
* .use(inPlace({ transform: 'jstransformer-nunjucks' })) // use jstransformer-nunjucks | ||
* .use(inPlace({ transform: 'nunjucks' })) // shorthand for above | ||
* .use(inPlace({ transform: nunjucks })) // equivalent to above | ||
* .use(inPlace({ transform: './local/transform.js' })) // custom local transformer | ||
* .use(inPlace({ transform: { // custom inline transformer | ||
* name: 'prepend-hello', | ||
* inputFormats: ['prepend-hello'], | ||
* outputFormat: 'html', | ||
* render(str, options, locals) => { | ||
* return 'hello ' + str | ||
* } | ||
* }})) | ||
*/ | ||
declare function initializeInPlace(options?: Options): Plugin; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters