mirror of
https://github.com/Kong/insomnia
synced 2024-11-07 22:30:15 +00:00
Added flow to templating index
This commit is contained in:
parent
01e10138ee
commit
0902aa6ef9
@ -1,7 +1,23 @@
|
||||
// @flow
|
||||
import nunjucks from 'nunjucks';
|
||||
import * as extensions from './extensions';
|
||||
import BaseExtension from './base-extension';
|
||||
|
||||
export class RenderError extends Error {
|
||||
message: string;
|
||||
path: string | null;
|
||||
location: {line: number, column: number};
|
||||
type: string;
|
||||
reason: string;
|
||||
}
|
||||
|
||||
export type NunjucksTag = {
|
||||
name: string,
|
||||
displayName: string,
|
||||
description: string,
|
||||
args: Array<Object>
|
||||
};
|
||||
|
||||
// Some constants
|
||||
export const RENDER_ALL = 'all';
|
||||
export const RENDER_VARS = 'variables';
|
||||
@ -20,7 +36,7 @@ let nunjucksAll = null;
|
||||
* @param {Object} [config.path] - Path to include in the error message
|
||||
* @param {Object} [config.renderMode] - Only render variables (not tags)
|
||||
*/
|
||||
export function render (text, config = {}) {
|
||||
export function render (text: string, config: Object = {}): Promise<string> {
|
||||
const context = config.context || {};
|
||||
const path = config.path || null;
|
||||
const renderMode = config.renderMode || RENDER_ALL;
|
||||
@ -43,7 +59,7 @@ export function render (text, config = {}) {
|
||||
? 'undefined'
|
||||
: 'error';
|
||||
|
||||
const newError = new Error(sanitizedMsg);
|
||||
const newError = new RenderError(sanitizedMsg);
|
||||
newError.path = path || null;
|
||||
newError.message = sanitizedMsg;
|
||||
newError.location = {line, column};
|
||||
@ -60,7 +76,7 @@ export function render (text, config = {}) {
|
||||
/**
|
||||
* Reload Nunjucks environments. Useful for if plugins change.
|
||||
*/
|
||||
export function reload () {
|
||||
export function reload (): void {
|
||||
nunjucksAll = null;
|
||||
nunjucksVariablesOnly = null;
|
||||
nunjucksTagsOnly = null;
|
||||
|
25
flow-typed/nunjucks.js
vendored
Normal file
25
flow-typed/nunjucks.js
vendored
Normal file
@ -0,0 +1,25 @@
|
||||
declare class Nunjucks<T> {
|
||||
extensions: {[string]: T},
|
||||
addExtension: (name: string, ext: T) => void,
|
||||
addFilter: (name: string, ext: Function) => void,
|
||||
renderString: (text: string, context: Object, callback: Function) => void
|
||||
}
|
||||
|
||||
declare type Config = {
|
||||
autoescape: boolean,
|
||||
throwOnUndefined: boolean,
|
||||
tags: {
|
||||
blockStart: string,
|
||||
blockEnd: string,
|
||||
variableStart: string,
|
||||
variableEnd: string,
|
||||
commentStart: string,
|
||||
commentEnd: string
|
||||
}
|
||||
};
|
||||
|
||||
declare module 'nunjucks' {
|
||||
declare module.exports: {
|
||||
configure: <T>(config: Config) => Nunjucks<T>
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user