Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .bem/templates/js.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ function toObjectValue(x) {
return typeof x === 'boolean' ? x : `'${x}'`;
}

module.exports = function ({ block, elem, mod={} }, naming) {
module.exports = function ({ block, elem, mod={} }) {
const { name : modName, val : modVal } = mod;
return `import { ${modName? 'declMod' : 'decl'} } from 'bem-react-core';

Expand Down
26 changes: 26 additions & 0 deletions .bem/templates/spec.js.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
var EOL = require('os').EOL,
nameRegEx = /^[a-zA-Z_][a-zA-Z\d_]*$/;


function toObjectKey(str) {
return nameRegEx.test(str) ? str : "'" + str + "'"
}

function toObjectValue(x) {
return typeof x === 'boolean' ? x : "'" + x + "'";
}

module.exports = function ({ block, elem, mod={} }, naming) {
const { name : modName, val : modVal } = mod;

return `import React from 'react';
import { block } from '../../.jest/helpers';
import ${block} from 'b:${block}';

const renderer = block('${block}');

it('should be ...', () => {
renderer(<${block}/>);
});
`;
};
15 changes: 15 additions & 0 deletions .bem/templates/tests-html.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module.exports = function ({ block }) {
return `<!DOCTYPE html>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
⚠︎ <meta charset="utf-8"/>
<title></title>
</head>
<body>
<div id="root"></div>
⚠︎ <script src="${block}.js"></script>
</body>
</html>
`;
};
27 changes: 27 additions & 0 deletions .bem/templates/tests-js.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
var EOL = require('os').EOL,
nameRegEx = /^[a-zA-Z_][a-zA-Z\d_]*$/;

function toObjectKey(str) {
return nameRegEx.test(str) ? str : "'" + str + "'"
}

function toObjectValue(x) {
return typeof x === 'boolean' ? x : "'" + x + "'";
}

module.exports = function ({ block, elem, mod={} }) {
const { name : modName, val : modVal } = mod,
entityName = elem || block;

return `import React from 'react';
import ReactDom from 'react-dom';
import ${entityName} from 'b:${block}${elem? ' e:' + elem : ''}${modName? ' m:' + modName + (modVal? '=' + modVal : ''): ''}';

class App extends React.Component {
render() {
return <${entityName}${modName? ' ' + modName + (modVal? '="${modVal}"' : ''): ''}/>
}
}
ReactDom.render(<App/>, document.getElementById('root'));
`;
};
30 changes: 30 additions & 0 deletions .bem/templates/tests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
var EOL = require('os').EOL,
nameRegEx = /^[a-zA-Z_][a-zA-Z\d_]*$/;


function toObjectKey(str) {
return nameRegEx.test(str) ? str : "'" + str + "'"
}

function toObjectValue(x) {
return typeof x === 'boolean' ? x : "'" + x + "'";
}

module.exports = function (entity, naming) {
return [
"import {decl} from 'bem-react-core';",
"",
"export default " +
(entity.modName ?
"declMod({ " +
toObjectKey(entity.modName) + " : " +
toObjectValue(entity.modVal || true) +
" }, {" :
"decl({"),
" block : '" + entity.block + "'" +
(entity.elem ?
"," + EOL + " elem : '" + entity.elem + "'" :
""),
"});"
].join(EOL);
};
22 changes: 17 additions & 5 deletions .bemrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,32 @@ module.exports = {
scheme : 'nested',
schemeOptions : 'react',
naming : 'react'
},
'blocks/**/*.tests' : {
scheme : 'flat'
}
},
modules : {
'bem-tools' : {
plugins : {
create : {
templates : {
js : '.bem/templates/js.js',
'spec.js' : '.bem/templates/spec.js.js',
'tests' : '.bem/templates/tests.js',
},
levels : {
blocks : {
default : true
default : true,
techs : ['js', 'css']
},
'blocks/**/*.tests' : {
techs : ['js', 'html'],
templates : {
js : '.bem/templates/tests-js.js',
html : '.bem/templates/tests-html.js',
}
}
},
techs : ['js', 'css'],
templates : {
js : '.bem/templates/js.js'
}
}
}
Expand Down