i have no clue what im doing ... da da da da
This commit is contained in:
		@@ -6,15 +6,43 @@
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
_css-prefix = 'RV'
 | 
			
		||||
_global_scope = {
 | 
			
		||||
	_selector_blocks_to_generate: {}
 | 
			
		||||
	_element-modifier: ()
 | 
			
		||||
	_additional-element-modifier-blocks: ()
 | 
			
		||||
	_last_element_name: null
 | 
			
		||||
	_blocks_to_generate: ()
 | 
			
		||||
	_element_modifier_block_stack: ()
 | 
			
		||||
	_element_block_stack: ()
 | 
			
		||||
	_element_modifier_stack: {}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Cache for Blocks
 | 
			
		||||
_last_block_name = null
 | 
			
		||||
_block_building_lane = ()
 | 
			
		||||
_element_building_lange = ()
 | 
			
		||||
 | 
			
		||||
_element_building_lane = {}
 | 
			
		||||
_element_block_stack = ()
 | 
			
		||||
_work_lane(lane, callback)
 | 
			
		||||
	l = length(lane)
 | 
			
		||||
	for _ in (0..l)
 | 
			
		||||
		piece =  pop(lane)
 | 
			
		||||
		callback(piece)
 | 
			
		||||
 | 
			
		||||
_block_modifier_building_lane = {}
 | 
			
		||||
_block_modifier_block_stack = ()
 | 
			
		||||
/*
 | 
			
		||||
 * Gets the selector of the parent class
 | 
			
		||||
 */
 | 
			
		||||
_get_parent_selector()
 | 
			
		||||
	return split(' ', selector())[-1]
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * Gets the selector of the current block
 | 
			
		||||
 */
 | 
			
		||||
_get_block_selector()
 | 
			
		||||
	return unquote(split('__', _get_parent_selector())[0])
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
_get_element_selector()
 | 
			
		||||
	element--modifier = split('__', _get_parent_selector())[1]
 | 
			
		||||
	return unquote(split('--', element--modifier)[0])
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
@@ -22,7 +50,17 @@ _block_modifier_block_stack = ()
 | 
			
		||||
 * Block according to BEM
 | 
			
		||||
 */
 | 
			
		||||
RV-Block(name)
 | 
			
		||||
	tow(name, block)
 | 
			
		||||
	.{name}
 | 
			
		||||
		{block}
 | 
			
		||||
		
 | 
			
		||||
		for element_name, element in _global_scope['_selector_blocks_to_generate']
 | 
			
		||||
			& .{name}__{element_name}
 | 
			
		||||
				for current_block in element.block_list
 | 
			
		||||
					{current_block}
 | 
			
		||||
				for modifier_name, modifier_block_list in element.modifier_list
 | 
			
		||||
					&--{modifier_name}
 | 
			
		||||
						for current_block in modifier_block_list
 | 
			
		||||
							{current_block}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
@@ -30,8 +68,11 @@ RV-Block(name)
 | 
			
		||||
 * according to BEM. 
 | 
			
		||||
 */
 | 
			
		||||
RV-Block__Modifier(name)
 | 
			
		||||
	attach('RV-Block', unquote('--' + name), block)
 | 
			
		||||
 | 
			
		||||
	if 'RV-Block__Modifier' in called-from
 | 
			
		||||
		{block}
 | 
			
		||||
	else
 | 
			
		||||
		&{_get_block_selector()}--{name}
 | 
			
		||||
			{block}
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * Generates an CSS class for an element
 | 
			
		||||
@@ -39,12 +80,27 @@ RV-Block__Modifier(name)
 | 
			
		||||
 * For more see RV-Element___Modifier
 | 
			
		||||
 */
 | 
			
		||||
RV-Element(name)
 | 
			
		||||
	attach('RV-Block', unquote('__' + name), block)
 | 
			
		||||
	tow(name, block)
 | 
			
		||||
	push(_global_scope['_element_block_stack'], block)
 | 
			
		||||
	
 | 
			
		||||
	current_block = _block_building_lane[-1]
 | 
			
		||||
	
 | 
			
		||||
	//Detect if the selector will be generated
 | 
			
		||||
	//by an earlier call of RV-Element
 | 
			
		||||
	if not 'RV-Element' in called-from
 | 
			
		||||
		// Saving accumulated modifiers and blocks
 | 
			
		||||
		element = {}
 | 
			
		||||
		element['block_list'] = _global_scope['_element_block_stack']
 | 
			
		||||
		element['modifier_list'] = _global_scope['_element_modifier_stack']
 | 
			
		||||
		
 | 
			
		||||
		//Reseting
 | 
			
		||||
		_global_scope['_element_block_stack'] = ()
 | 
			
		||||
		_global_scope['_element_modifier_stack'] = {}
 | 
			
		||||
		
 | 
			
		||||
		//Saving element
 | 
			
		||||
		_global_scope['_selector_blocks_to_generate'][name] = element
 | 
			
		||||
		_global_scope['_last_element_name'] = name
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/*	p(_block_building_lane)
 | 
			
		||||
/*
 | 
			
		||||
 * Generates a CSS class for an element modifier
 | 
			
		||||
 * according to BEM. These are ment to be part of the 
 | 
			
		||||
 * content block of an element and since child-mixins
 | 
			
		||||
@@ -54,5 +110,34 @@ RV-Element(name)
 | 
			
		||||
 * from RV-Element
 | 
			
		||||
 */
 | 
			
		||||
RV-Element__Modifier(name)
 | 
			
		||||
	attach('RV-Element', '--' + name, block)
 | 
			
		||||
	counter = 0
 | 
			
		||||
	for fn in called-from
 | 
			
		||||
		if fn is 'RV-Element'
 | 
			
		||||
			counter += 1
 | 
			
		||||
					
 | 
			
		||||
	if counter <= 1
 | 
			
		||||
		element_modifier_block_stack = _global_scope['_element_modifier_block_stack']
 | 
			
		||||
		append(element_modifier_block_stack, block)
 | 
			
		||||
		_global_scope['_element_modifier_block_stack'] = element_modifier_block_stack
 | 
			
		||||
		
 | 
			
		||||
		//Is this modifier beeing included by another modifier
 | 
			
		||||
		if not 'RV-Element__Modifier' in called-from
 | 
			
		||||
			//No
 | 
			
		||||
			//Is this modifier beeing called in in- or postfix
 | 
			
		||||
			if not 'RV-Element' in called-from
 | 
			
		||||
				//Yes
 | 
			
		||||
				last_element_name = _global_scope['_last_element_name']
 | 
			
		||||
				
 | 
			
		||||
				//Accesing the last generated element and appending the modifier
 | 
			
		||||
				element = _global_scope['_selector_blocks_to_generate'][last_element_name]
 | 
			
		||||
				modifier_list = element['modifier_list']
 | 
			
		||||
				modifier_list[name] = _global_scope['_element_modifier_block_stack']
 | 
			
		||||
				element['modifier_list'] = modifier_list
 | 
			
		||||
 | 
			
		||||
				_global_scope['_selector_blocks_to_generate'][last_element_name] = element
 | 
			
		||||
			else
 | 
			
		||||
				//No
 | 
			
		||||
				_global_scope['_element_modifier_stack'][name] = _global_scope['_element_modifier_block_stack']
 | 
			
		||||
				
 | 
			
		||||
			_global_scope['_element_modifier_block_stack'] = ()
 | 
			
		||||
		
 | 
			
		||||
@@ -1,4 +1,3 @@
 | 
			
		||||
@import './_blockAppendix'
 | 
			
		||||
@import './_bemGenerator'
 | 
			
		||||
@import './_selectorHook'
 | 
			
		||||
@import './_cssParameter'
 | 
			
		||||
 
 | 
			
		||||
@@ -79,6 +79,23 @@ _pop_stack(block_type=null)
 | 
			
		||||
	else
 | 
			
		||||
		return ()
 | 
			
		||||
 | 
			
		||||
_add_to_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 = {}
 | 
			
		||||
 | 
			
		||||
	if key in lane
 | 
			
		||||
		stack = lane[key]
 | 
			
		||||
	else
 | 
			
		||||
		stack = ()
 | 
			
		||||
 | 
			
		||||
	push(stack, value)
 | 
			
		||||
	lane[key] = stack
 | 
			
		||||
	_lanes[block_type] = lane
 | 
			
		||||
 | 
			
		||||
_put_into_lane(key, value, block_type=null)
 | 
			
		||||
	if block_type == null
 | 
			
		||||
@@ -119,26 +136,19 @@ attach(parent_type, suffix, 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}
 | 
			
		||||
				--attach 'blubb'
 | 
			
		||||
			& .{_last_parent_name} .{_last_parent_name}{suffix}
 | 
			
		||||
				{block}
 | 
			
		||||
 | 
			
		||||
tow(name, block, block_type=null)
 | 
			
		||||
	if block_type == null	// Determining if we are inside a block or after a block
 | 
			
		||||
		block_type = called-from[0]
 | 
			
		||||
 | 
			
		||||
	if not block_type in _being_towed
 | 
			
		||||
		prefix = '.'+name
 | 
			
		||||
		{prefix}
 | 
			
		||||
			{block}
 | 
			
		||||
	else
 | 
			
		||||
		prefix = ''
 | 
			
		||||
 | 
			
		||||
	{prefix}
 | 
			
		||||
	.{name}
 | 
			
		||||
		{block}
 | 
			
		||||
		if block_type in _lanes
 | 
			
		||||
			for suffix, block_list in _pop_lane(block_type)
 | 
			
		||||
				p('name' name 'suffix' suffix)
 | 
			
		||||
				& {name}{suffix}
 | 
			
		||||
				p(name suffix selector())
 | 
			
		||||
				&{name}{suffix}
 | 
			
		||||
					for current_block in block_list
 | 
			
		||||
						{current_block}
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user