as i discovered, this is pretty much worthless, good night ladies and germs
This commit is contained in:
parent
4991dd276b
commit
cb6f67676e
@ -6,8 +6,16 @@
|
||||
*/
|
||||
|
||||
_css-prefix = 'RV'
|
||||
_element-modifier = ()
|
||||
_additional-element-modifier-blocks = ()
|
||||
_global_scope = {
|
||||
_selector_blocks_to_generate: {}
|
||||
_element-modifier: ()
|
||||
_additional-element-modifier-blocks: ()
|
||||
_last_element_name: null
|
||||
_blocks_to_generate: ()
|
||||
_element_modifier_block_stack: ()
|
||||
_element_block_stack: ()
|
||||
_element_modifier_stack: {}
|
||||
}
|
||||
|
||||
/*
|
||||
* Gets the selector of the parent class
|
||||
@ -15,17 +23,19 @@ _additional-element-modifier-blocks = ()
|
||||
_get_parent_selector()
|
||||
return split(' ', selector())[-1]
|
||||
|
||||
|
||||
/*
|
||||
* Gets the selector of the current block
|
||||
*/
|
||||
_get_block_selector()
|
||||
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
|
||||
* Block according to BEM
|
||||
@ -33,7 +43,16 @@ _get_element_selector()
|
||||
RV-Block(name)
|
||||
.{_css-prefix}-{name}
|
||||
{block}
|
||||
|
||||
for name, element in _global_scope['_selector_blocks_to_generate']
|
||||
& &__{name}
|
||||
for current_block in element.block_list
|
||||
{current_block}
|
||||
for modifier_name, modifier_block_list in element.modifier_list
|
||||
&--{modifier_name}
|
||||
for current_block in modifier_block_list
|
||||
{current_block}
|
||||
|
||||
|
||||
/*
|
||||
* Generates a CSS class for an block modifier
|
||||
* according to BEM.
|
||||
@ -45,44 +64,32 @@ RV-Block__Modifier(name)
|
||||
&{_get_block_selector()}--{name}
|
||||
{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
|
||||
* according to BEM. Also minds the element modifiers
|
||||
* For more see RV-Element___Modifier
|
||||
*/
|
||||
RV-Element(name)
|
||||
block-selector = _get_block_selector()
|
||||
// Are we in a block?
|
||||
if block-selector != '&'
|
||||
//Create Selector and output the CSS for the element
|
||||
RV-Element(name)
|
||||
element_block_stack = _global_scope['_element_block_stack']
|
||||
append(element_block_stack, block)
|
||||
_global_scope['_element_block_stack'] = element_block_stack
|
||||
|
||||
//Detect if the selector will be generated
|
||||
//by an earlier call of RV-Element
|
||||
if not 'RV-Element' in called-from
|
||||
// Saving accumulated modifiers and blocks
|
||||
element = {}
|
||||
element['block_list'] = _global_scope['_element_block_stack']
|
||||
element['modifier_list'] = _global_scope['_element_modifier_stack']
|
||||
|
||||
//Detect if the selector will be generated
|
||||
//by an earlier call of RV-Element
|
||||
if 'RV-Element' in called-from
|
||||
_create_element(name, block)
|
||||
else
|
||||
{block-selector}__{name}
|
||||
_create_element(name, block)
|
||||
else
|
||||
warn('No block found. Creating One instead')
|
||||
+RV-Block(name)
|
||||
{block}
|
||||
//Reseting
|
||||
_global_scope['_element_block_stack'] = ()
|
||||
_global_scope['_element_modifier_stack'] = {}
|
||||
|
||||
//Saving element
|
||||
_global_scope['_selector_blocks_to_generate'][name] = element
|
||||
_global_scope['_last_element_name'] = name
|
||||
|
||||
/*
|
||||
* Generates a CSS class for an element modifier
|
||||
* according to BEM. These are ment to be part of the
|
||||
@ -93,27 +100,36 @@ RV-Element(name)
|
||||
* from RV-Element
|
||||
*/
|
||||
RV-Element__Modifier(name)
|
||||
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}{
|
||||
for current_block in block_list{
|
||||
counter = 0
|
||||
for fn in called-from
|
||||
if fn is 'RV-Element'
|
||||
counter += 1
|
||||
|
||||
{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, {
|
||||
callback: callback
|
||||
name: name
|
||||
block_list: block_list,
|
||||
})
|
||||
if counter <= 1
|
||||
element_modifier_block_stack = _global_scope['_element_modifier_block_stack']
|
||||
append(element_modifier_block_stack, block)
|
||||
_global_scope['_element_modifier_block_stack'] = element_modifier_block_stack
|
||||
|
||||
//Is this modifier beeing included by another modifier
|
||||
if not 'RV-Element__Modifier' in called-from
|
||||
//No
|
||||
//Is this modifier beeing called in in- or postfix
|
||||
if not 'RV-Element' in called-from
|
||||
//Yes
|
||||
last_element_name = _global_scope['_last_element_name']
|
||||
|
||||
//Accesing the last generated element and appending the modifier
|
||||
element = _global_scope['_selector_blocks_to_generate'][last_element_name]
|
||||
modifier_list = element['modifier_list']
|
||||
modifier_list[name] = _global_scope['_element_modifier_block_stack']
|
||||
element['modifier_list'] = modifier_list
|
||||
|
||||
_global_scope['_selector_blocks_to_generate'][last_element_name] = element
|
||||
else
|
||||
//No
|
||||
_global_scope['_element_modifier_stack'][name] = _global_scope['_element_modifier_block_stack']
|
||||
|
||||
_global_scope['_element_modifier_block_stack'] = ()
|
||||
else
|
||||
p('wurstwasser')
|
||||
|
Loading…
Reference in New Issue
Block a user