-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
2,240 additions
and
107 deletions.
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"LICENSE": "5c597a93416a6b2fd475a4b6a5ae567f", | ||
"README.md": "112e5f8aef658636f95f3829c0438d7a", | ||
"doc/api.md": "3f730a37c3a97efe68b40981ae095d2b", | ||
"doc/config.md": "8ebb6ec1a5d1a7c006ec7ac0371278d9", | ||
"doc/syntax.md": "3c25984820a384c9149163f49846980b", | ||
"main.js": "5c131f6789741ceba9117a95552d2918", | ||
"package.json": "a0ec59a0969ab0b8baf493c5143689ac", | ||
"src/main.js": "41a67fe16af3251b578f1bd0bd3f0b3b", | ||
"src/tpl.js": "012520cf5f6e01fba5293ef27106b3ea" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
root = true | ||
|
||
[*] | ||
end_of_line = lf | ||
charset = utf-8 | ||
trim_trailing_whitespace = true | ||
insert_final_newline = true | ||
|
||
[**.js] | ||
indent_style = space | ||
indent_size = 4 | ||
|
||
[**.css] | ||
indent_style = space | ||
indent_size = 4 | ||
|
||
[**.less] | ||
indent_style = space | ||
indent_size = 4 | ||
|
||
[**.styl] | ||
indent_style = space | ||
indent_size = 4 | ||
|
||
[**.html] | ||
indent_style = space | ||
indent_size = 4 | ||
|
||
[**.tpl] | ||
indent_style = space | ||
indent_size = 4 | ||
|
||
[**.json] | ||
indent_style = space | ||
indent_size = 4 | ||
|
||
[*.md] | ||
trim_trailing_whitespace = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
language: node_js | ||
node_js: | ||
- 0.10 | ||
branches: | ||
only: | ||
- master |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
Copyright (c) 2013, Baidu Inc. | ||
All rights reserved. | ||
|
||
Redistribution and use of this software in source and binary forms, with or | ||
without modification, are permitted provided that the following conditions | ||
are met: | ||
|
||
Redistributions of source code must retain the above copyright notice, this | ||
list of conditions and the following disclaimer. | ||
|
||
Redistributions in binary form must reproduce the above copyright notice, | ||
this list of conditions and the following disclaimer in the documentation | ||
and/or other materials provided with the distribution. | ||
|
||
Neither the name of Baidu Inc. nor the names of its contributors may be used | ||
to endorse or promote products derived from this software without specific | ||
prior written permission of Baidu Inc. | ||
|
||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR | ||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON | ||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
# ETPL (Enterprise Template) | ||
|
||
[![Build Status](https://travis-ci.org/ecomfe/etpl.svg?branch=master)](https://travis-ci.org/ecomfe/etpl) | ||
|
||
ETPL是一个强复用、灵活、高性能的JavaScript模板引擎,适用于浏览器端或Node环境中视图的生成。 | ||
|
||
|
||
## Start | ||
|
||
ETpl可以在`CommonJS/AMD`的模块定义环境中使用,也能直接在页面下通过`script`标签引用。 | ||
|
||
|
||
### 浏览器环境 | ||
|
||
直接通过script标签引用,你可以获得一个全局的`etpl`变量 | ||
|
||
```html | ||
<script src="etpl.js"></script> | ||
``` | ||
|
||
在AMD环境的模块定义时,你可以通过`同步require`获得ETpl模块 | ||
|
||
```javascript | ||
define(function (require) { | ||
var etpl = require('etpl'); | ||
}); | ||
``` | ||
|
||
在AMD环境,你也可以通过`异步require`获得ETpl模块 | ||
|
||
```javascript | ||
require([ 'etpl' ], function (etpl) { | ||
}); | ||
``` | ||
|
||
*在AMD环境下,请确保你的require.config配置能够让Loader找到ETpl模块* | ||
|
||
### Node.JS环境 | ||
|
||
你可以通过`npm`来安装ETpl | ||
|
||
``` | ||
$ npm install etpl | ||
``` | ||
|
||
安装完成后,你就可以通过`require`获得一个ETpl模块,正常地使用它 | ||
|
||
```javascript | ||
var etpl = require('etpl'); | ||
``` | ||
|
||
### 使用 | ||
|
||
使用ETPL模块,对模板源代码进行编译,会能得到编译后的function | ||
|
||
```javascript | ||
var render = etpl.compile('Hello ${name}!'); | ||
``` | ||
|
||
执行这个function,传入数据对象,就能得到模板执行的结果了 | ||
|
||
```javascript | ||
var text = render({ name: 'etpl' }); | ||
``` | ||
|
||
查看更多例子,或者对模板渲染结果有疑虑,就去ETPL的[example](http://ecomfe.github.io/etpl/example.html)看看吧。 | ||
|
||
|
||
## Documents | ||
|
||
通过文档,你可以更详细地了解ETpl的语法格式、使用方法、API等内容。 | ||
|
||
- [模板语法](doc/syntax.md) | ||
- [API](doc/api.md) | ||
- [配置参数](doc/config.md) | ||
|
||
|
||
## Compatibility | ||
|
||
### ETpl3的新语法 | ||
|
||
我们认为,当前流行的通过`block`来表达模板继承中的变化,是更好的表达方式。所以在ETpl3中,我们优化了母版的语法,删除了`master`、`contentplacehoder`、`content`标签,引入了`block`标签。 | ||
|
||
对于ETpl2的使用者,我们提供一个[etpl2to3](https://github.com/ecomfe/etpl2to3)工具,能够帮助你平滑地将ETpl2的模板翻译成ETpl3。 | ||
|
||
|
||
### get | ||
|
||
ETpl2中,为了前向兼容,Engine的`get`方法可以根据target名称获取模板内容。 | ||
|
||
ETpl3不再支持该方法,所有的模板都通过render来使用: | ||
|
||
- 直接使用engine实例的render方法 | ||
- 调用renderer function | ||
|
||
如果仍需要该功能,说明你正在维护一个遗留系统,并且没有很频繁的升级需求。请继续使用ETpl2。 | ||
|
||
|
||
### merge | ||
|
||
ETpl的前身是[ER框架](https://github.com/ecomfe/er)自带的简易模板引擎,其基本与前身保持兼容。但出于代码体积和使用频度的考虑,ETpl删除了`merge`API。如果想要该API,请在自己的应用中加入如下代码: | ||
|
||
```javascript | ||
/** | ||
* 执行模板渲染,并将渲染后的字符串作为innerHTML填充到HTML元素中。 | ||
* 兼容老版本的模板引擎api | ||
* | ||
* @param {HTMLElement} element 渲染字符串填充的HTML元素 | ||
* @param {string} name target名称 | ||
* @param {Object=} data 模板数据 | ||
*/ | ||
etpl.merge = function ( element, name, data ) { | ||
if ( element ) { | ||
element.innerHTML = this.render( name, data ); | ||
} | ||
}; | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/** | ||
* ETPL (Enterprise Template) | ||
* Copyright 2013 Baidu Inc. All rights reserved. | ||
* | ||
* @file Node入口 | ||
* @author firede([email protected]) | ||
*/ | ||
|
||
module.exports = require('./src/main'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"name": "etpl", | ||
"version": "3.0.0", | ||
"contributors": [ | ||
{ "name": "erik", "email": "[email protected]" }, | ||
{ "name": "otakustay", "email": "[email protected]" }, | ||
{ "name": "firede", "email": "[email protected]" } | ||
], | ||
"main": "main", | ||
"homepage": "http://ecomfe.github.io/etpl/", | ||
"repository": "git://github.com/ecomfe/etpl", | ||
"description": "ETPL是一个强复用、灵活、高性能的JavaScript模板引擎,适用于浏览器端或Node环境中视图的生成。", | ||
"scripts": { | ||
"test": "jasmine-node test/spec" | ||
}, | ||
"devDependencies": { | ||
"jasmine-node": "1.14.2" | ||
} | ||
} |
Oops, something went wrong.