From dd5f3c463fab336d694f426dcad11a1783590fc9 Mon Sep 17 00:00:00 2001 From: Volpeon Date: Sat, 5 Feb 2022 07:52:13 +0100 Subject: Ported from import syntax to modules --- src/bem/_block.scss | 166 +++++++++++++++++++++++++++------------------------- 1 file changed, 86 insertions(+), 80 deletions(-) (limited to 'src/bem/_block.scss') diff --git a/src/bem/_block.scss b/src/bem/_block.scss index d065891..49af04b 100644 --- a/src/bem/_block.scss +++ b/src/bem/_block.scss @@ -4,6 +4,12 @@ /// @access public //// +@use './validators'; +@use './vars'; +@use './functions' as bemfunctions; +@use '../functions'; +@use '../contexts'; + /// /// Generate a new block. /// @@ -20,7 +26,7 @@ /// @throw If the block is preceded by another block, element, modifier or suffix /// /// @example scss - Creating a new block -/// @include iro-bem-block('something', 'component') { +/// @include block('something', 'component') { /// /* some definitions */ /// } /// @@ -30,12 +36,12 @@ /// /* some definitions */ /// } /// -@mixin iro-bem-block($name, $type: null) { - $result: iro-bem-block($name, $type); +@mixin block($name, $type: null) { + $result: block($name, $type); $selector: nth($result, 1); $context: nth($result, 2); - @include iro-bem-validate( + @include validators.validate( 'block', (name: $name, type: $type), $selector, @@ -43,16 +49,16 @@ ); @if $type != null { - $iro-bem-blocks: append($iro-bem-blocks, $name + '_' + $type) !global; + vars.$blocks: append(vars.$blocks, $name + '_' + $type); } @else { - $iro-bem-blocks: append($iro-bem-blocks, $name) !global; + vars.$blocks: append(vars.$blocks, $name); } - @include iro-context-push($iro-bem-context-id, $context...); + @include contexts.push(vars.$context-id, $context...); @at-root #{$selector} { @content; } - @include iro-context-pop($iro-bem-context-id); + @include contexts.pop(vars.$context-id); } /// @@ -60,21 +66,21 @@ /// /// @return {list} A list with two items: 1. selector, 2. context or `null` /// -/// @see {mixin} iro-bem-block +/// @see {mixin} block /// -@function iro-bem-block($name, $type: null) { +@function block($name, $type: null) { // // Possible outcomes: // - ({b,e,m,s}) block // - $noop: iro-context-assert-stack-count($iro-bem-context-id, $iro-bem-max-depth); + $noop: contexts.assert-stack-count(vars.$context-id, vars.$max-depth); $selector: null; $base-selector: null; @if $type != null { - $namespace: map-get($iro-bem-namespaces, $type); + $namespace: map-get(vars.$namespaces, $type); @if not $namespace { @error '"#{$type}" is not a valid type.'; @@ -85,7 +91,7 @@ @if $type != 'theme' or & { $selector: $base-selector; } @else if not & { - $selector: iro-bem-theme-selector($name); + $selector: bemfunctions.theme-selector($name); } } @else { $base-selector: selector-parse('.' + $name); @@ -107,14 +113,14 @@ } /// -/// Generate a new object block. It's a shorthand for iro-bem-block($name, 'object'). +/// Generate a new object block. It's a shorthand for block($name, 'object'). /// /// @param {string} $name - Object block name /// /// @content /// -@mixin iro-bem-object($name) { - @include iro-bem-block($name, 'object') { +@mixin object($name) { + @include block($name, 'object') { @content; } } @@ -124,21 +130,21 @@ /// /// @return {list} A list with two items: 1. selector, 2. context or `null` /// -/// @see {mixin} iro-bem-object +/// @see {mixin} object /// -@function iro-bem-object($name) { - @return iro-bem-block($name, 'object'); +@function object($name) { + @return block($name, 'object'); } /// -/// Generate a new component block. It's a shorthand for iro-bem-block($name, 'component'). +/// Generate a new component block. It's a shorthand for block($name, 'component'). /// /// @param {string} $name - Component block name /// /// @content /// -@mixin iro-bem-component($name) { - @include iro-bem-block($name, 'component') { +@mixin component($name) { + @include block($name, 'component') { @content; } } @@ -148,21 +154,21 @@ /// /// @return {list} A list with two items: 1. selector, 2. context or `null` /// -/// @see {mixin} iro-bem-component +/// @see {mixin} component /// -@function iro-bem-component($name) { - @return iro-bem-block($name, 'component'); +@function component($name) { + @return block($name, 'component'); } /// -/// Generate a new layout block. It's a shorthand for iro-bem-block($name, 'layout'). +/// Generate a new layout block. It's a shorthand for block($name, 'layout'). /// /// @param {string} $name - Layout block name /// /// @content /// -@mixin iro-bem-layout($name) { - @include iro-bem-block($name, 'layout') { +@mixin layout($name) { + @include block($name, 'layout') { @content; } } @@ -172,21 +178,21 @@ /// /// @return {list} A list with two items: 1. selector, 2. context or `null` /// -/// @see {mixin} iro-bem-layout +/// @see {mixin} layout /// -@function iro-bem-layout($name) { - @return iro-bem-block($name, 'layout'); +@function layout($name) { + @return block($name, 'layout'); } /// -/// Generate a new utility block. It's a shorthand for iro-bem-block($name, 'utility'). +/// Generate a new utility block. It's a shorthand for block($name, 'utility'). /// /// @param {string} $name - Utility block name /// /// @content /// -@mixin iro-bem-utility($name) { - @include iro-bem-block($name, 'utility') { +@mixin utility($name) { + @include block($name, 'utility') { @content; } } @@ -196,21 +202,21 @@ /// /// @return {list} A list with two items: 1. selector, 2. context or `null` /// -/// @see {mixin} iro-bem-utility +/// @see {mixin} utility /// -@function iro-bem-utility($name) { - @return iro-bem-block($name, 'utility'); +@function utility($name) { + @return block($name, 'utility'); } /// -/// Generate a new scope block. It's a shorthand for iro-bem-block($name, 'scope'). +/// Generate a new scope block. It's a shorthand for block($name, 'scope'). /// /// @param {string} $name - Scope block name /// /// @content /// -@mixin iro-bem-scope($name) { - @include iro-bem-block($name, 'scope') { +@mixin scope($name) { + @include block($name, 'scope') { @content; } } @@ -220,21 +226,21 @@ /// /// @return {list} A list with two items: 1. selector, 2. context or `null` /// -/// @see {mixin} iro-bem-scope +/// @see {mixin} scope /// -@function iro-bem-scope($name) { - @return iro-bem-block($name, 'scope'); +@function scope($name) { + @return block($name, 'scope'); } /// -/// Generate a new theme block. It's a shorthand for iro-bem-block($name, 'theme'). +/// Generate a new theme block. It's a shorthand for block($name, 'theme'). /// /// @param {string} $name - Theme block name /// /// @content /// -@mixin iro-bem-theme($name) { - @include iro-bem-block($name, 'theme') { +@mixin theme($name) { + @include block($name, 'theme') { @content; } } @@ -244,21 +250,21 @@ /// /// @return {list} A list with two items: 1. selector, 2. context or `null` /// -/// @see {mixin} iro-bem-theme +/// @see {mixin} theme /// -@function iro-bem-theme($name) { - @return iro-bem-block($name, 'theme'); +@function theme($name) { + @return block($name, 'theme'); } /// -/// Generate a new JS block. It's a shorthand for iro-bem-block($name, 'js'). +/// Generate a new JS block. It's a shorthand for block($name, 'js'). /// /// @param {string} $name - JS block name /// /// @content /// -@mixin iro-bem-js($name) { - @include iro-bem-block($name, 'js') { +@mixin js($name) { + @include block($name, 'js') { @content; } } @@ -268,21 +274,21 @@ /// /// @return {list} A list with two items: 1. selector, 2. context or `null` /// -/// @see {mixin} iro-bem-js +/// @see {mixin} js /// -@function iro-bem-js($name) { - @return iro-bem-block($name, 'js'); +@function js($name) { + @return block($name, 'js'); } /// -/// Generate a new QA block. It's a shorthand for iro-bem-block($name, 'qa'). +/// Generate a new QA block. It's a shorthand for block($name, 'qa'). /// /// @param {string} $name - QA block name /// /// @content /// -@mixin iro-bem-qa($name) { - @include iro-bem-block($name, 'qa') { +@mixin qa($name) { + @include block($name, 'qa') { @content; } } @@ -292,21 +298,21 @@ /// /// @return {list} A list with two items: 1. selector, 2. context or `null` /// -/// @see {mixin} iro-bem-qa +/// @see {mixin} qa /// -@function iro-bem-qa($name) { - @return iro-bem-block($name, 'qa'); +@function qa($name) { + @return block($name, 'qa'); } /// -/// Generate a new hack block. It's a shorthand for iro-bem-block($name, 'hack'). +/// Generate a new hack block. It's a shorthand for block($name, 'hack'). /// /// @param {string} $name - Hack block name /// /// @content /// -@mixin iro-bem-hack($name) { - @include iro-bem-block($name, 'hack') { +@mixin hack($name) { + @include block($name, 'hack') { @content; } } @@ -316,10 +322,10 @@ /// /// @return {list} A list with two items: 1. selector, 2. context or `null` /// -/// @see {mixin} iro-bem-hack +/// @see {mixin} hack /// -@function iro-bem-hack($name) { - @return iro-bem-block($name, 'hack'); +@function hack($name) { + @return block($name, 'hack'); } /// @@ -337,15 +343,15 @@ /// @throw If a block doesn't exist /// /// @example scss - Successful assertion -/// @include iro-bem-component('someBlock') { +/// @include component('someBlock') { /// /* some definitions */ /// } /// -/// @include iro-bem-component('anotherBlock') { +/// @include component('anotherBlock') { /// /* some definitions */ /// -/// @include iro-bem-element('elem') { -/// @include iro-bem-composed-of('someBlock' 'component'); +/// @include elem('elem') { +/// @include composed-of('someBlock' 'component'); /// /// /* some definitions */ /// } @@ -354,37 +360,37 @@ /// // Intended use:
...
/// /// @example scss - Failing assertion -/// @include iro-bem-component('anotherBlock') { +/// @include component('anotherBlock') { /// /* some definitions */ /// -/// @include iro-bem-element('elem') { -/// @include iro-bem-composed-of('someBlock' 'component'); +/// @include elem('elem') { +/// @include composed-of('someBlock' 'component'); /// /// /* some definitions */ /// } /// } /// -/// @include iro-bem-component('someBlock') { +/// @include component('someBlock') { /// /* some definitions */ /// } /// /// // Compilation will fail because c-someBlock is defined after c-anotherBlock__elem /// -@mixin iro-bem-composed-of($block, $blocks...) { - @each $block in iro-list-prepend($blocks, $block) { +@mixin composed-of($block, $blocks...) { + @each $block in functions.list-prepend($blocks, $block) { @if type-of($block) == string { - @if not index($iro-bem-blocks, $block) { + @if not index(vars.$blocks, $block) { @error 'Block "#{$block}" does not exist.'; } } @else { $name: nth($block, 1); $type: nth($block, 2); - @if not map-get($iro-bem-namespaces, $type) { + @if not map-get(vars.$namespaces, $type) { @error '"#{$type}" is not a valid type.'; } - @if not index($iro-bem-blocks, $name + '_' + $type) { + @if not index(vars.$blocks, $name + '_' + $type) { @error 'Block "#{$name}" does not exist.'; } } -- cgit v1.2.3-70-g09d2