-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implemented a lite version of the bem-cn
- Loading branch information
1 parent
4a0a01c
commit 1044fa8
Showing
5 changed files
with
133 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
.DS_Store | ||
.idea | ||
*.iml | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
"use strict"; | ||
|
||
var bemClassName = require('bem-cn').default; | ||
|
||
module.exports = function (blockName) { | ||
var b = bemClassName(blockName); | ||
|
||
function element(elementName, modifiers, mixin) { | ||
// normalize arguments | ||
if (typeof elementName === 'string') { | ||
// going to create an element | ||
if (typeof modifiers === 'string') { | ||
mixin = modifiers; | ||
modifiers = null; | ||
} | ||
} else { | ||
// going to create a block | ||
mixin = modifiers; | ||
modifiers = null; | ||
} | ||
|
||
var result = b(elementName, modifiers); | ||
|
||
return (mixin ? result.mix(mixin) : result).toString(); | ||
} | ||
|
||
element.builder = function () { | ||
return b; | ||
}; | ||
|
||
return element; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
"use strict"; | ||
|
||
require('should'); | ||
|
||
var generator = require('../index'); | ||
|
||
var b = generator('block'); | ||
|
||
describe('module', function () { | ||
it('should generate block', function () { | ||
var block = b(); | ||
|
||
block.should.equal('block'); | ||
}); | ||
|
||
it('should generate block with modifier', function () { | ||
var block = b({modifier: true}); | ||
|
||
block.should.equal('block block_modifier'); | ||
}); | ||
|
||
it('should generate block with modifier and value', function () { | ||
var block = b({modifier: 'value'}); | ||
|
||
block.should.equal('block block_modifier_value'); | ||
}); | ||
|
||
it('should generate block with mixin', function () { | ||
var block = b(null, 'mixin'); | ||
|
||
block.should.equal('block mixin'); | ||
}); | ||
|
||
it('should generate block with modifier and mixin', function () { | ||
var block = b({modifier: 'value'}, 'mixin'); | ||
|
||
block.should.equal('block block_modifier_value mixin'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
"use strict"; | ||
|
||
require('should'); | ||
|
||
var generator = require('../index'); | ||
|
||
var b = generator('block'); | ||
|
||
describe('module', function () { | ||
it('should generate element', function () { | ||
var element = b('element'); | ||
|
||
element.should.equal('block__element'); | ||
}); | ||
|
||
it('should generate element with modifier', function () { | ||
var element = b('element', {modifier: true}); | ||
|
||
element.should.equal('block__element block__element_modifier'); | ||
}); | ||
|
||
it('should generate element with modifier and value', function () { | ||
var element = b('element', {modifier: 'value'}); | ||
|
||
element.should.equal('block__element block__element_modifier_value'); | ||
}); | ||
|
||
it('should generate element with mixin', function () { | ||
var element = b('element', 'mixin'); | ||
|
||
element.should.equal('block__element mixin'); | ||
}); | ||
|
||
it('should generate element with modifier and mixin', function () { | ||
var element = b('element', {modifier: 'value'}, 'mixin'); | ||
|
||
element.should.equal('block__element block__element_modifier_value mixin'); | ||
}); | ||
}); |