new attempt
This commit is contained in:
parent
b8be7a8ede
commit
d07b14f879
@ -6,43 +6,15 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
_css-prefix = 'RV'
|
_css-prefix = 'RV'
|
||||||
_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: {}
|
|
||||||
}
|
|
||||||
|
|
||||||
_block_building_lane = ()
|
// Cache for Blocks
|
||||||
_element_building_lange = ()
|
_last_block_name = null
|
||||||
|
|
||||||
_work_lane(lane, callback)
|
_element_building_lane = {}
|
||||||
l = length(lane)
|
_element_block_stack = ()
|
||||||
for _ in (0..l)
|
|
||||||
piece = pop(lane)
|
|
||||||
callback(piece)
|
|
||||||
|
|
||||||
/*
|
_block_modifier_building_lane = {}
|
||||||
* Gets the selector of the parent class
|
_block_modifier_block_stack = ()
|
||||||
*/
|
|
||||||
_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()
|
|
||||||
element--modifier = split('__', _get_parent_selector())[1]
|
|
||||||
return unquote(split('--', element--modifier)[0])
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -50,21 +22,7 @@ _get_element_selector()
|
|||||||
* Block according to BEM
|
* Block according to BEM
|
||||||
*/
|
*/
|
||||||
RV-Block(name)
|
RV-Block(name)
|
||||||
.{name}
|
tow(name, block)
|
||||||
push(_block_building_lane, {
|
|
||||||
elements: {}
|
|
||||||
block_modifiers: {}
|
|
||||||
})
|
|
||||||
{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}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -72,11 +30,25 @@ RV-Block(name)
|
|||||||
* according to BEM.
|
* according to BEM.
|
||||||
*/
|
*/
|
||||||
RV-Block__Modifier(name)
|
RV-Block__Modifier(name)
|
||||||
if 'RV-Block__Modifier' in called-from
|
// Determining if we are inside a block or after a block
|
||||||
{block}
|
call_stack = _call_stack_till_first_block()
|
||||||
|
if 'RV-Block' in call_stack
|
||||||
|
// We are called inside a block
|
||||||
|
push(_block_modifier_block_stack, @block{block})
|
||||||
|
|
||||||
|
//Detect if the selector will be generated
|
||||||
|
//by an earlier call of RV-Element
|
||||||
|
if not 'RV-Block__Modifier' in call_stack
|
||||||
|
block_list = _pop_stack(_block_modifier_block_stack)
|
||||||
|
_block_modifier_building_lane[name] = {
|
||||||
|
block_list: block_list
|
||||||
|
}
|
||||||
else
|
else
|
||||||
&{_get_block_selector()}--{name}
|
// We are not called inside a block
|
||||||
{block}
|
// Is there a block to attach to
|
||||||
|
if _last_block_name != null
|
||||||
|
.{_last_block_name}--{name}
|
||||||
|
{block}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Generates an CSS class for an element
|
* Generates an CSS class for an element
|
||||||
@ -84,32 +56,11 @@ RV-Block__Modifier(name)
|
|||||||
* For more see RV-Element___Modifier
|
* For more see RV-Element___Modifier
|
||||||
*/
|
*/
|
||||||
RV-Element(name)
|
RV-Element(name)
|
||||||
// Is there a block to build
|
attach('RV-Block', unquote('__' + name), block)
|
||||||
block_index = (index(called-from, 'RV-Block'))
|
|
||||||
p(called-from block_index slice(called-from, 0, block_index))
|
|
||||||
|
|
||||||
if length(_block_building_lane) >= 1
|
|
||||||
push(_block_building_lane, block)
|
|
||||||
|
|
||||||
current_block = _block_building_lane[-1]
|
|
||||||
|
|
||||||
//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']
|
|
||||||
|
|
||||||
//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
|
|
||||||
|
|
||||||
/*
|
|
||||||
|
|
||||||
|
/* p(_block_building_lane)
|
||||||
* Generates a CSS class for an element modifier
|
* Generates a CSS class for an element modifier
|
||||||
* according to BEM. These are ment to be part of the
|
* according to BEM. These are ment to be part of the
|
||||||
* content block of an element and since child-mixins
|
* content block of an element and since child-mixins
|
||||||
|
Loading…
Reference in New Issue
Block a user