How to use velocityjs - 10 common examples

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 dherault / serverless-offline / src / events / http / lambda-events / renderVelocityTemplateObject.js View on Github external
const renderResult = runInPollutedScope(() =>
    // This line can throw, but this function does not handle errors
    // Quick args explanation:
    // { escape: false } --> otherwise would escape &, < and > chars with html (&, < and >)
    // render(context, null, true) --> null: no custom macros; true: silent mode, just like APIG
    new Compile(parse(velocityString), { escape: false }).render(
      context,
      null,
      true,
    ),
  )
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 syndesisio / syndesis / app / ui-react / packages / ui / src / Shared / TextEditor / velocity-lint.ts View on Github external
public parse(content: string): TemplateSymbol[] {
    const symbols: TemplateSymbol[] = [];
    const tokens: any[] = Velocity.parse(content);
    for (const token of tokens) {
      if (token.type === 'references') {
        symbols.push(new TemplateSymbol(token.id, 'string'));
      }
    }
    return symbols;
  }
github syndesisio / syndesis / app / ui-react / packages / ui / src / Shared / TextEditor / velocity-lint.ts View on Github external
protected validate(text: string, errors: any[]): void {
    try {
      const tokens: any[] = Velocity.parse(text);
      let totalSymbols = 0;
      for (const token of tokens) {
        if (token.type === 'references') {
          totalSymbols++;
        }
      }

      if (totalSymbols === 0) {
        const msg = 'linter-no-symbols';
        errors.push({
          from: CodeMirror.Pos(0, 0),
          message: msg,
          severity: 'warning',
          to: CodeMirror.Pos(0, 0),
        });
      }
github aws-amplify / amplify-cli / packages / amplify-velocity-template / examples / app.js View on Github external
import { parse, Compile } from 'velocityjs';

const asts = parse(document.querySelector('#tmpl').innerHTML);
const data = {
  items: [{ a: '1' }, { a: 'successed' }],
};
const s = new Compile(asts).render(data);

document.querySelector('.foo').innerHTML = s;
github aws-amplify / amplify-cli / packages / amplify-velocity-template / examples / app.js View on Github external
import { parse, Compile } from 'velocityjs';

const asts = parse(document.querySelector('#tmpl').innerHTML);
const data = {
  items: [{ a: '1' }, { a: 'successed' }],
};
const s = new Compile(asts).render(data);

document.querySelector('.foo').innerHTML = s;
github shepherdwind / plum / hooks / webx / webx.js View on Github external
if (isParse) {

        str = JSON.stringify(html, false, 2);

      } else if (isJsonify) {

        str = this.jsonify(vm);

      } else {

        for(var i in this.tools)
          context[i] = this.tools[i];
        //context = utils.mixin(context, this.tools);

        var macros = this.globalMacros;
        var vmrun = new Velocity.Compile(html);
        vmrun.addIgnoreEscpape(['control', 'securityUtil', 'tbToken', 'stringEscapeUtil', 'enhanceToken'])
        str = vmrun.render(context, getMacros(macros, this.get('basePath')));

        var layout = this.layout(vmrun.context);
        str = layout.replace(/\$screen_placeholder/, str);
        this.tools.reset();

      }

      return Iconv.encode(str, 'gbk');
    } catch(e) {
      throw e;
    }
  },
github shepherdwind / plum / hooks / webx / webx.js View on Github external
layout: function(context){

    var vm = this._getLayoutString();
    var macros = this.globalMacros;
    var html = Velocity.Parser.parse(vm);

    var vmrun = new Velocity.Compile(html);
    vmrun.addIgnoreEscpape(['control', 'securityUtil', 'tbToken', 'stringEscapeUtil', 'enhanceToken'])
    var str = vmrun.render(context, getMacros(macros, this.get('basePath')));
    return str;

  }

velocityjs

Velocity Template Language(VTL) for JavaScript

MIT
Latest version published 3 years ago

Package Health Score

68 / 100
Full package analysis