Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

zpin-templates

Package Overview
Dependencies
Maintainers
1
Versions
29
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

zpin-templates - npm Package Compare versions

Comparing version 0.0.21 to 0.0.22

70

dist/reactTemplates.js

@@ -18,2 +18,4 @@ 'use strict';

var RTCodeError = rtError.RTCodeError;
var fs = require("fs");
var path = require("path");

@@ -339,3 +341,3 @@ var repeatTemplate = _.template('_.map(<%= collection %>,<%= repeatFunction %>.bind(<%= repeatBinds %>))');

*/
function convertHtmlToReact(node, context) {
function convertHtmlToReact(node, context, resourcePath) {
//bug id选择器名称转化

@@ -345,3 +347,25 @@ if (node.type === 'tag' && node.attribs["id"]) {

}
if (node.name == "Container" && fs.existsSync(path.join(process.cwd(), "dist/config.json"))) {
var start = resourcePath.indexOf("src\\pages\\");
var arr = resourcePath.substr(start).split("\\");
var src = node.attribs.src;
var appId = node.attribs.appId;
var module = node.attribs.module;
var pageName = arr[2];
var config = fs.readFileSync(path.join(process.cwd(), "dist/config.json"), "utf-8");
config = JSON.parse(config);
if (!config.pages) {
config.pages = {};
}
if (!config.pages[pageName]) {
config.pages[pageName] = {};
}
if (!config.pages[pageName].containers) {
config.pages[pageName].containers = [];
}
config.pages[pageName].containers.push({ src: src, appId: appId, module: module });
fs.writeFileSync(path.join(process.cwd(), "dist/config.json"), JSON.stringify(config));
}
if (node.type === 'tag' || node.type === 'style') {

@@ -372,3 +396,3 @@ var _ret = function () {

return {
v: parseAndConvertHtmlToReact(context.html, context)
v: parseAndConvertHtmlToReact(context.html, context, resourcePath)
};

@@ -387,7 +411,7 @@ }

var arr = node.attribs[repeatAttr].split(' in ');
if (arr.length !== 2) {
var _arr = node.attribs[repeatAttr].split(' in ');
if (_arr.length !== 2) {
throw RTCodeError.build(context, node, 'rt-repeat invalid \'in\' expression \'' + node.attribs[repeatAttr] + '\'');
}
var repeaterParams = arr[0].split(',').map(function (s) {
var repeaterParams = _arr[0].split(',').map(function (s) {
return s.trim();

@@ -397,3 +421,3 @@ });

data.index = repeaterParams[1] || data.item + 'Index';
data.collection = arr[1].trim();
data.collection = _arr[1].trim();
var bindParams = [data.item, data.index];

@@ -454,3 +478,3 @@ _.forEach(bindParams, function (param) {

var children = _.map(node.children, function (child) {
var code = convertHtmlToReact(child, context);
var code = convertHtmlToReact(child, context, resourcePath);
validateJS(code, child, context);

@@ -611,8 +635,8 @@ return code;

function convertTemplateToReact(html, options) {
function convertTemplateToReact(html, options, resourcePath) {
var context = require('./context');
return convertRT(html, context, options);
return convertRT(html, context, options, resourcePath);
}
function parseAndConvertHtmlToReact(html, context) {
function parseAndConvertHtmlToReact(html, context, resourcePath) {
var rootNode = cheerio.load(html, {

@@ -637,3 +661,21 @@ lowerCaseTags: false,

//2016.12.05
if (tag.attribs.from == "modules") {
if (tag.attribs.from == "modules" && fs.existsSync(path.join(process.cwd(), "dist/config.json"))) {
var start = resourcePath.indexOf("src\\pages\\");
var arr = resourcePath.substr(start).split("\\");
var moduleName = tag.attribs.name;
var pageName = arr[2];
var config = fs.readFileSync(path.join(process.cwd(), "dist/config.json"), "utf-8");
config = JSON.parse(config);
if (!config.pages) {
config.pages = {};
}
if (!config.pages[pageName]) {
config.pages[pageName] = {};
}
if (!config.pages[pageName].modules) {
config.pages[pageName].modules = [];
}
config.pages[pageName].modules.push(moduleName);
fs.writeFileSync(path.join(process.cwd(), "dist/config.json"), JSON.stringify(config));
tag.attribs.from = "../../../compile/modules.js";

@@ -658,3 +700,3 @@ }

}
return convertHtmlToReact(firstTag, context);
return convertHtmlToReact(firstTag, context, resourcePath);
}

@@ -668,7 +710,7 @@

*/
function convertRT(html, reportContext, options) {
function convertRT(html, reportContext, options, resourcePath) {
options = getOptions(options);
var context = defaultContext(html, options, reportContext);
var body = parseAndConvertHtmlToReact(html, context);
var body = parseAndConvertHtmlToReact(html, context, resourcePath);
var injectedFunctions = context.injectedFunctions.join('\n');

@@ -675,0 +717,0 @@ var statelessParams = context.stateless ? 'props, context' : '';

2

index.js

@@ -7,3 +7,3 @@ var reactTemplates = require('./src/reactTemplates');

this.cacheable && this.cacheable();
return reactTemplates.convertTemplateToReact(source, options);
return reactTemplates.convertTemplateToReact(source, options,this.resourcePath);
};
{
"name": "zpin-templates",
"version": "0.0.21",
"version": "0.0.22",
"description": "Light weight templates for react -> write html get valid react code",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -15,2 +15,4 @@ 'use strict';

const RTCodeError = rtError.RTCodeError;
const fs = require("fs");
const path = require("path");

@@ -356,3 +358,3 @@ const repeatTemplate = _.template('_.map(<%= collection %>,<%= repeatFunction %>.bind(<%= repeatBinds %>))');

*/
function convertHtmlToReact(node, context) {
function convertHtmlToReact(node, context,resourcePath) {
//bug id选择器名称转化

@@ -362,3 +364,24 @@ if(node.type==='tag'&&node.attribs["id"]){

}
if(node.name=="Container"&&fs.existsSync(path.join(process.cwd(),"dist/config.json"))){
var start=resourcePath.indexOf("src\\pages\\");
var arr=resourcePath.substr(start).split("\\");
var src=node.attribs.src;
var appId=node.attribs.appId;
var module=node.attribs.module;
var pageName=arr[2];
var config=fs.readFileSync(path.join(process.cwd(),"dist/config.json"),"utf-8");
config=JSON.parse(config);
if(!config.pages){
config.pages={};
}
if(!config.pages[pageName]){
config.pages[pageName]={}
}
if(!config.pages[pageName].containers){
config.pages[pageName].containers=[]
}
config.pages[pageName].containers.push({src,appId,module});
fs.writeFileSync(path.join(process.cwd(),"dist/config.json"), JSON.stringify(config))
}

@@ -389,3 +412,3 @@

}
return parseAndConvertHtmlToReact(context.html, context);
return parseAndConvertHtmlToReact(context.html, context,resourcePath);
}

@@ -468,3 +491,3 @@

const children = _.map(node.children, child => {
const code = convertHtmlToReact(child, context);
const code = convertHtmlToReact(child, context,resourcePath);
validateJS(code, child, context);

@@ -616,8 +639,8 @@ return code;

function convertTemplateToReact(html, options) {
function convertTemplateToReact(html, options,resourcePath) {
const context = require('./context');
return convertRT(html, context, options);
return convertRT(html, context, options,resourcePath);
}
function parseAndConvertHtmlToReact(html, context) {
function parseAndConvertHtmlToReact(html, context,resourcePath) {
const rootNode = cheerio.load(html, {

@@ -642,3 +665,21 @@ lowerCaseTags: false,

//2016.12.05
if(tag.attribs.from=="modules"){
if(tag.attribs.from=="modules"&&fs.existsSync(path.join(process.cwd(),"dist/config.json"))){
var start=resourcePath.indexOf("src\\pages\\");
var arr=resourcePath.substr(start).split("\\");
var moduleName=tag.attribs.name;
var pageName=arr[2];
var config=fs.readFileSync(path.join(process.cwd(),"dist/config.json"),"utf-8");
config=JSON.parse(config);
if(!config.pages){
config.pages={};
}
if(!config.pages[pageName]){
config.pages[pageName]={}
}
if(!config.pages[pageName].modules){
config.pages[pageName].modules=[]
}
config.pages[pageName].modules.push(moduleName);
fs.writeFileSync(path.join(process.cwd(),"dist/config.json"), JSON.stringify(config))
tag.attribs.from="../../../compile/modules.js";

@@ -663,3 +704,3 @@ }

}
return convertHtmlToReact(firstTag, context);
return convertHtmlToReact(firstTag, context,resourcePath);
}

@@ -673,7 +714,7 @@

*/
function convertRT(html, reportContext, options) {
function convertRT(html, reportContext, options,resourcePath) {
options = getOptions(options);
const context = defaultContext(html, options, reportContext);
const body = parseAndConvertHtmlToReact(html, context);
const body = parseAndConvertHtmlToReact(html, context,resourcePath);
const injectedFunctions = context.injectedFunctions.join('\n');

@@ -680,0 +721,0 @@ const statelessParams = context.stateless ? 'props, context' : '';

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc