How to use the velocityjs.Compile 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 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 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;

  }
github shepherdwind / plum / hooks / velocity.js View on Github external
this._add();

    var dataFile = path.dirname(filePath) + '/.data/' + path.basename(filePath);
    var data = {};
    if (fs.existsSync(dataFile)) {
      data = JSON.parse(fs.readFileSync(dataFile).toString());
    }

    var vm = fs.readFileSync(filePath).toString();
    try {
      var html = Velocity.Parser.parse(vm);
      if (isParse) {
        this.fire('set:header', {type: '.json'});
        var str = JSON.stringify(html, false, 2);
      } else {
        str = new Velocity.Compile(html).render(data);
      }

      this.fire('end', {index: i, data: str});
    } catch(e) {
      this.fire('end', {index: i, data: '<pre>' + e.toString()});
      throw e;
    }
  }
</pre>

velocityjs

Velocity Template Language(VTL) for JavaScript

MIT
Latest version published 2 years ago

Package Health Score

65 / 100
Full package analysis