Giter Site home page Giter Site logo

velocity.js's Introduction

Velocity - Template Engine

Build Status Coverage Status

NPM

velocity.js是velocity模板语法的javascript实现。

##Features

  • 支持客户端和服务器端使用
  • 语法分析和模板渲染分离
  • 基本完全支持velocity语法
  • Vim Syntax

##Install

via npm:

$ npm install velocityjs

##Broswer

兼容支持es5的浏览器,可以通过测试来验证test case

对于低端浏览器需要实现以下方法

  1. Array.prototype的map, forEach, some, filter, every, indexOf
  2. Date.now
  3. Object.keys

##Examples

在tests目录下有大量的例子,node和浏览器下使用是一致的,另外,examples目录下有一个 最简单的例子。

##Public API

文件组织通过CommonJS方式,对于浏览器,通过spm可以打包为cmd模块。

var Velocity = require('velocityjs');

//1. 直接解析
Velocity.render('string of velocity', context, macros);

//2. 使用Parser和Compile
var Parser = Velocity.Parser;
var Compile = Velocity.Compile;

var asts = Parser.parse('string of velocity');
(new Compile(asts)).render(context, macros);

####context

context是一个对象,可以为空,执行中$foo.bar,访问路径是context.foo.barcontext的属性可以是函数,和vm中定义保持一致。

context中得函数,有一个固定的eval方法,可以用来运算vm语法字符串,比如webx对应的 $control.setTemplate实现

##Syntax

具体语法请访问官网文档:velocity user guide

###Directives

Directives支持set, foreach, if|else|elseif, macro, break。不 支持有,stop, evaluate, define, parse。不过可以通过context来实现,比如 parse 实现

###macro与parse

宏分为系统的宏,比如parse, include,和用户自定义宏,通过#macro在vm中定义,此 外可以使用自定义的js函数替代在vm中定义。对于系统宏和自定义宏,不做区分,对于 #parse#include的调用,可以使用自定义函数来执行,可以参考测试用例中self defined macro部分。

##Questions

提问有几种方式

  1. 新建issue
  2. 邮件到eward.song at gmail.com
  3. 阿里内部员工,可以通过hanwen.sah搜到我的旺旺

其他

推荐一下沉鱼写的velocity

##License

(The MIT License)

velocity.js's People

Contributors

shepherdwind avatar jamescookie avatar cabumtz avatar popomore avatar

Watchers

James Cloos avatar  avatar  avatar

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.