From baf47d315e9ca2611713be1f3e124898819c5767 Mon Sep 17 00:00:00 2001 From: reverend Date: Tue, 9 Mar 2021 12:38:47 +0100 Subject: [PATCH] Change: alias stack for each level type, leads to consistent 'modifier last' rule --- components/00_Tools/_bemGenerator.styl | 32 ++++++++++++++++++-------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/components/00_Tools/_bemGenerator.styl b/components/00_Tools/_bemGenerator.styl index 1a298f6..7a535eb 100644 --- a/components/00_Tools/_bemGenerator.styl +++ b/components/00_Tools/_bemGenerator.styl @@ -1,6 +1,7 @@ _bem_context = { _alias_map: {} - _alias_stack: () () + _alias_stacks: { + } } work_stack(stack, callback) @@ -12,24 +13,37 @@ work_stack(stack, callback) set_alias(alias, name) if name != null && alias != null _bem_context._alias_map[alias] = name - + lookup_alias(name) if name in _bem_context._alias_map return _bem_context._alias_map[name] else return name + + store_alias(alias) + level_name = called-from[1] + if not level_name in _bem_context._alias_stacks + _bem_context._alias_stacks[level_name] = () () + if alias != null - push(_bem_context._alias_stack, alias) + push(_bem_context._alias_stacks[level_name], alias) pop_last_alias() - return pop(_bem_context._alias_stack) - + level_name = called-from[1] + if not level_name in _bem_context._alias_stacks + return null + return pop(_bem_context._alias_stacks[level_name]) + apply_alias_stack(name) - work_stack(_bem_context._alias_stack, @(element){ - set_alias(element, name) - }) + level_name = called-from[1] + if level_name in _bem_context._alias_stacks + work_stack(_bem_context._alias_stacks[level_name], @(element){ + set_alias(element, name) + }) + + auto_name(delimiter) if length(called-from) < 3 @@ -87,7 +101,7 @@ RV-Block(name) {block} _bem_context._alias_map = {} - _bem_context._alias_stack = () () + _bem_context._alias_stacks = {} RV-Element(name=null) +RV-Level(name, '__', ('RV-Block' 'RV-Block--modifier'), @(name){