Comparing version 2.0.10-rc to 2.1.0-rc
{ | ||
"name": "etpl", | ||
"version": "2.0.10-rc", | ||
"version": "2.1.0-rc", | ||
"contributors": [ | ||
{ "name": "erik", "email": "errorrik@gmail.com" }, | ||
{ "name": "otakustay", "email": "otakustay@gmail.com" } | ||
{ "name": "otakustay", "email": "otakustay@gmail.com" }, | ||
{ "name": "firede", "email": "firede@firede.us" } | ||
], | ||
"main": "main", | ||
"homepage": "http://ecomfe.github.io/etpl/", | ||
"repository": "git://github.com/ecomfe/etpl" | ||
"repository": "git://github.com/ecomfe/etpl", | ||
"description": "ETPL是一个灵活、具有强大复用能力的高性能Javascript模板引擎,适用于WEB前端应用中视图的生成,特别是SPA(Single Page APP)类型的应用。", | ||
"scripts": { | ||
"test": "jasmine-node test/spec" | ||
}, | ||
"devDependencies": { | ||
"jasmine-node": "~1.14.2" | ||
} | ||
} |
# ETPL (Enterprise Template) | ||
[![Build Status](https://travis-ci.org/ecomfe/etpl.svg?branch=master)](https://travis-ci.org/ecomfe/etpl) | ||
ETPL是一个灵活、具有强大复用能力的高性能的模板引擎,适用于WEB前端应用中视图的生成,特别是SPA(Single Page APP)类型的应用。 | ||
@@ -106,4 +108,14 @@ | ||
如果仅仅编写的是一个模板片段,可以省略`target`的声明。这样的编写方式与其他模板引擎类似,但模板片段将不可复用(不可被import或use,不可指定母版)。 | ||
如果仅仅编写的是一个模板片段,可以省略`target`的声明。这样的编写方式与其他模板引擎类似,ETPL将默认生成匿名target,但模板片段将不可复用(不可被import或use,不可指定母版)。 | ||
匿名target应位于模板源码起始。下面例子中,位于其他target后的模板片段`Bye`将没有任何作用。 | ||
``` | ||
<!-- use: hello(name=${name}) --> | ||
<!-- target: hello --> | ||
Hello ${name}! | ||
<!-- /target --> | ||
Bye | ||
``` | ||
##### 语法 | ||
@@ -480,2 +492,4 @@ | ||
- `{string}`options.defaultFilter - 默认变量替换的filter,默认值为 *html* | ||
- `{boolean}`options.strip - 是否清除命令标签前后的空白字符,默认值为 *false* | ||
- `{string}`options.namingConflict - target或master名字冲突时的处理策略,值可以是`error` | `ignore` | `override`,分别代表`抛出错误`、`保留现有目标,忽略新目标`、`覆盖现有目标`。默认值为 *error* | ||
@@ -589,2 +603,4 @@ ```javascript | ||
- `{string}`options.defaultFilter - 默认变量替换的filter,默认值为 *html* | ||
- `{boolean}`options.strip - 是否清除命令标签前后的空白字符,默认值为 *false* | ||
- `{string}`options.namingConflict - target或master名字冲突时的处理策略,值可以是`error` | `ignore` | `override`,分别代表`抛出错误`、`保留现有目标,忽略新目标`、`覆盖现有目标`。默认值为 *error* | ||
@@ -591,0 +607,0 @@ ```javascript |
125
src/main.js
@@ -369,3 +369,3 @@ /** | ||
onInBlock( buf.join( '' ) ); | ||
text && onOutBlock( text ); | ||
onOutBlock( text ); | ||
buf = []; | ||
@@ -375,3 +375,3 @@ } | ||
else { | ||
onOutBlock( text ); | ||
text && onOutBlock( text ); | ||
} | ||
@@ -406,2 +406,8 @@ } | ||
getRendererBody: function () { | ||
if ( !this.value | ||
|| ( this.engine.options.strip && /^\s*$/.test( this.value ) ) | ||
) { | ||
return ''; | ||
} | ||
var defaultFilter = this.engine.options.defaultFilter; | ||
@@ -636,7 +642,2 @@ var code = []; | ||
Command.call( this, value, engine ); | ||
if ( engine.targets[ this.name ] ) { | ||
throw new Error( 'Target is exists: ' + this.name ); | ||
} | ||
this.contents = {}; | ||
@@ -664,7 +665,2 @@ } | ||
Command.call( this, value, engine ); | ||
if ( engine.masters[ this.name ] ) { | ||
throw new Error( 'Master is exists: ' + this.name ); | ||
} | ||
this.contents = {}; | ||
@@ -973,5 +969,3 @@ } | ||
var child = node.children[ i ]; | ||
if ( child instanceof ImportCommand | ||
|| child instanceof UseCommand | ||
) { | ||
if ( child instanceof ImportCommand ) { | ||
var target = engine.targets[ child.name ]; | ||
@@ -1051,18 +1045,42 @@ readyState = readyState | ||
/** | ||
* target节点open,解析开始 | ||
* 将target或master节点对象添加到语法分析环境中 | ||
* | ||
* @inner | ||
* @param {TargetCommand|MasterCommand} targetOrMaster target或master节点对象 | ||
* @param {Object} context 语法分析环境对象 | ||
*/ | ||
TargetCommand.prototype.open = function ( context ) { | ||
autoCloseCommand( context ); | ||
Command.prototype.open.call( this, context ); | ||
function addTargetOrMasterToContext( targetOrMaster, context ) { | ||
context.targetOrMaster = targetOrMaster; | ||
var name = this.name; | ||
context.targetOrMaster = this; | ||
this.state = TMNodeState.READING; | ||
context.engine.targets[ name ] = this; | ||
context.targets.push( name ); | ||
}; | ||
var engine = context.engine; | ||
var name = targetOrMaster.name; | ||
var isTarget = targetOrMaster instanceof TargetCommand; | ||
var prop = isTarget ? 'targets' : 'masters'; | ||
if ( engine[ prop ][ name ] ) { | ||
switch ( engine.options.namingConflict ) { | ||
case 'override': | ||
engine[ prop ][ name ] = targetOrMaster; | ||
isTarget && context.targets.push( name ); | ||
case 'ignore': | ||
break; | ||
default: | ||
throw new Error( ( isTarget ? 'Target' :'Master' ) | ||
+ ' is exists: ' + name ); | ||
} | ||
} | ||
else { | ||
engine[ prop ][ name ] = targetOrMaster; | ||
isTarget && context.targets.push( name ); | ||
} | ||
} | ||
/** | ||
* target节点open,解析开始 | ||
* | ||
* @param {Object} context 语法分析环境对象 | ||
*/ | ||
TargetCommand.prototype.open = | ||
/** | ||
* master节点open,解析开始 | ||
@@ -1075,7 +1093,4 @@ * | ||
Command.prototype.open.call( this, context ); | ||
var name = this.name; | ||
context.targetOrMaster = this; | ||
this.state = TMNodeState.READING; | ||
context.engine.masters[ name ] = this; | ||
addTargetOrMasterToContext( this, context ); | ||
}; | ||
@@ -1453,2 +1468,4 @@ | ||
* @param {string=} options.defaultFilter 默认变量替换的filter | ||
* @param {boolean=} options.strip 是否清除命令标签前后的空白字符 | ||
* @param {string=} options.namingConflict target或master名字冲突时的处理策略 | ||
*/ | ||
@@ -1475,2 +1492,4 @@ function Engine( options ) { | ||
* @param {string=} options.defaultFilter 默认变量替换的filter | ||
* @param {boolean=} options.strip 是否清除命令标签前后的空白字符 | ||
* @param {string=} options.namingConflict target或master名字冲突时的处理策略 | ||
*/ | ||
@@ -1497,6 +1516,10 @@ Engine.prototype.config = function ( options ) { | ||
Engine.prototype.parse = function ( source ) { | ||
var targetNames = parseSource( source, this ); | ||
if ( targetNames.length ) { | ||
return this.targets[ targetNames[ 0 ] ].getRenderer(); | ||
if ( source ) { | ||
var targetNames = parseSource( source, this ); | ||
if ( targetNames.length ) { | ||
return this.targets[ targetNames[ 0 ] ].getRenderer(); | ||
} | ||
} | ||
return new Function('return ""'); | ||
}; | ||
@@ -1590,10 +1613,16 @@ | ||
function flushTextBuf() { | ||
var len = textBuf.length; | ||
var text; | ||
if ( len > 0 && (text = textBuf.join( '' )) !== '' ) { | ||
if ( textBuf.length > 0 ) { | ||
var text = textBuf.join( '' ); | ||
var textNode = new TextNode( text, engine ); | ||
textNode.beforeAdd( analyseContext ); | ||
stack.top().addTextNode( textNode ); | ||
textBuf = []; | ||
if ( engine.options.strip | ||
&& analyseContext.current instanceof Command | ||
) { | ||
textNode.value = text.replace( /^[\x20\t\r]*\n/, '' ); | ||
} | ||
analyseContext.current = textNode; | ||
} | ||
@@ -1630,16 +1659,22 @@ } | ||
flushTextBuf(); | ||
var currentNode = analyseContext.current; | ||
if ( engine.options.strip && currentNode instanceof TextNode ) { | ||
currentNode.value = currentNode.value | ||
.replace( /\r?\n[\x20\t]*$/, '\n' ); | ||
} | ||
if ( match[1] ) { | ||
var closeNode = stack.find( | ||
isInstanceofNodeType | ||
); | ||
closeNode && closeNode.close( analyseContext ); | ||
currentNode = stack.find( isInstanceofNodeType ); | ||
currentNode && currentNode.close( analyseContext ); | ||
} | ||
else { | ||
var openNode = new NodeType( match[4], engine ); | ||
if ( typeof openNode.beforeOpen == 'function' ) { | ||
openNode.beforeOpen( analyseContext ); | ||
currentNode = new NodeType( match[4], engine ); | ||
if ( typeof currentNode.beforeOpen == 'function' ) { | ||
currentNode.beforeOpen( analyseContext ); | ||
} | ||
openNode.open( analyseContext ); | ||
currentNode.open( analyseContext ); | ||
} | ||
analyseContext.current = currentNode; | ||
} | ||
@@ -1646,0 +1681,0 @@ else if ( !/^\s*\/\//.test( text ) ) { |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 2 instances in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Mixed license
License(Experimental) Package contains multiple licenses.
Found 1 instance in 1 package
0
672
1
2
70327
1
8
1552