Skip to content

This generator helps to create and support bem-structure for you project.

License

Notifications You must be signed in to change notification settings

solovets/generator-sbs

Repository files navigation

Generator-sbs

Simple-BEM-Structure Yeoman generator

Install

npm install -g generator-sbs

Configuration

To set prefered settings run subgenerator config:

$ yo sbs:config

This generator helps to set following settings

Naming convention

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": "--"
}

Use collections

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.

Collection suffix

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

BEM root directory

type: string

Define "root" styles directory, for example src/styles. Will be created automatically if doesn't exist.

Extension

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.

"Root" styles file

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.

Usage

Run generator:

$ yo sbs

Templates

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.

"Root" styles file

//<= bemBlocks =>
... // @import rules
//<= endbemBlocks =>

Block

.block-name {
    //<= bemElements =>
    ... // @import rules
    //<= endbemElements =>

    //<= bemModifiers =>
    ... // @import rules
    //<= endbemModifiers =>
}

Element

&__element {
    //<= bemModifiers =>
    ... // @import rules
    //<= endbemModifiers =>
}

Modifier

&--modifier {

}

License

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.

About

This generator helps to create and support bem-structure for you project.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published