Skip to content

Commit

Permalink
fix templates
Browse files Browse the repository at this point in the history
  • Loading branch information
veged committed Sep 1, 2017
1 parent f3f6779 commit b755b55
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 103 deletions.
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
30 changes: 13 additions & 17 deletions .bem/templates/spec.js.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,17 @@ 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);
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}/>);
});
`;
};
30 changes: 0 additions & 30 deletions .bem/templates/tests-css.js

This file was deleted.

43 changes: 14 additions & 29 deletions .bem/templates/tests-html.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,15 @@
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);
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>
`;
};
33 changes: 15 additions & 18 deletions .bem/templates/tests-js.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
var EOL = require('os').EOL,
nameRegEx = /^[a-zA-Z_][a-zA-Z\d_]*$/;


function toObjectKey(str) {
return nameRegEx.test(str) ? str : "'" + str + "'"
}
Expand All @@ -10,21 +9,19 @@ 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);
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'));
`;
};
15 changes: 7 additions & 8 deletions .bemrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,27 @@ module.exports = {
naming : 'react'
},
'blocks/**/*.tests' : {
scheme : 'flat',
schemeOptions : 'react',
naming : 'react'
scheme : 'flat'
}
},
modules : {
'bem-tools' : {
plugins : {
create : {
techs : ['js', 'spec.js', 'css', 'tests' ],
templates : {
js : '.bem/templates/js.js',
'spec.js' : '.bem/templates/spec.js.js',
'tests' : '.bem/templates/tests.js',
},
levels : {
blocks : { default : true },
'blocks*/**/*.tests' : {
techs : ['js', 'css', 'html'],
blocks : {
default : true,
techs : ['js', 'css']
},
'blocks/**/*.tests' : {
techs : ['js', 'html'],
templates : {
js : '.bem/templates/tests-js.js',
css : '.bem/templates/tests-css.js',
html : '.bem/templates/tests-html.js',
}
}
Expand Down

0 comments on commit b755b55

Please sign in to comment.