Advanced BEM generator with overridung
This commit is contained in:
parent
fff7e73064
commit
a1c4a6f883
@ -7,6 +7,7 @@
|
|||||||
|
|
||||||
_css-prefix = 'RV'
|
_css-prefix = 'RV'
|
||||||
_element-modifier = ()
|
_element-modifier = ()
|
||||||
|
_additional-element-modifier-blocks = ()
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Gets the selector of the parent class
|
* Gets the selector of the parent class
|
||||||
@ -20,6 +21,11 @@ _get_parent_selector()
|
|||||||
_get_block_selector()
|
_get_block_selector()
|
||||||
return unquote(split('__', _get_parent_selector())[0])
|
return unquote(split('__', _get_parent_selector())[0])
|
||||||
|
|
||||||
|
_get_element_selector()
|
||||||
|
p(_get_parent_selector())
|
||||||
|
element--modifier = split('__', _get_parent_selector())[1]
|
||||||
|
return unquote(split('--', element--modifier)[0])
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Generates a CSS class for an
|
* Generates a CSS class for an
|
||||||
* Block according to BEM
|
* Block according to BEM
|
||||||
@ -33,9 +39,28 @@ RV-Block(name)
|
|||||||
* according to BEM.
|
* according to BEM.
|
||||||
*/
|
*/
|
||||||
RV-Block__Modifier(name)
|
RV-Block__Modifier(name)
|
||||||
|
if 'RV-Block__Modifier' in called-from
|
||||||
|
{block}
|
||||||
|
else
|
||||||
&{_get_block_selector()}--{name}
|
&{_get_block_selector()}--{name}
|
||||||
{block}
|
{block}
|
||||||
|
|
||||||
|
_create_element(name, block)
|
||||||
|
{block}
|
||||||
|
// Checking for modifiers
|
||||||
|
l = length(_element-modifier) - 1
|
||||||
|
for i in range(0, l)
|
||||||
|
modifier = pop(_element-modifier)
|
||||||
|
callback = modifier['callback']
|
||||||
|
// Calling the modifiers block,
|
||||||
|
// passing the name of the element
|
||||||
|
callback(
|
||||||
|
element: name,
|
||||||
|
name: modifier['name'],
|
||||||
|
block_list: modifier['block_list']
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Generates an CSS class for an element
|
* Generates an CSS class for an element
|
||||||
* according to BEM. Also minds the element modifiers
|
* according to BEM. Also minds the element modifiers
|
||||||
@ -46,21 +71,14 @@ RV-Element(name)
|
|||||||
// Are we in a block?
|
// Are we in a block?
|
||||||
if block-selector != '&'
|
if block-selector != '&'
|
||||||
//Create Selector and output the CSS for the element
|
//Create Selector and output the CSS for the element
|
||||||
{block-selector}__{name}
|
|
||||||
{block}
|
|
||||||
|
|
||||||
// Checking for modifiers
|
//Detect if the selector will be generated
|
||||||
l = length(_element-modifier) - 1
|
//by an earlier call of RV-Element
|
||||||
for i in range(0, l)
|
if 'RV-Element' in called-from
|
||||||
modifier = pop(_element-modifier)
|
_create_element(name, block)
|
||||||
callback = modifier['callback']
|
else
|
||||||
// Calling the modifiers block,
|
{block-selector}__{name}
|
||||||
// passing the name of the element
|
_create_element(name, block)
|
||||||
callback(
|
|
||||||
element: name,
|
|
||||||
name: modifier['name'],
|
|
||||||
modifier_block: modifier['block']
|
|
||||||
)
|
|
||||||
else
|
else
|
||||||
warn('No block found. Creating One instead')
|
warn('No block found. Creating One instead')
|
||||||
+RV-Block(name)
|
+RV-Block(name)
|
||||||
@ -75,13 +93,27 @@ RV-Element(name)
|
|||||||
* from RV-Element
|
* from RV-Element
|
||||||
*/
|
*/
|
||||||
RV-Element__Modifier(name)
|
RV-Element__Modifier(name)
|
||||||
callback = @(element, name, modifier_block){
|
if 'RV-Element__Modifier' in called-from
|
||||||
|
//What the actual fuch this language is to utterly buggy
|
||||||
|
push(_additional-element-modifier-blocks, @block{block})
|
||||||
|
else
|
||||||
|
callback = @(element, name, block_list){
|
||||||
&{_get_block_selector()}__{element}--{name}{
|
&{_get_block_selector()}__{element}--{name}{
|
||||||
{modifier_block}
|
for current_block in block_list{
|
||||||
|
|
||||||
|
{current_block}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
block_list = ()
|
||||||
|
push(block_list, @block{block})
|
||||||
|
l = length(_additional-element-modifier-blocks)
|
||||||
|
for i in range(0, l)
|
||||||
|
b = pop(_additional-element-modifier-blocks)
|
||||||
|
push(block_list, b)
|
||||||
|
|
||||||
push(_element-modifier, {
|
push(_element-modifier, {
|
||||||
callback: callback
|
callback: callback
|
||||||
name: name
|
name: name
|
||||||
block: block,
|
block_list: block_list,
|
||||||
})
|
})
|
Loading…
Reference in New Issue
Block a user