(sails >= 0.11)
npm i sails-hook-bem-render --save
res.render(data)
(sails < 0.11) also needs explicit hooks declaration:
bem-render
folder in api/hooks
index.js
file in api/hooks/bem-render/
api/hooks/bem-render/index.js
this:
module.exports = require('sails-hook-bem-render');
For example project see sails-bem-project-stub.
/views/common
directory for BEM blocks./views/.enb
directory with make-config file for enb
assembler.
You can copy config from sails-bem-project-stub/frontend/.enb/make.js. Notice: there is only desktop
config yet./views/desktop.bundles/index/index.bemdecl.js
file – dependency declaration for enb
assembler:
exports.blocks = [
{block: 'page'} // Other dependencies will be declare in `page` block.
];
"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"
}
node_modules/.bin/enb make -d views --no-cache
. It will compile BEMTREE, BEMHTML, assemble js, CSS into views/desktop.bundles/merged
folder.page
block you can access data by this.ctx.data
.
NB: you can find req
(req.session
, req.path
and other useful stuff) object in this.ctx.data.req
.