New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

bemrender

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bemrender - npm Package Compare versions

Comparing version

to
0.3.0

example/mvc/blocks/article/article.html

16

example/mvc/controllers/index.js

@@ -11,3 +11,17 @@ /**

var values = {
text : "<h1>index page</h1>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum."
text : "<h1>index page</h1>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.",
tableData : [
{
"first" : "aaaa",
"second" : "bbbb"
},
{
"first" : "ccccc",
"second" : "dddd"
},
{
"first" : "eeeee",
"second" : "fffff"
}
]
};

@@ -14,0 +28,0 @@ res.render('index', values, function(err, string){

@@ -24,3 +24,51 @@ {

"block" : "wrapper",
"content": "{{=it.text}}"
"content": [
{
"block" : "article",
"content" : "{{=it.text}}"
},
{
"block" : "article",
"content" : "<h2>multiple elements</h2>"
},
{
"block" : "table",
"mods" : [
{"size" : "big"}
],
"content" : [
{
"element" : "row",
"multiple": true,
"content" : "{{=it.tableData}}"
}
]
},
{
"block" : "table",
"mods" : [
{"size" : "big"}
],
"content" : [
{
"element" : "row",
"multiple": true,
"content" : [
{
"first" : "aaaa",
"second" : "bbbb"
},
{
"first" : "ccccc",
"second" : "dddd"
},
{
"first" : "eeeee",
"second" : "fffff"
}
]
}
]
}
]
}

@@ -27,0 +75,0 @@ ]

@@ -66,4 +66,4 @@ /**

else{
fs.readFile(jsonPath, 'utf8', function(err, str){
if (err) return fn(err);
self.readJSON(jsonPath, function(err, str){
if (err) fn(err);

@@ -77,4 +77,3 @@ try{

options.js = path.join(self.baseName, "all.js");
options.css = path.join(self.baseName, "all.css");
self.defineTplAPI(options);

@@ -113,3 +112,3 @@ //prepare page template

* @param json
* @param parent
* @param [parent]
* @return {*}

@@ -122,14 +121,20 @@ */

isElement = entity == "element",
isMultiple = "multiple" in json,
name = json[entity],
html = "",
bPath = path.join(config.blocksPath, isElement ? parent : "", name, name);
html = this.loadHTML(isElement, parent, name),
serviceVars = {};
for (var i in json){
if (json.hasOwnProperty(i)){
if (i == "content" && json[i] instanceof Array){
var content = [];
json[i].forEach(function(str){
content.push(self.prepareTemplate(str, name));
});
json["content"] = content.join("");
if (i == "content"){
if (json[i] instanceof Array && !isMultiple){
var content = [];
json[i].forEach(function(str){
content.push(self.prepareTemplate(str, name));
});
serviceVars[i] = content.join("");
}
else{
serviceVars[i] = json[i];
}
}

@@ -146,3 +151,3 @@ else if(i == "mods" && json[i] instanceof Array){

});
json["mods"] = mods.join(" ");
serviceVars["mods"] = mods.join(" ");
}

@@ -153,3 +158,3 @@ else if(i == "js" && json[i] instanceof Array){

});
json[i] = path.join(self.baseName, "all.js");
serviceVars[i] = ["",self.baseName, "all.js"].join("/");
}

@@ -160,30 +165,76 @@ else if(i == "css" && json[i] instanceof Array){

});
json[i] = path.join(self.baseName, "all.css");
serviceVars[i] = ["",self.baseName, "all.css"].join("/");
}
}
json["blockName"] = self.getCssName(isElement, parent, name);
json["getBlockName"] = function(n){
return self.getCssName(isElement, parent, name + n);
};
json["mods"] = json["mods"] || "";
serviceVars["blockName"] = self.getCssName(isElement, parent, name);
serviceVars["mods"] = serviceVars["mods"] || "";
}
if (bPath in self.blocksHash)
html = self.blocksHash[bPath]["html"];
for (var v in serviceVars){
if (serviceVars.hasOwnProperty(v)){
html = html.replace(new RegExp("\\{\\{[^\}]+it\\.(" + v + ")(.*?)\\}\\}", "g"), function(str, code){
var res = serviceVars[code];
if (code == "content"){
if(json["multiple"]){
if (typeof res == "string")
res = str.replace(/content/g,res.replace(/(\{\{=it.)|(\}\})/g, ""));
else
res = str;
}
}
else
res = str.replace(new RegExp("it\\." + code, "g"), "'" + res + "'");
return res;
});
}
}
if (serviceVars["content"] && serviceVars["content"] instanceof Array){
var opt = this.defineTplAPI({content : serviceVars["content"]});
html = doT.template(html)(opt);
}
return html;
};
/**
* load HTML template
* @param isElement
* @param parent
* @param name
* @return {String}
*/
bemRender.prototype.loadHTML = function(isElement, parent, name){
var
bPath = path.join(config.blocksPath, isElement ? parent : "", name, name),
html = "";
if (bPath in this.blocksHash){
html = this.blocksHash[bPath]["html"];
}
else{
try{
html = fs.readFileSync(bPath + ".html", 'utf8');
self.blocksHash[bPath] = {
this.blocksHash[bPath] = {
"html": html,
"css" : self.getCssName(isElement, parent, name)
"css" : this.getCssName(isElement, parent, name)
};
}
catch(e){
html = "";
console.log(e.message);
html = "";
}
}
return doT.template(html)(json);
return html;
};
/**
* read JSON file
* @param {String} jsonPath
* @param {function} cb
*/
bemRender.prototype.readJSON = function(jsonPath, cb){
fs.readFile(jsonPath, "utf8", cb);
};
/**
* prepare string of all.js

@@ -261,4 +312,4 @@ * @param {function} handler

* @param {String} name
* @param {String} mod
* @param {String} modV
* @param {String} [mod]
* @param {String} [modV]
* @return {String}

@@ -309,5 +360,47 @@ */

/**
* Define api
* @param options
*/
bemRender.prototype.defineTplAPI = function(options){
var self = this;
//@tplProperty {String} js - link for js file, which include all the scripts
options.js = path.join("/", self.baseName, "all.js");
//@tplProperty {String} css - link for css file, which include all the styles
options.css = path.join("/", self.baseName, "all.css");
//@tplProperty {String} blockName - css class for block or element
//@tplProperty {String} modifiers - css classes for predefined modifiers
/**
* @tplFunction getElementName - return valid css name for inner element
* @param {String} blockName
* @param {String} elementName
* @return {String}
*/
options.getElementName = function(blockName, elementName){
return self.getCssName(true, blockName, elementName);
};
/**
* @tplFunction getMod - return modifier css class
* @param {String} blockName
* @param {String} mod
* @param {String} val
* @return {String}
*/
options.getMod = function(blockName, mod, val){
return self.getCssName(false, "", blockName, mod, val);
};
return options;
};
return function(jsonPath, options, fn){
if (arguments.length == 1)
return bemRender;
return new bemRender(jsonPath, options, fn);
}
};

12

package.json
{
"name": "bemrender",
"description": "express.js view render based on BEM methodology",
"version": "0.2.2",
"version": "0.3.0",
"author": "Ershov Konstantin <ershov.konst@gmail.com>",

@@ -15,6 +15,8 @@ "keywords": [

"less": "1.3.x",
"mkdirp": "0.3.x",
"express": "3.x"
"mkdirp": "0.3.x"
},
"devDependencies": {},
"devDependencies": {
"express": "3.x",
"nodeunit ": "*"
},
"main": "./lib/bemRender.js",

@@ -30,5 +32,5 @@ "engines": {

"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "node runtest.js"
},
"license": "BSD"
}

Sorry, the diff of this file is not supported yet