Simple-BEM-Structure Yeoman generator
npm install -g generator-sbs
To set prefered settings run subgenerator config
:
$ yo sbs:config
This generator helps to set following settings
allowed: ['classic', 'twoDashes', 'CamelCase', 'noUnderscores']
type: list
Depending on you answer you'll get:
Classic style
{
"example": "block-name__element-name_modifier-key_modifier-val",
"separatorForElement": "__",
"separatorForModifier": "_"
}
Two Dashes style
{
"example": "block-name__element-name--modifier-name",
"separatorForElement": "__",
"separatorForModifier": "--"
}
CamelCase style
{
"example": "BlockName__ElementName_modifierKey_modifierVal",
"separatorForElement": "__",
"separatorForModifier": "_"
}
"Sans underscore" style
{
"example": "blockName-elementName--modifierKey--modifierVal",
"separatorForElement": "-",
"separatorForModifier": "--"
}
default: false
type: confirm
Recommended file structure is:
block-a/
__elem-a/
_mod-a/
_mod_a/
block-b/
__elem-b/
_mod-b/
_mod-b/
But sometimes it's quite convenient to group some blocks, to put them in logical collection. For example to group blocks that related to forms, header or buttons:
forms--bem-collection
select/
__ietm/
_selected/
_short/
checkbox/
__icon/
_checked/
_theme-dark/
block-a/
__elem-a/
_mod-a/
_mod_a/
If you set this to true
, you'll be allowed to create and use collections.
Set suffix that will be added to all new collections. Also this suffix will be used to detedct existing collections.
default: --bem-collection
type: string
when: useCollections === true
Limitations:
- suffix should starts with
--
(will be added automatically if needed) - suffix can contains letters A-Z, numvers 0-9, dashes and underscores
- suffix can't be empty
type: string
Define "root" styles directory, for example src/styles
. Will be created automatically if doesn't exist.
allowed: ['scss', 'sass', 'sytl', 'less', 'custom']
type: list
Please select extension that is used by your preprocessor. If custom
is set, you'll be asked to define it.
type: string
Define "root" styles file (for expamle styles.scss
or app.styl
). It should be places in BEM root directory. Will be created automatically if needed.
After all needed parameters are set your .yo-rc.json
will be created.
Run generator:
$ yo sbs
Generated files will include special comments:
//<= bemBlocks =>
//<= endbemBlocks =>
//<= bemElements =>
//<= endbemElements =>
//<= bemModifiers =>
//<= endbemModifiers =>
All created blocks, elements or modifiers will be imported inside of these comments.
//<= bemBlocks =>
... // @import rules
//<= endbemBlocks =>
.block-name {
//<= bemElements =>
... // @import rules
//<= endbemElements =>
//<= bemModifiers =>
... // @import rules
//<= endbemModifiers =>
}
&__element {
//<= bemModifiers =>
... // @import rules
//<= endbemModifiers =>
}
&--modifier {
}
MIT License
Copyright (c) 2016 Denis Solovets
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.