zpin-templates
Advanced tools
Comparing version 0.0.32 to 0.0.33
@@ -29,3 +29,3 @@ 'use strict'; | ||
var propsMergeFunction = 'function mergeProps(inline,external) {\n var res = _.assign({},inline,external)\n if (inline.hasOwnProperty(\'style\')) {\n res.style = _.defaults(res.style, inline.style);\n }\n if (inline.hasOwnProperty(\'className\') && external.hasOwnProperty(\'className\')) {\n res.className = external.className + \' \' + inline.className;\n }\n return res;\n}\n'; | ||
//2016.11.22 rt-class别名转换bug | ||
//2016.11.22 zp-class别名转换bug | ||
var classSetTemplate = _.template('_(<%= classSet %>).transform(function(res, value, key){ if(value){ res.push(this.styles[key]);} }.bind(this), []).join(" ")'); | ||
@@ -44,16 +44,16 @@ // const classSetTemplate = _.template('_(<%= classSet %>).transform(function(res, value, key){ if(value){ res.push(key);} }.bind(this), []).join(" ")'); | ||
var repeatAttr = 'rt-repeat'; | ||
var ifAttr = 'rt-if'; | ||
var classSetAttr = 'rt-class'; | ||
var repeatAttr = 'zp-repeat'; | ||
var ifAttr = 'zp-if'; | ||
var classSetAttr = 'zp-class'; | ||
var classAttr = 'class'; | ||
var scopeAttr = 'rt-scope'; | ||
var propsAttr = 'rt-props'; | ||
var templateNode = 'rt-template'; | ||
var virtualNode = 'rt-virtual'; | ||
var includeNode = 'rt-include'; | ||
var scopeAttr = 'zp-scope'; | ||
var propsAttr = 'zp-props'; | ||
var templateNode = 'zp-template'; | ||
var virtualNode = 'zp-virtual'; | ||
var includeNode = 'zp-include'; | ||
var includeSrcAttr = 'src'; | ||
var requireAttr = 'rt-require'; | ||
var importAttr = 'rt-import'; | ||
var statelessAttr = 'rt-stateless'; | ||
var preAttr = 'rt-pre'; | ||
var requireAttr = 'zp-require'; | ||
var importAttr = 'zp-import'; | ||
var statelessAttr = 'zp-stateless'; | ||
var preAttr = 'zp-pre'; | ||
@@ -63,4 +63,4 @@ var reactTemplatesSelfClosingTags = [includeNode]; | ||
//指令扩展 | ||
var dataBindAttr = "rt-bind"; | ||
var htmlNode = "rt-html"; | ||
var dataBindAttr = "zp-bind"; | ||
var htmlNode = "zp-html"; | ||
var htmlNodeIndex = 0; | ||
@@ -126,6 +126,6 @@ /** | ||
if (!_.has(child.attribs, 'prop')) { | ||
throw RTCodeError.build(context, child, 'rt-template must have a prop attribute'); | ||
throw RTCodeError.build(context, child, 'zp-template must have a prop attribute'); | ||
} | ||
if (_.filter(child.children, { type: 'tag' }).length !== 1) { | ||
throw RTCodeError.build(context, child, "'rt-template' should have a single non-text element as direct child"); | ||
throw RTCodeError.build(context, child, "'zp-template' should have a single non-text element as direct child"); | ||
} | ||
@@ -209,3 +209,3 @@ | ||
} else if (propKey === reactSupport.classNameProp) { | ||
// Processing for both class and rt-class conveniently return strings that | ||
// Processing for both class and zp-class conveniently return strings that | ||
// represent JS expressions, each evaluating to a space-separated set of class names. | ||
@@ -237,3 +237,3 @@ // We can just join them with another space here. | ||
} | ||
} else if (!_.startsWith(key, 'rt-')) { | ||
} else if (!_.startsWith(key, 'zp-')) { | ||
props[propKey] = utils.convertText(node, context, val.trim()); | ||
@@ -393,3 +393,3 @@ } | ||
if (node.type === 'tag' && node.name === importAttr) { | ||
throw RTCodeError.build(context, node, "'rt-import' must be a toplevel node"); | ||
throw RTCodeError.build(context, node, "'zp-import' must be a toplevel node"); | ||
} | ||
@@ -400,6 +400,6 @@ | ||
if (!srcFile) { | ||
throw RTCodeError.build(context, node, 'rt-include must supply a source attribute'); | ||
throw RTCodeError.build(context, node, 'zp-include must supply a source attribute'); | ||
} | ||
if (!context.options.readFileSync) { | ||
throw RTCodeError.build(context, node, 'rt-include needs a readFileSync polyfill on options'); | ||
throw RTCodeError.build(context, node, 'zp-include needs a readFileSync polyfill on options'); | ||
} | ||
@@ -410,3 +410,3 @@ try { | ||
console.error(e); | ||
throw RTCodeError.build(context, node, 'rt-include failed to read file \'' + srcFile + '\''); | ||
throw RTCodeError.build(context, node, 'zp-include failed to read file \'' + srcFile + '\''); | ||
} | ||
@@ -421,6 +421,6 @@ return { | ||
// Order matters. We need to add the item and itemIndex to context.boundParams before | ||
// the rt-scope directive is processed, lest they are not passed to the child scopes | ||
// the zp-scope directive is processed, lest they are not passed to the child scopes | ||
if (node.attribs[repeatAttr]) { | ||
//为循环加上key | ||
// if (node.name != "rt-virtual"&&!node.attribs["key"]) { | ||
// if (node.name != "zp-virtual"&&!node.attribs["key"]) { | ||
// node.attribs["key"] = "{Math.random()}"; | ||
@@ -431,3 +431,3 @@ // } | ||
if (_arr.length !== 2) { | ||
throw RTCodeError.build(context, node, 'rt-repeat invalid \'in\' expression \'' + node.attribs[repeatAttr] + '\''); | ||
throw RTCodeError.build(context, node, 'zp-repeat invalid \'in\' expression \'' + node.attribs[repeatAttr] + '\''); | ||
} | ||
@@ -481,3 +481,3 @@ var repeaterParams = _arr[0].split(',').map(function (s) { | ||
if (invalidAttributes.length > 0) { | ||
throw RTCodeError.build(context, node, "<rt-virtual> may not contain attributes other than 'rt-scope', 'rt-if' and 'rt-repeat'"); | ||
throw RTCodeError.build(context, node, "<zp-virtual> may not contain attributes other than 'zp-scope', 'zp-if' and 'zp-repeat'"); | ||
} | ||
@@ -512,4 +512,4 @@ | ||
var $ = cheerio.load(html); | ||
// console.log($('rt-html').eq(htmlNodeIndex).html,htmlNodeIndex) | ||
var innerHtml = $('rt-html').eq(htmlNodeIndex++).html().replace(/[\r\n]/g, '').replace(/[']/g, '\\\'').trim(); | ||
// console.log($('zp-html').eq(htmlNodeIndex).html,htmlNodeIndex) | ||
var innerHtml = $('zp-html').eq(htmlNodeIndex++).html().replace(/[\r\n]/g, '').replace(/[']/g, '\\\'').trim(); | ||
// console.log(node,innerHtml) | ||
@@ -528,3 +528,3 @@ data.body = '[React.createElement(\'div\',{dangerouslySetInnerHTML:{__html:\'' + innerHtml + '\'}})]'; | ||
// Order matters here. Each rt-repeat iteration wraps over the rt-scope, so | ||
// Order matters here. Each zp-repeat iteration wraps over the zp-scope, so | ||
// the scope variables are evaluated in context of the current iteration. | ||
@@ -579,3 +579,3 @@ if (node.attribs[repeatAttr]) { | ||
// the scope chain, as well as variables that are locally bound before any | ||
// function call, as with the ones we generate for rt-scope. | ||
// function call, as with the ones we generate for zp-scope. | ||
if (!_.includes(context.boundParams, alias)) { | ||
@@ -600,3 +600,3 @@ context.boundParams.push(alias); | ||
if (ifAttributeTree && ifAttributeTree.body && ifAttributeTree.body.length === 1 && ifAttributeTree.body[0].type === 'ExpressionStatement') { | ||
// make sure that rt-if does not use an inner mapping | ||
// make sure that zp-if does not use an inner mapping | ||
if (ifAttributeTree.body[0].expression && utils.usesScopeName(innerMappingKeys, ifAttributeTree.body[0].expression)) { | ||
@@ -735,3 +735,3 @@ throw RTCodeError.buildFormat(context, node, "invalid scope mapping used in if part '%s'", node.attribs[ifAttr]); | ||
} else if (_.includes(_.keys(firstTag.attribs), repeatAttr)) { | ||
throw RTCodeError.build(context, firstTag, "root element may not have a 'rt-repeat' attribute"); | ||
throw RTCodeError.build(context, firstTag, "root element may not have a 'zp-repeat' attribute"); | ||
} | ||
@@ -738,0 +738,0 @@ return convertHtmlToReact(firstTag, context, resourcePath, html); |
{ | ||
"name": "zpin-templates", | ||
"version": "0.0.32", | ||
"version": "0.0.33", | ||
"description": "Light weight templates for react -> write html get valid react code", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -36,3 +36,3 @@ 'use strict'; | ||
`; | ||
//2016.11.22 rt-class别名转换bug | ||
//2016.11.22 zp-class别名转换bug | ||
const classSetTemplate = _.template('_(<%= classSet %>).transform(function(res, value, key){ if(value){ res.push(this.styles[key]);} }.bind(this), []).join(" ")'); | ||
@@ -52,16 +52,16 @@ // const classSetTemplate = _.template('_(<%= classSet %>).transform(function(res, value, key){ if(value){ res.push(key);} }.bind(this), []).join(" ")'); | ||
const repeatAttr = 'rt-repeat'; | ||
const ifAttr = 'rt-if'; | ||
const classSetAttr = 'rt-class'; | ||
const repeatAttr = 'zp-repeat'; | ||
const ifAttr = 'zp-if'; | ||
const classSetAttr = 'zp-class'; | ||
const classAttr = 'class'; | ||
const scopeAttr = 'rt-scope'; | ||
const propsAttr = 'rt-props'; | ||
const templateNode = 'rt-template'; | ||
const virtualNode = 'rt-virtual'; | ||
const includeNode = 'rt-include'; | ||
const scopeAttr = 'zp-scope'; | ||
const propsAttr = 'zp-props'; | ||
const templateNode = 'zp-template'; | ||
const virtualNode = 'zp-virtual'; | ||
const includeNode = 'zp-include'; | ||
const includeSrcAttr = 'src'; | ||
const requireAttr = 'rt-require'; | ||
const importAttr = 'rt-import'; | ||
const statelessAttr = 'rt-stateless'; | ||
const preAttr = 'rt-pre'; | ||
const requireAttr = 'zp-require'; | ||
const importAttr = 'zp-import'; | ||
const statelessAttr = 'zp-stateless'; | ||
const preAttr = 'zp-pre'; | ||
@@ -71,4 +71,4 @@ const reactTemplatesSelfClosingTags = [includeNode]; | ||
//指令扩展 | ||
const dataBindAttr="rt-bind"; | ||
const htmlNode="rt-html"; | ||
const dataBindAttr="zp-bind"; | ||
const htmlNode="zp-html"; | ||
let htmlNodeIndex=0; | ||
@@ -139,6 +139,6 @@ /** | ||
if (!_.has(child.attribs, 'prop')) { | ||
throw RTCodeError.build(context, child, 'rt-template must have a prop attribute'); | ||
throw RTCodeError.build(context, child, 'zp-template must have a prop attribute'); | ||
} | ||
if (_.filter(child.children, {type: 'tag'}).length !== 1) { | ||
throw RTCodeError.build(context, child, "'rt-template' should have a single non-text element as direct child"); | ||
throw RTCodeError.build(context, child, "'zp-template' should have a single non-text element as direct child"); | ||
} | ||
@@ -224,3 +224,3 @@ | ||
} else if (propKey === reactSupport.classNameProp) { | ||
// Processing for both class and rt-class conveniently return strings that | ||
// Processing for both class and zp-class conveniently return strings that | ||
// represent JS expressions, each evaluating to a space-separated set of class names. | ||
@@ -252,3 +252,3 @@ // We can just join them with another space here. | ||
} | ||
} else if (!_.startsWith(key, 'rt-')) { | ||
} else if (!_.startsWith(key, 'zp-')) { | ||
props[propKey] = utils.convertText(node, context, val.trim()); | ||
@@ -410,3 +410,3 @@ } | ||
if (node.type === 'tag' && node.name === importAttr) { | ||
throw RTCodeError.build(context, node, "'rt-import' must be a toplevel node"); | ||
throw RTCodeError.build(context, node, "'zp-import' must be a toplevel node"); | ||
} | ||
@@ -417,6 +417,6 @@ | ||
if (!srcFile) { | ||
throw RTCodeError.build(context, node, 'rt-include must supply a source attribute'); | ||
throw RTCodeError.build(context, node, 'zp-include must supply a source attribute'); | ||
} | ||
if (!context.options.readFileSync) { | ||
throw RTCodeError.build(context, node, 'rt-include needs a readFileSync polyfill on options'); | ||
throw RTCodeError.build(context, node, 'zp-include needs a readFileSync polyfill on options'); | ||
} | ||
@@ -427,3 +427,3 @@ try { | ||
console.error(e); | ||
throw RTCodeError.build(context, node, `rt-include failed to read file '${srcFile}'`); | ||
throw RTCodeError.build(context, node, `zp-include failed to read file '${srcFile}'`); | ||
} | ||
@@ -436,6 +436,6 @@ return parseAndConvertHtmlToReact(context.html, context,resourcePath); | ||
// Order matters. We need to add the item and itemIndex to context.boundParams before | ||
// the rt-scope directive is processed, lest they are not passed to the child scopes | ||
// the zp-scope directive is processed, lest they are not passed to the child scopes | ||
if (node.attribs[repeatAttr]) { | ||
//为循环加上key | ||
// if (node.name != "rt-virtual"&&!node.attribs["key"]) { | ||
// if (node.name != "zp-virtual"&&!node.attribs["key"]) { | ||
// node.attribs["key"] = "{Math.random()}"; | ||
@@ -446,3 +446,3 @@ // } | ||
if (arr.length !== 2) { | ||
throw RTCodeError.build(context, node, `rt-repeat invalid 'in' expression '${node.attribs[repeatAttr]}'`); | ||
throw RTCodeError.build(context, node, `zp-repeat invalid 'in' expression '${node.attribs[repeatAttr]}'`); | ||
} | ||
@@ -494,3 +494,3 @@ const repeaterParams = arr[0].split(',').map(s => s.trim()); | ||
if (invalidAttributes.length > 0) { | ||
throw RTCodeError.build(context, node, "<rt-virtual> may not contain attributes other than 'rt-scope', 'rt-if' and 'rt-repeat'"); | ||
throw RTCodeError.build(context, node, "<zp-virtual> may not contain attributes other than 'zp-scope', 'zp-if' and 'zp-repeat'"); | ||
} | ||
@@ -526,4 +526,4 @@ | ||
let $ = cheerio.load(html); | ||
// console.log($('rt-html').eq(htmlNodeIndex).html,htmlNodeIndex) | ||
let innerHtml=$('rt-html').eq(htmlNodeIndex++).html() | ||
// console.log($('zp-html').eq(htmlNodeIndex).html,htmlNodeIndex) | ||
let innerHtml=$('zp-html').eq(htmlNodeIndex++).html() | ||
.replace(/[\r\n]/g,'') | ||
@@ -545,3 +545,3 @@ .replace(/[']/g,'\\\'') | ||
// Order matters here. Each rt-repeat iteration wraps over the rt-scope, so | ||
// Order matters here. Each zp-repeat iteration wraps over the zp-scope, so | ||
// the scope variables are evaluated in context of the current iteration. | ||
@@ -589,3 +589,3 @@ if (node.attribs[repeatAttr]) { | ||
// the scope chain, as well as variables that are locally bound before any | ||
// function call, as with the ones we generate for rt-scope. | ||
// function call, as with the ones we generate for zp-scope. | ||
if (!_.includes(context.boundParams, alias)) { | ||
@@ -610,3 +610,3 @@ context.boundParams.push(alias); | ||
if (ifAttributeTree && ifAttributeTree.body && ifAttributeTree.body.length === 1 && ifAttributeTree.body[0].type === 'ExpressionStatement') { | ||
// make sure that rt-if does not use an inner mapping | ||
// make sure that zp-if does not use an inner mapping | ||
if (ifAttributeTree.body[0].expression && utils.usesScopeName(innerMappingKeys, ifAttributeTree.body[0].expression)) { | ||
@@ -745,3 +745,3 @@ throw RTCodeError.buildFormat(context, node, "invalid scope mapping used in if part '%s'", node.attribs[ifAttr]); | ||
} else if (_.includes(_.keys(firstTag.attribs), repeatAttr)) { | ||
throw RTCodeError.build(context, firstTag, "root element may not have a 'rt-repeat' attribute"); | ||
throw RTCodeError.build(context, firstTag, "root element may not have a 'zp-repeat' attribute"); | ||
} | ||
@@ -748,0 +748,0 @@ return convertHtmlToReact(firstTag, context,resourcePath,html); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package