Technologies API
The package includes the following technologies:
For building BH templates:
For generating HTML:
bh-bundle
Collects bh.js
block and core files in a single file – the ?. bh.js
bundle, which is used both for working in a browser and in Node.js. After compiling, it does not require connecting the template source files.
It has support for the YModules modular system and partial support for CommonJS, since require
will not work correctly in bh.js
files.
If the executable environment doesn't have any modular systems, the module will be provided to the BH
global variable.
Options
Options are specified in the configuration file (.enb/make.js).
target
Type: String
. Default: ?.bh.js
.
The name of the compiled file for saving the build result with the necessary bh.js
project files.
filesTarget
Type: String
. Default: ?.files
.
The name of the target for accessing the list of source files for the build. The list of files is provided by the files technology in the enb-bem-techs package.
sourceSuffixes
Type: String | String[]
. Default: ['bh.js']
.
The file suffixes to use for filtering BH template files for the build.
bhFilename
Type: String
. Default: require.resolve('bh/lib/bh.js')
.
Path to the file with the BH engine.
Use this option if you need a non-standard version of the BH template engine.
Important! The bh-bundle technology is only guaranteed to work correctly with the BH template engine version 4.1.0
sourcemap
Type: Boolean
. Default: false
.
Creates source maps with information about the source files. The maps are included in a compiled file called ? .files
– they are not stored in separate files with a .map
extension.
requires
Type: Object
. Default: {}
.
Specifies the names or paths to connect external libraries to the bh.lib
namespace – bh.lib.name
.
For information on how it works, see the section Connecting third-party libraries.
mimic
Type: String | String[]
. Default: ['bh']
.
Specifies the names of the new variables.
For information on how it works, see the section BEMHTML Mimicry.
scope
Type: String
. Default: template
.
Specifies the scope of the source code for the templates.
Possible values:
template
– Isolates template execution.global
– Enables you to execute templates in a shared scope.
bhOptions
Type: Object
. Default: {}
.
Configures the BH template engine using the passed options.
Possible options are described in the template engine documentation.
Example
var BHBundleTech = require('enb-bh/techs/bh-bundle'),
FileProvideTech = require('enb/techs/file-provider'),
bemTechs = require('enb-bem-techs');
module.exports = function(config) {
config.node('bundle', function(node) {
// Getting the FileList
node.addTechs([
[FileProvideTech, { target: '?.bemdecl.js' }],
[bemTechs.levels, { levels: ['blocks'] }],
[bemTechs.deps],
[bemTechs.files]
]);
// Creating a BH file
node.addTech(BHBundleTech);
node.addTarget('?.bh.js');
});
};
bh-commonjs
Collects bh.js
block files in a single file – the ?.bh.js
bundle, which is used both for working in Node.js. After the build, all the source files that are connected using require
must be present.
The dependencies are added to the templates using require
. The paths are processed relative to the file that specifies require
.
The result of the build is a bh.js
file that connects the necessary bh.js
source files and the core file from node_modules
.
Options
Options are specified in the configuration file (.enb/make.js).
target
Type: String
. Default: ?.bh.js
.
The name of the target file for saving the build result of the necessary project bh.js
files – the compiled ?.bh.js
file.
filesTarget
Type: String
. Default: ?.files
.
The name of the target for accessing the list of source files for the build. The file list is provided by the files technology in the enb-bem-techs package.
sourceSuffixes
Type: String | String[]
. Default: ['bh.js']
.
The file suffixes to use for filtering BH template files for the build.
bhFilename
Type: String
. Default: require.resolve('bh/lib/bh.js')
.
Path to the file with the BH engine.
Use this option if you need a non-standard version of the BH template engine.
Important! The bh-commonjs technology is only guaranteed to work correctly with the BH template engine version 4.1.0
and later.
devMode
Type: Boolean
. Default: true
.
Build mode in which each new connection of the build file initiates a reset of therequire
cache for all internal files. This allows you to see changes in templates without restarting Node.js.
mimic
Type: String | Array
. Default: ['bh']
.
Specifies the names of the new variables.
For information on how it works, see the section BEMHTML Mimicry.
bhOptions
Type: Object
. Default: {}
.
Configures the BH template engine using the passed options.
Possible options are described in the template engine documentation.
Example
var BHCommonJSTech = require('enb-bh/techs/bh-commonjs'),
FileProvideTech = require('enb/techs/file-provider'),
bemTechs = require('enb-bem-techs');
module.exports = function(config) {
config.node('bundle', function(node) {
// Getting the FileList
node.addTechs([
[FileProvideTech, { target: '?.bemdecl.js' }],
[bemTechs.levels, { levels: ['blocks'] }],
[bemTechs.deps],
[bemTechs.files]
]);
// Building the BH file
node.addTech(BHCommonJSTech);
node.addTarget('?.bh.js');
});
};
bemjson-to-html
Intended for building an HTML file. Processes BEMJSON and a compiled ?.bh.js
file (resulting from bh-bundle or bh-commonjs technologies) in order to get HTML.
Options
Options are specified in the configuration file (.enb/make.js).
bhFile
Type: String
. Default: ?.bh.js
.
The name of the file that contains the template that was compiled using one of the technologies (bh-bundle or bh-commonjs). Used for converting BEMJSON to HTML.
bemjsonFile
Type: String
. Default: ?.bemjson.js
.
The name of the BEMJSON file to apply the compiled ?.bh.js
template to (resulting from bh-bundle or bh-commonjs technologies) in order to get HTML.
target
Type: String
. Default: ?.html
.
The HTML file is the result of applying the compiled template to the specified BEMJSON file.
Example
var BemjsonToHtmlTech = require('enb-bh/techs/bemjson-to-html'),
BHCommonJSTech = require('enb-bh/techs/bh-commonjs'),
FileProvideTech = require('enb/techs/file-provider'),
bemTechs = require('enb-bem-techs');
module.exports = function(config) {
config.node('bundle', function(node) {
// Getting the BEMJSON file
node.addTech([FileProvideTech, { target: '?.bemjson.js' }]);
// Getting the FileList
node.addTechs([
[bemTechs.levels, { levels: ['blocks'] }],
[bemTechs.bemjsonToBemdecl],
[bemTechs.deps],
[bemTechs.files]
]);
// Building the BH file
node.addTech(BHCommonJSTech);
node.addTarget('?.bh.js');
// Creating the HTML file
node.addTech(BemjsonToHtmlTech);
node.addTarget('?.html');
});
};