Renaming Global to Tools

This commit is contained in:
2021-01-17 22:48:54 +01:00
parent 78902c530f
commit 4ac61a8224
7 changed files with 1 additions and 1 deletions

View File

@@ -0,0 +1,9 @@
RV-Reset()
margin 0
padding 0
top 0
bottom 0
left 0
right 0
border none
gap 0

View File

@@ -0,0 +1,249 @@
// Storing the currents block properties and attributes
// to generate the block afterwards
/*
* A method for iterating throug a
* list/array safely since this language sucks
* realy bad https://github.com/stylus/stylus/issues/1440
*/
foreach(list, callback)
for entry in list
if entry != ()
callback(entry)
create_list()
return () ()
_block = {}
reset_block()
_block.elements = create_list()
_block.block_modifiers = create_list()
_block.alias = {
map: {}
stash: {
RV-Element: create_list()
RV-Element__Modifier: create_list()
RV-Block__Modifier: create_list()
}
}
_block.modifier_stash = create_list()
_block.element_stash = create_list()
// Calling the function to initiate the block
// for first use
reset_block()
_bem_mixins = 'RV-Block','RV-Element','RV-Modifier','RV-Element__Modifier','RV-Block__Modifier'
/*
* Checks if the caller of this funcion is a direct
* descendant of RV-Block. Checks for BEM-Mixins only.
* If any other function or mixin is between the last
* block and the caller, it will still count as an direct
* descendant of RV-Block
*/
is_direct_descendant_of_block()
block_index = index(called-from, 'RV-Block') - 1
if block_index <= 0
return true
for i in (1..block_index)
if called-from[i] in _bem_mixins
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=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
else
warn('No name found for '+called-from)
blocks = ()
foreach(_block.alias.stash[level_type], @(alias){
_block.alias.map[level_type+':'+alias.name] = actual_name
push(blocks, alias.block)
})
_block.alias.stash[level_type] = create_list()
return {
name: actual_name
blocks: blocks
}
/*
* Resolving the alias according to the level type
* (using called-from). Returning the given name
* when no alias is found
*/
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, 'RV-Element__Modifier')}
foreach(modifier.blocks, @(block){
{block}
})
/*
* Renders an element
*/
render_element(element)
&__{resolve_alias(element.name, 'RV-Element')}
foreach(element.blocks, @(block){
{block}
})
foreach(element.modifiers, @(modifier){
render_element_modifier(modifier)
})
/*
* Renders an block modifier,
*/
render_block_modifier(modifier)
&--{resolve_alias(modifier.name, 'RV-Block__Modifier')}
foreach(modifier.blocks, @(block){
{block}
})
& ^[-2..-2]{
foreach(modifier.elements, @(element){
render_element(element)
})
}
RV-Squash()
{block}
/*
* Stashing the given block under the given
* name to be aliased by a late level
* (See generate_aliases)
*/
RV-Element--name(name)
if 'RV-Squash' in called-from
{block}
else
if 'RV-Element' in called-from
push(_block.alias.stash.RV-Element, {
name: name
block: block
})
else
{block}
RV-Element__Modifier--name(name)
if 'RV-Squash' in called-from
{block}
else
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)
if 'RV-Squash' in called-from
{block}
else
if 'RV-Block__Modifier' in called-from
push(_block.alias.stash.RV-Block__Modifier, {
name: name
block: block
})
else
{block}
RV-Block(block_name)
& .{block_name}
{block}
foreach(_block.block_modifiers, @(modifier){
render_block_modifier(modifier)
})
foreach(_block.elements, @(element){
render_element(element)
})
reset_block()
RV-Block__Modifier(modifier_name=null)
if 'RV-Squash' in called-from
{block}
else
blocks = generate_aliases(modifier_name)
modifier_name = blocks.name
blocks = blocks.blocks
push(blocks, block)
modifier = {
name: modifier_name
blocks: blocks
elements: _block.element_stash
}
_block.element_stash = create_list()
push(_block.block_modifiers, modifier)
RV-Element(element_name=null)
if 'RV-Squash' in called-from
{block}
else
blocks = generate_aliases(element_name)
element_name = blocks.name
blocks = blocks.blocks
push(blocks, block)
element = {
name: element_name
blocks: blocks
modifiers: _block.modifier_stash
}
_block.modifier_stash = create_list()
if is_direct_descendant_of_block()
push(_block.elements, element)
else
push(_block.element_stash, element)
RV-Element__Modifier(modifier_name=null)
if 'RV-Squash' in called-from
{block}
else
blocks = generate_aliases(modifier_name)
modifier_name = blocks.name
blocks = blocks.blocks
push(blocks, block)
modifier = {
name: modifier_name
blocks: blocks
}
push(_block.modifier_stash, modifier)

View File

@@ -0,0 +1,44 @@
_lower_map = {
A: 'a',
B: 'b',
C: 'c',
D: 'd',
E: 'e',
F: 'f',
G: 'g',
H: 'h',
I: 'i',
J: 'j',
K: 'k',
L: 'l',
M: 'm',
N: 'n',
O: 'o',
P: 'p',
Q: 'q',
R: 'r',
S: 's',
T: 't',
U: 'u',
V: 'v',
W: 'w',
X: 'x',
Y: 'y',
Z: 'z'
}
lower(string)
for upper, lower in _lower_map
string = replace(upper, lower, string)
string
upper(string)
for upper, lower in _lower_map
string = replace(lower, upper, string)
string
RV-CSSParameter(block)
for name, value in block
css-var-name = '--%s' % unquote(name)
add-property(css-var-name, value)
define(name, unquote('var(--%s)' % (unquote(name))), true)

View File

@@ -0,0 +1,6 @@
RV-Utils__ElementAmount(callback, up-to=20)
for i in (1..up-to)
*:first-child:nth-last-child({i}),
*:first-child:nth-last-child({i})~*
callback(i, up-to)

View File

@@ -0,0 +1,149 @@
_lanes = {}
_stacks = {}
_aliases = {}
_last_name = {}
_block_type(block_type)
if block_type == null
block_type = called-from[1]
return block_type
_reset_last_name(block_type=null)
block_type = _block_type(block_type)
if block_type in _last_name
remove(_last_name, block_type)
_set_last_name(name, block_type=null)
block_type = _block_type(block_type)
_last_name[block_type] = name
_get_last_name(block_type)
block_type = _block_type(block_type)
if block_type in _last_name
return _last_name[block_type]
else
return null
_push_onto_stack(block, block_type=null)
block_type = _block_type(block_type)
if block_type in _stacks
stack = _stacks[block_type]
else
stack = ()
push(stack, block)
_stacks[block_type] = stack
_pop_from_stack(block_type=null)
block_type = _block_type(block_type)
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)
block_type = _block_type(block_type)
if block_type in _stacks
stack = _stacks[block_type]
remove(_stacks, block_type)
return stack
else
return ()
_last_element_of_stack(block_type=null)
block_type = _block_type(block_type)
if block_type in _stacks
stack = _stacks[block_type]
return stack[-1]
else
return null
_set_lane(lane_name, value, block_type=null)
block_type = _block_type(block_type)
if block_type in _lanes
lane = _lanes[block_type]
else
lane = {}
if lane_name in lane
stack = lane[lane_name]
else
stack = ()
push(stack, value)
lane[lane_name] = stack
_lanes[block_type] = lane
_get_lane(block_type)
block_type = _block_type(block_type)
if block_type in _lanes
return _lanes[block_type]
else
return {}
_put_into_lane(key, value, block_type=null)
block_type = _block_type(block_type)
if block_type in _lanes
lane = _lanes[block_type]
else
lane = {}
lane[key] = value
_lanes[block_type] = lane
_pop_lane(block_type=null)
block_type = _block_type(block_type)
if block_type in _lanes
lane = _lanes[block_type]
remove(_lanes, block_type)
return lane
else
return {}
_set_alias(name, alias, block_type=null)
block_type = _block_type(block_type)
if block_type in _aliases
alias_map = _aliases[block_type]
else
alias_map = {}
alias_map[name] = alias
_aliases[block_type] = alias_map
_get_alias(name, block_type=null)
block_type = _block_type(block_type)
if block_type in _aliases
alias_map = _aliases[block_type]
if name in alias_map
return alias_map[name]
else
return name
else
return name
_reset_aliases()
for key in keys(_aliases)
remove(_aliases, key)

View File

@@ -0,0 +1,4 @@
@import './_bemGenerator'
@import './_cssParameter'
@import './_elementAmount'
@import './_alignment'