i have no clue what im doing ... da da da da

This commit is contained in:
reverend 2021-01-10 15:27:00 +01:00
parent e37315f90f
commit c3e69cd0cc
5 changed files with 139 additions and 54 deletions

View File

@ -6,15 +6,43 @@
*/ */
_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: {}
}
// Cache for Blocks _block_building_lane = ()
_last_block_name = null _element_building_lange = ()
_element_building_lane = {} _work_lane(lane, callback)
_element_block_stack = () l = length(lane)
for _ in (0..l)
piece = pop(lane)
callback(piece)
_block_modifier_building_lane = {} /*
_block_modifier_block_stack = () * Gets the selector of the parent class
*/
_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])
/* /*
@ -22,7 +50,17 @@ _block_modifier_block_stack = ()
* Block according to BEM * Block according to BEM
*/ */
RV-Block(name) RV-Block(name)
tow(name, block) .{name}
{block}
for element_name, element in _global_scope['_selector_blocks_to_generate']
& .{name}__{element_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}
/* /*
@ -30,8 +68,11 @@ RV-Block(name)
* according to BEM. * according to BEM.
*/ */
RV-Block__Modifier(name) RV-Block__Modifier(name)
attach('RV-Block', unquote('--' + name), block) if 'RV-Block__Modifier' in called-from
{block}
else
&{_get_block_selector()}--{name}
{block}
/* /*
* Generates an CSS class for an element * Generates an CSS class for an element
@ -39,12 +80,27 @@ RV-Block__Modifier(name)
* For more see RV-Element___Modifier * For more see RV-Element___Modifier
*/ */
RV-Element(name) RV-Element(name)
attach('RV-Block', unquote('__' + name), block) push(_global_scope['_element_block_stack'], block)
tow(name, 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
@ -54,5 +110,34 @@ RV-Element(name)
* from RV-Element * from RV-Element
*/ */
RV-Element__Modifier(name) RV-Element__Modifier(name)
attach('RV-Element', '--' + name, block) counter = 0
for fn in called-from
if fn is 'RV-Element'
counter += 1
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'] = ()

View File

@ -1,4 +1,3 @@
@import './_blockAppendix'
@import './_bemGenerator' @import './_bemGenerator'
@import './_selectorHook' @import './_selectorHook'
@import './_cssParameter' @import './_cssParameter'

View File

@ -79,6 +79,23 @@ _pop_stack(block_type=null)
else else
return () return ()
_add_to_lane(key, value, block_type=null)
if block_type == null
block_type = called-from[1]
if block_type in _lanes
lane = _lanes[block_type]
else
lane = {}
if key in lane
stack = lane[key]
else
stack = ()
push(stack, value)
lane[key] = stack
_lanes[block_type] = lane
_put_into_lane(key, value, block_type=null) _put_into_lane(key, value, block_type=null)
if block_type == null if block_type == null
@ -119,26 +136,19 @@ attach(parent_type, suffix, block)
// Is there a block to attach to // Is there a block to attach to
_last_parent_name = _get_last_name(parent_type) _last_parent_name = _get_last_name(parent_type)
if _last_parent_name != null if _last_parent_name != null
&.{_last_parent_name}{suffix} & .{_last_parent_name} .{_last_parent_name}{suffix}
--attach 'blubb'
{block} {block}
tow(name, block, block_type=null) tow(name, block, block_type=null)
if block_type == null // Determining if we are inside a block or after a block if block_type == null // Determining if we are inside a block or after a block
block_type = called-from[0] block_type = called-from[0]
if not block_type in _being_towed .{name}
prefix = '.'+name {block}
{prefix}
{block}
else
prefix = ''
{prefix}
if block_type in _lanes if block_type in _lanes
for suffix, block_list in _pop_lane(block_type) for suffix, block_list in _pop_lane(block_type)
p('name' name 'suffix' suffix) p(name suffix selector())
& {name}{suffix} &{name}{suffix}
for current_block in block_list for current_block in block_list
{current_block} {current_block}

View File

@ -126,18 +126,17 @@ RV-Fan()
RV-Fan--horizontal(base-height, base-width) RV-Fan--horizontal(base-height, base-width)
RV-Fan--auto(base-height, base-width) RV-Fan--auto(base-height, base-width)
*/ */
+RV-Block('Fächer') RV-Test()
--wurst yeet +RV-Block('Fächer')
RV-Fan__Surface(50px, 50px) --wurst yeet
+RV-Element('BLubb') RV-Fan__Surface(50px, 50px)
color black +RV-Element('susses')
--blubb wasser +RV-Element('BLubb')
color black
--blubb wasser
+RV-Element__Modifier('Wurst') +RV-Element__Modifier('pp')
--wurst 'wurst' +RV-Element__Modifier('Wurst')
--wasser 'wurst'
+RV-Element('Affter') .wurstwasser
--hasi 'lein' RV-Test()
+RV-Block__Modifier('Mafter')
--blubb 'bernd'

View File

@ -318,23 +318,15 @@
bottom: 0; bottom: 0;
right: 0; right: 0;
} }
.Fächer { .wurstwasser .Fächer {
--wurst: yeet; --wurst: yeet;
} }
.Fächer BLubb--Wurst { .wurstwasser .Fächer .Fächer__BLubb {
--wurst: 'wurst';
}
.Fächer Fächer__BLubb {
color: #000; color: #000;
--blubb: wasser; --blubb: wasser;
} }
.Fächer__Affter { .wurstwasser .Fächer .Fächer__BLubb--pp {
--attach: 'blubb'; --wasser: 'wurst';
--hasi: 'lein';
}
.Fächer--Mafter {
--attach: 'blubb';
--blubb: 'bernd';
} }
.RV-FlexGrid__Container { .RV-FlexGrid__Container {
display: grid; display: grid;