How to use the velocityjs.render function in velocityjs

To help you get started, we’ve selected a few velocityjs examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jdf2e / jdf / lib / vm.js View on Github external
}
            }
            // 递归解析
            content += vm.render(vmVfile.targetContent, {
                dataObj: dataObj,
                dirname: path.dirname(vmpath),
                existMap: existMap
            });

            content += ``;

            return content;
        }
    }

    return  velocity.render(vmSource, dataObj, macros);
}
github Testlio / lambda-tools / lib / helpers / api-gateway-mapping-parser.js View on Github external
if (params.querystring && !_.isUndefined(params.querystring[key])) {
                    return params.querystring[key];
                }

                if (params.header && !_.isUndefined(params.header[key])) {
                    return params.header[key];
                }

                return null;
            }
        }
    };

    // Always keep macros empty, API gateway doesn't support those
    const result = velocity.render(template, data, {});
    return _.unescape(result);
};
github gnemtsov / ab-app2 / backend / appsync-local.js View on Github external
resolvers[typeName][fieldName] = async (root, args, context) => {
                const d = new Date();
                console.log(
                    `Resolver`,
                    chalk.black.bgBlue(fieldName),
                    `executed at ${d.toLocaleTimeString()}`
                );

                console.log("Rendering velocity template...");
                let template = velocity.render(requestMappingTemplate, {
                    context: {
                        arguments: JSON.stringify(args),
                        request: {
                            headers: JSON.stringify(context.request.headers)
                        },
                        identity: JSON.stringify(context.identity)
                    }
                });
                template = JSON.parse(template);
                const payload = JSON.parse(JSON.stringify(template.payload));

                if (!options.quiet) {
                    const headers = template.payload.headers;
                    if (headers !== undefined && headers !== null) {
                        Object.keys(headers).map(function(key, index) {
                            headers[key] =
github ConduitVC / aws-utils / packages / appsync-emulator-serverless / vtl.js View on Github external
const vtl = (str, context, macros = {}) => {
  log.info('render\n', str);
  const output = velocity.render(str, context, macros, {
    valueMapper: javaify,
  });
  log.info('render output\n', output);
  return output;
};
github hangyangws / demos / src / alipay_node / app.js View on Github external
app.engine('html', function(path, options, fn) {
    var template = fs.readFileSync(path).toString(),
        macros = {
            parse: function(file) {
                var template = fs.readFileSync(process.cwd() + '/views/' + file).toString();
                return this.eval(template);
            }
        };
    try {
        fn(null, velocity.render(template, options, macros));
    } catch (err) {
        fn(err)
    }
});

velocityjs

Velocity Template Language(VTL) for JavaScript

MIT
Latest version published 2 years ago

Package Health Score

65 / 100
Full package analysis