From e8609fe833cd322cd2d7ead744a0d91547e34d27 Mon Sep 17 00:00:00 2001 From: reverend Date: Sun, 17 Jan 2021 16:33:09 +0100 Subject: [PATCH] Alias Problems and Optin --- components/00_Global/_bemGenerator.styl | 71 +++++++++++++++++-------- 1 file changed, 48 insertions(+), 23 deletions(-) diff --git a/components/00_Global/_bemGenerator.styl b/components/00_Global/_bemGenerator.styl index f86399a..03e51f6 100644 --- a/components/00_Global/_bemGenerator.styl +++ b/components/00_Global/_bemGenerator.styl @@ -52,13 +52,20 @@ is_direct_descendant_of_block() return false return true +/* + * Checks if we are called inside a block + */ +is_in_block() + return 'RV-Block' in called-from + /* * Taking the currently stashed names, mapping * them to the given name under the called parent * (using called-from) and returning the stashed blocks */ -generate_aliases(actual_name) - level_type = split(' ', called-from)[0] +generate_aliases(actual_name, level_type=null) + if level_type == null + level_type = split(' ', called-from)[0] if actual_name == null if length(_block.alias.stash[level_type]) > 2 actual_name = _block.alias.stash[level_type][-1].name @@ -82,22 +89,29 @@ generate_aliases(actual_name) * (using called-from). Returning the given name * when no alias is found */ -resolve_alias(name) - level_type = split(' ', called-from)[0] +resolve_alias(name, level_type=null) + if level_type == null + level_type = split(' ', called-from)[0] if level_type+':'+name in _block.alias.map return _block.alias.map[level_type+':'+name] else return name +/* + * Renders an element modifier + */ render_element_modifier(modifier) - &--{resolve_alias(modifier.name)} + &--{resolve_alias(modifier.name, 'RV-Element__Modifier')} foreach(modifier.blocks, @(block){ {block} }) +/* + * Renders an element + */ render_element(element) - &__{resolve_alias(element.name)} + &__{resolve_alias(element.name, 'RV-Element')} foreach(element.blocks, @(block){ {block} }) @@ -105,8 +119,11 @@ render_element(element) render_element_modifier(modifier) }) +/* + * Renders an block modifier, + */ render_block_modifier(modifier) - &--{resolve_alias(modifier.name)} + &--{resolve_alias(modifier.name, 'RV-Block__Modifier')} foreach(modifier.blocks, @(block){ {block} }) @@ -123,22 +140,31 @@ render_block_modifier(modifier) * (See generate_aliases) */ RV-Element--name(name) - push(_block.alias.stash.RV-Element, { - name: name - block: block - }) + if 'RV-Element' in called-from + push(_block.alias.stash.RV-Element, { + name: name + block: block + }) + else + {block} RV-Element__Modifier--name(name) - push(_block.alias.stash.RV-Element__Modifier, { - name: name - block: block - }) + if 'RV-Element__Modifier' in called-from + push(_block.alias.stash.RV-Element__Modifier, { + name: name + block: block + }) + else + {block} RV-Block__Modifier--name(name) - push(_block.alias.stash.RV-Block__Modifier, { - name: name - block: block - }) + if 'RV-Block__Modifier' in called-from + push(_block.alias.stash.RV-Block__Modifier, { + name: name + block: block + }) + else + {block} RV-Block(block_name) @@ -149,11 +175,12 @@ RV-Block(block_name) }) foreach(_block.elements, @(element){ render_element(element) - }) + }) + + reset_block() RV-Block__Modifier(modifier_name=null) - modifier_name = resolve_alias(modifier_name) blocks = generate_aliases(modifier_name) modifier_name = blocks.name blocks = blocks.blocks @@ -169,7 +196,6 @@ RV-Block__Modifier(modifier_name=null) push(_block.block_modifiers, modifier) RV-Element(element_name=null) - element_name = resolve_alias(element_name) blocks = generate_aliases(element_name) element_name = blocks.name @@ -190,7 +216,6 @@ RV-Element(element_name=null) RV-Element__Modifier(modifier_name=null) - modifier_name = resolve_alias(modifier_name) blocks = generate_aliases(modifier_name) modifier_name = blocks.name blocks = blocks.blocks