From 3233b7bcffa79e437600cb25197794de4132b5f0 Mon Sep 17 00:00:00 2001 From: reverend Date: Sat, 9 Jan 2021 16:28:59 +0100 Subject: [PATCH] astracting appending elemnts to each other --- components/00_Global/_blockAppendix.styl | 138 +++++++++++++++++++++++ 1 file changed, 138 insertions(+) create mode 100644 components/00_Global/_blockAppendix.styl diff --git a/components/00_Global/_blockAppendix.styl b/components/00_Global/_blockAppendix.styl new file mode 100644 index 0000000..c11152a --- /dev/null +++ b/components/00_Global/_blockAppendix.styl @@ -0,0 +1,138 @@ +_lanes = {} +_stacks = {} +_last_name = {} + +_reset_last_name(block_type=null) + if block_type == null + block_type = called-from[1] + + if block_type in _last_name + remove(_last_name, block_type) + + +_set_last_name(name, block_type=null) + if block_type == null + block_type = called-from[1] + + _last_name[block_type] = name + +_get_last_name(block_type) + if block_type == null + block_type = called-from[1] + + if block_type in _last_name + return _last_name[block_type] + else + return null + +_current_block_type() + return called-from[1] + +_call_stack_till_first(block_type) + striped = slice(called-from, 2) + block_index = (index(striped, block_type)) + if block_index == null + if length(striped) <= 1 + return (striped ()) + return slice(striped, 1) + stack = () + for i in (0..block_index) + push(stack, striped[i]) + return stack + + +_push_onto_stack(block, block_type=null) + if block_type == null + block_type = called-from[1] + + if block_type in _stacks + stack = _stacks[block_type] + else + stack = () + + push(stack, block) + _stacks[block_type] = stack + +_pop_from_stack(block_type=null) + if block_type == null + block_type = called-from[1] + + if block_type in _stacks + stack = _stacks[block_type] + b = pop(stack) + if length(stack) > 0 + _stacks[block_type] + else + remove(_stacks, block_type) + return b + return null + +_pop_stack(block_type=null) + if block_type == null + block_type = called-from[1] + + if block_type in _stacks + stack = _stacks[block_type] + remove(_stacks, block_type) + return stack + else + return () + + +_put_into_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 = {} + + lane[key] = value + _lanes[block_type] = lane + +_pop_lane(block_type=null) + if block_type == null + block_type = called-from[1] + + if block_type in _lanes + lane = _lanes[block_type] + remove(_lanes, block_type) + return lane + else + return {} + +attach(parent_type, suffix, block) + call_stack = _call_stack_till_first(parent_type) + if parent_type in call_stack + // We are called inside a block + _push_onto_stack(block) + //Detect if the selector will be generated + //by an earlier call of RV-Element + _current_block = _current_block_type() + if not _curent_block in (call_stack) + block_list = _pop_stack() + _put_into_lane(suffix, block_list, parent_type) + else + // We are not called inside a block + // Is there a block to attach to + _last_parent_name = _get_last_name(parent_type) + if _last_parent_name != null + & .{_last_parent_name}{suffix} + {block} + +tow(name, block, block_type=null) + if block_type == null + block_type = called-from[0] + + .{name} + {block} + + if block_type in _lanes + for suffix, block_list in _pop_lane(block_type) + & .{name}{suffix} + for b in block_list + {b} + + _set_last_name(name, block_type) +