From 3b03410b3c7edff27c10cb9656f0a8ce6db728e4 Mon Sep 17 00:00:00 2001 From: reverend Date: Tue, 16 Mar 2021 14:27:34 +0100 Subject: [PATCH] Playground --- components/00_Tools/_bemGenerator.styl | 86 ++++++++++++++++++++++++-- components/01_Layouts/fan/_fan.styl | 27 ++++++++ 2 files changed, 108 insertions(+), 5 deletions(-) diff --git a/components/00_Tools/_bemGenerator.styl b/components/00_Tools/_bemGenerator.styl index fed3b87..c8e29ec 100644 --- a/components/00_Tools/_bemGenerator.styl +++ b/components/00_Tools/_bemGenerator.styl @@ -87,7 +87,6 @@ is_any_parent_nested() RV-Level(name_delimiter, allowed_parent_levels=null, selector_callback, squash_if_parent_nested=false) name = auto_name(name_delimiter) - p(called-from) not_in_parent = true for parent_level in allowed_parent_levels not_in_parent = not_in_parent && not_nested_in(parent_level) @@ -114,9 +113,6 @@ RV-Level(name_delimiter, allowed_parent_levels=null, selector_callback, squash_i // RV-Fan--horizontal RV-Fan--horizontal __ Base -- wurst // RV-BreakPoint__Item--outside RV-Fan--horizontal__Base RV-Fan--horizontal - - - RV-Block(name) .{name} {block} @@ -162,4 +158,84 @@ RV-Block--modifier() {block} RV-Squash() - {block} \ No newline at end of file + {block} + +filter(list, value) + filtered = () + for element in list + if element != value + push(filtered, element) + return filtered + + + +_level_types = { + '': 'block' + '__': 'element' + '--': 'modifier' +} + +get_first_level_name(mixin_name) + shortest_split = null + for delimiter, level_type in _level_types + if length(delimiter) > 0 + current_split = split(delimiter, mixin_name)[0] + if shortest_split == null || length(current_split) <= length(shortest_split) + shortest_split = current_split + + return shortest_split + +string_contains(smaller, greater) + if smaller == null || greater == null + return false + + if length(smaller) > length(greater) + return false + + p('%s'%smaller length('%s'%smaller)) + + for i in range(0, length(smaller)) + if smaller[i] != greater[i] + return false + return true + +is_contigious(call_stack) + for i in range(0, length(call_stack) - 1) + p(call_stack[i+1] call_stack[i]) + p(string_contains(call_stack[i+1], call_stack[i])) + if !call_stack[i+1] in call_stack[i] + return false + return true + +determine_level_type(mixin_name) + candidate = null + candidate_level = null + candidate_delimiter = null + + // This is why humanity is doomed + mixin_name = split('äöü', mixin_name)[0] + for delimiter, level in _level_types + if length(delimiter) <= 0 + splited_level = mixin_name + else + splited_level = split(delimiter, mixin_name)[-1] + if candidate == null || length(candidate) > length(splited_level) + candidate = splited_level + candidate_level = level + candidate_delimiter = delimiter + + return unquote(candidate) candidate_level unquote(candidate_delimiter) + +generate_selector(mixin_name) + block_name = get_first_level_name(mixin_name) + level_info = determine_level_type(mixin_name) + return '&%s%s' % (level_info[2] level_info[0]) + + +RV-BEM() + call_stack = filter(called-from, 'RV-BEM') + p(cs call_stack) + if is_contigious(call_stack) + {generate_selector(called-from[0])} + {block} + p('###') \ No newline at end of file diff --git a/components/01_Layouts/fan/_fan.styl b/components/01_Layouts/fan/_fan.styl index 13f1b23..85bc3a4 100644 --- a/components/01_Layouts/fan/_fan.styl +++ b/components/01_Layouts/fan/_fan.styl @@ -150,4 +150,31 @@ RV-Fan(base-height, base-width) RV-Fan--auto(--base-height, --base-width) RV-Fan--vertical(--base-height, --base-width) RV-Fan--horizontal(--base-height, --base-width) + + +RV-Fan--horizontal__Surface() + +RV-BEM() + --peter bernd + +RV-Fan--horizontal__Base--wurst() + +RV-BEM() + --fan wurst + +RV-Fan--horizontal__Base() + +RV-BEM() + RV-Fan--horizontal__Base--wurst() + RV-Fan--horizontal__Surface() + --wurst wasser + +RV-Fan--horizontal() + +RV-BEM() + RV-Fan--horizontal__Base() + --kaka pipi + +RV-Fan() + +RV-BEM() + RV-Fan--horizontal() + --blubb bernd + +RV-Fan() \ No newline at end of file