- BEM: http://bem.info
- Sailsjs: http://sailsjs.org
(sails >= 0.11)
- add this hook to package.json:
npm i sails-hook-bem-render --save
- use in your controllers
res.render(data)
(sails < 0.11) also needs explicit hooks declaration:
- create
bem-render
folder inapi/hooks
- create
index.js
file inapi/hooks/bem-render/
- write in
api/hooks/bem-render/index.js
this:
module.exports = require('sails-hook-bem-render');
For example project see sails-bem-project-stub.
- Create a
/views/common
directory for BEM blocks. - Create
/views/.enb
directory with make-config file forenb
assembler. You can copy config from sails-bem-project-stub/frontend/.enb/make.js. Notice: there is onlydesktop
config yet. - Create
/views/desktop.bundles/index/index.bemdecl.js
file – dependency declaration forenb
assembler:
exports.blocks = [
{block: 'page'} // Other dependencies will be declare in `page` block.
];
- Add dependencies: 4.1 npm dependency for BEM and enb to package.json:
"dependencies": {
"vow": "^0.4.5",
"ym": "^0.1.0"
},
"devDependencies": {
"bem": "^0.9.0",
"borschik": "^1.3.0",
"borschik-tech-cleancss": "^1.0.0",
"bower": "^1.3.9",
"enb": "^0.13.7",
"enb-autoprefixer": "^0.1.1",
"enb-bem": "0.1.0-beta2",
"enb-bemxjst": "^1.3.2",
"enb-borschik": "^1.1.1",
"enb-diverse-js": "^0.1.0",
"enb-modules": "^0.2.0",
"enb-stylus": "1.1.2"
}
4.2 bower:
"dependencies": {
"bem-core": "2.6.0"
}
Don't forget to add .bowerrc
file:
{
"directory": "views/libs"
}
- After you add your blocks, run
node_modules/.bin/enb make -d views --no-cache
. It will compile BEMTREE, BEMHTML, assemble js, CSS intoviews/desktop.bundles/merged
folder. - So, in BEMTREE-template
page
block you can access data bythis.ctx.data
. NB: you can findreq
(req.session
,req.path
and other useful stuff) object inthis.ctx.data.req
.