How to use the velocityjs.Parser 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 shepherdwind / plum / hooks / webx / webx.js View on Github external
jsonify: function(vm){

    var vmLayout = this._getLayoutString();
    vm = vmLayout.replace(/\$screen_placeholder/, vm);
    vm = this.globalMacros + vm;

    var context = {
      control: this.tools.control
    };

    var asts = Velocity.Parser.parse(vm);
    var jsonify = new Velocity.Jsonify(asts, context);
    return (jsonify.toVTL());

  },
github shepherdwind / plum / hooks / webx / webx.js View on Github external
parse: function(){

    var filePath = this.get('filePath');
    var vm = Iconv.decode(fs.readFileSync(filePath), 'gbk');
    var str = '';
    var isParse = this.get('isParse');
    var isJsonify = this.get('isJsonify');
    var file = this.get('file').replace('.htm', '.js');
    var context = this.getContext(file);
    var basePath = this.get('basePath');

    try {

      var html = Velocity.Parser.parse(vm);

      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;
github shepherdwind / plum / hooks / velocity.js View on Github external
var url = URL.parse(request.url, true);
    var isParse = '__parse' in url.query;

    //接受处理
    this.fire('receive', {file: file, index: i});
    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 3 years ago

Package Health Score

56 / 100
Full package analysis