Giter VIP home page Giter VIP logo

velocity's People

Contributors

antife-yinyue avatar dead-horse avatar fengmk2 avatar fool2fish avatar npmmirror avatar shaoshuai0102 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

velocity's Issues

velocity-config require问题

我想通过gulp的watch方法,发现vm或者context有改变时,重新渲染vm,实现自动化;
但是context是require进来的,改变后也没法获取到。
是否可以改变下这块的逻辑?

缩进换行问题

判断语句或者macro方法执行后,输出的内容会有多余的换行或者缩进,这不是我想要的,有什么办法能去掉吗?
IMG

Extract data structure from template

Reference

input:

$a
$b
$b.c[0]
$b.c[$d].e
$f.h($a).i
       ^ return of method won't go further

output:

{
  a: '',
  b: {
    c:[{e: ''}]
  },
  f: {
    h: function(){}
  }
}

Method look up

input:

$a.length()
$b.size()
$c.keySet()
$c.d

output:

{
  a: '',
  b: [],
  c: {d: ''}
}

#set

input:

#set($a = 1)
#set($b = $c.d)
$b.e

ouput:

module.exports = {
  c: {
    d: {
      e: ''
    }
  }
}

#foreach

input:

#foreach($employee in $employeeList)
$foreach.index: $employee.name - $employee.email
#end

ouput:

{
  employeeList: [
    {
      name: '',
      email: ''
    }
  ]
}

#parse

input:

## file a.vm
#parse('path/to/b.vm')

## file b.vm
$a

output:

{
  a: ''
}

#define

input:

#define($userInfo)
$user.name
$user.email
#end
$userInfo

output:

{
  user: {
    name: '',
    email: ''
  }
}

#macro

input:

#macro(hello $user)
Welcome, $user.name !
#end
#hello($employee)

output:

module.exports = {
    employee: {
      name: ''
    }
}

Cases need to note

#set($f = {$g: $h})
$f[$g].i             // any property of $f won't be handled
#set($j = [$k])
$j[0].l              // any property of $j won't be handled

#foreach not support object

when I was testing the #foreach, I found that #foreach not support object as input parameter, but according the velocity user guid -- Foreach Loop,"The contents of the $allProducts variable is a Vector, a Hashtable or an Array".

if #foreach not support the object as input parameter, we can not simulate data like "map" in context.js, eg.

#foreach( $key in $allProducts.keySet() )
    <li>Key: $key -> Value: $allProducts.get($key)</li>
#end 

is this a bug?

vm npm package

I stumbled across this because someone on my team seems to have (accidentally) installed the 'vm' package which is here: https://www.npmjs.com/package/vm

It redirects to this github repo but it appears to be basically dead, and the bin file is simply console.log('Place holder').

Should it be taken down from npm?

$ cd hello

应该是 $ cd examples 然后才是 $ cd hello

null变量引用

js 中 a 变量为null

在模板中使用

$!a

正确的方式是输出空,但是实际输出了 null

undefined的处理没问题

Support varargs

Length of params not must be equal with the length of arguments.

define变量的引用问题

below is library.vm:

#macro(render $subchannel)
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style tyle="text/css">
    ## 页面css
    $!q_css
</style>
</head>
<body>
    ## 页面html
    $!q_body
    ## 页面js
    $!q_js
</body>
</html>
#end
{code}

below is index.vm:

#define( $q_css )
body{background:green;}
#end

#define( $q_body )
hello word!
#end

#define( $q_js )
<script>
    var nimei = "nimei";
</script>
#end

#render('hotel')

在java里,render index.vm能输出$q_js,$q_css,$q_body,这样也是比较合理的

在engine-ref.js里

   Reference: function(node) {
    // call define
    if (common.isId(node)) {
      var name = node.object.name
      if (name in this.template.__define) {
        var def = this.template.__define[name]
        var result = this[def.type](def)
        if (result.stats !== STATS.SUCCESS) {
          // at where the #define is called
          result.stack.push(common.getRealLoc([this.template, node.pos]))
        }
        return result
      }
    }

是不是做成 return this.template._define[xxx] <- this.template.__parent.__define这样逐层查找比较合理,且和java更加吻合

不支持相对路径的引入吗?

比如

template/vm
├── inc.vm
└── index.vm

在index.vm中

#parse("./inc.vm")

提示

#parse("inc.vm")
       ^^^^^^^^
Error: Param of #parse not exists or is not subpath of root.
    at /Users/leeluolee/code/wdp/test/template/vm/index.vm (16:7)

必须传入root参数?

set语句中出现expr&&expr==expr时报错

#set($isInsuDisable = $!{appointmentVO.oldMan}&&$!{$productXTypeChild.productXTypeCode}=='INSU')
Error: Lexical error on line 19. Unrecognized text.
...ointmentVO.oldMan}&&$!{$productXTypeChil
-----------------------^

lex改不来……这工具不熟悉……

Convert object to string

require('util').inspect won't output the proper string of function when writes a object to a file.

Reduce return value of calls on method from template

Expand existing context

Context

{
  method: {
    // defined by hand
    foo: function() { return true },

    // definition reduced from template
    bar: function() { return this.__barReturn },
    __barReturn: true
  }
}

Intermediate code

{
  method: {
    __stats: CERTAIN,
    __value: {
      foo: {
        __stats: CERTAIN_FUNC,
        __value: function() {return true}
      },
      bar: {
        __stats: CERTAIN_FUNC,
        __return: {
          __stats: CERTAIN,
          __value: true
        },
        argc: 0
      }
    }
  }
}

Calls on method

Input

$method.foo($arg).bar().prop

Intermediate code

{
  method: {
    __stats: CERTAIN,
    __value: {
      foo: {
        __stats: CERTAIN_FUNC,
        __argc: 1,
        __return: {
          __stats: CERTAIN,
          __value: {
            bar: {
              __stats: CERTAIN_FUNC,
              __argc: 0,
              __return: {
                prop: {
                  __stats: UNCERTAIN
                }
              }
            }
          }
        }
      }
    }
  }
}

Output

{
  method: {
    foo: function(a) { return this.__fooReturn },
    __fooReturn: {
      bar: function() { return this.__barReturn },
      __barReturn: {
        prop: ''
      }
    }
  }
}

when #set encounters an undefined reference,result is strange

the code:

================test begin======
#set($foo="abc")
#set($id=1)
#set($bar="${foo}${id}")
#set($dar_1="${goo}${id}")
#set($dar_2="$!{goo}${id}")

##goo is undefined
output goo: $goo

output bar:$bar
output dar_1:$dar_1
output dar_2:$dar_2


================test end======

the render result:
image

the $dar_1 render result is not "$goo1", instead it is strange string of this template file begin contents "======1".

is this a bug?

.

解析并调用一个 非全局的 macro

问题描述:
有两个模版文件 a.vm 和 b.vm, 前者定义了一个 macro ,后者通过 parse 指令解析前者并调用其定义的 macro


在 java 版中这样做是可以的,node 版会报 macro 未定义的错误

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.