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/_validators.scss | 68 +++++++++++++++++++++++++----------------------- 1 file changed, 36 insertions(+), 32 deletions(-) (limited to 'src/bem/_validators.scss') diff --git a/src/bem/_validators.scss b/src/bem/_validators.scss index eb09a60..042e15e 100644 --- a/src/bem/_validators.scss +++ b/src/bem/_validators.scss @@ -16,6 +16,10 @@ /// @access public //// +@use './vars'; +@use '../functions'; +@use '../contexts'; + /// /// A list of validator functions. /// @@ -23,7 +27,7 @@ /// /// @access private /// -$iro-bem-validators: (); +$validators: (); /// /// Register one or multiple validator functions. @@ -41,19 +45,19 @@ $iro-bem-validators: (); /// @param {string} $func-name - First function name. /// @param {string} $func-names - Other function names. /// -@mixin iro-bem-add-validator($func-name, $func-names...) { - $noop: iro-bem-add-validator($func-name, $func-names...); +@mixin add($func-name, $func-names...) { + $noop: add($func-name, $func-names...); } /// /// Register one or multiple validator functions. Check the respective mixin documentation for more information. /// -/// @see {mixin} iro-bem-add-validator +/// @see {mixin} add /// -@function iro-bem-add-validator($func-name, $func-names...) { +@function add($func-name, $func-names...) { @each $fn-name in join($func-name, $func-names) { $fn: get-function($fn-name); - $iro-bem-validators: map-merge($iro-bem-validators, ($fn-name: $fn)) !global; + $validators: map-merge($validators, ($fn-name: $fn)); } @return null; } @@ -64,25 +68,25 @@ $iro-bem-validators: (); /// @param {string} $func-name - First function name. /// @param {string} $func-names - Other function names. /// -@mixin iro-bem-remove-validator($func-name, $func-names...) { - $noop: iro-bem-remove-validator($func-name, $func-names...); +@mixin remove($func-name, $func-names...) { + $noop: remove($func-name, $func-names...); } /// /// Unregister one or multiple validator functions. Check the respective mixin documentation for more information. /// -/// @see {mixin} iro-bem-remove-validator +/// @see {mixin} remove /// -@function iro-bem-remove-validator($func-name, $func-names...) { - $iro-bem-validators: map-remove($iro-bem-validators, $func-name, $func-names...) !global; +@function remove($func-name, $func-names...) { + $validators: map-remove($validators, $func-name, $func-names...); @return null; } /// /// @access private /// -@mixin iro-bem-validate($type, $args, $selector, $context) { - @each $id, $fn in $iro-bem-validators { +@mixin validate($type, $args, $selector, $context) { + @each $id, $fn in $validators { $result: call($fn, $type, $args, $selector, $context); @if not nth($result, 1) { @error 'A BEM validator rejected this mixin usage due to the following reason: #{nth($result, 2)}'; @@ -100,26 +104,26 @@ $iro-bem-validators: (); /// A validator that makes sure blocks are declared in the right order, determined by the /// namespace used. /// -@function iro-bem-validator--enforce-namespace-order($type, $args, $selector, $context) { - @if not global-variable-exists(iro-bem-namespace-order) { - $iro-bem-namespace-order: map-keys($iro-bem-namespaces) !global; +@function enforce-namespace-order($type, $args, $selector, $context) { + @if not global-variable-exists(namespace-order, vars) { + vars.$namespace-order: map-keys(vars.$namespaces); } - @if not global-variable-exists(iro-bem-cur-namespace-index) { - $iro-bem-cur-namespace-index: 1 !global; + @if not global-variable-exists(cur-namespace-index, vars) { + vars.$cur-namespace-index: 1; } @if $type == 'block' { $block-type: map-get($args, 'type'); @if $block-type != null { - $ns-index: index($iro-bem-namespace-order, $block-type); + $ns-index: index(vars.$namespace-order, $block-type); @if $ns-index != null { - @if $ns-index < $iro-bem-cur-namespace-index { - @return false 'Namespace "#{$block-type}" comes before current namespace #{nth($iro-bem-namespace-order, $iro-bem-cur-namespace-index)}'; + @if $ns-index < vars.$cur-namespace-index { + @return false 'Namespace "#{$block-type}" comes before current namespace #{nth(vars.$namespace-order, vars.$cur-namespace-index)}'; } - $iro-bem-cur-namespace-index: $ns-index !global; + vars.$cur-namespace-index: $ns-index; } } } @@ -130,9 +134,9 @@ $iro-bem-validators: (); /// /// A validator that makes all BEM entities immutable. /// -@function iro-bem-validator--immutable-entities($type, $args, $selector, $context) { - @if not global-variable-exists(iro-bem-generated-selectors) { - $iro-bem-generated-selectors: () !global; +@function immutable-entities($type, $args, $selector, $context) { + @if not global-variable-exists(generated-selectors, vars) { + vars.$generated-selectors: (); } $block-name: null; @@ -143,7 +147,7 @@ $iro-bem-validators: (); $block-name: map-get($args, 'name'); $block-type: map-get($args, 'type'); } @else { - $block-context: iro-context-get($iro-bem-context-id, 'block'); + $block-context: contexts.get(vars.$context-id, 'block'); $block-name: map-get(nth($block-context, 2), 'name'); $block-type: map-get(nth($block-context, 2), 'type'); } @@ -155,21 +159,21 @@ $iro-bem-validators: (); } @if $type == 'block' { - @if map-has-key($iro-bem-generated-selectors, $block-id) { - @return false 'Entity "#{$type}" with arguments [ #{iro-map-print($args)} ] was already defined.'; + @if map-has-key(vars.$generated-selectors, $block-id) { + @return false 'Entity "#{$type}" with arguments [ #{functions.map-print($args)} ] was already defined.'; } - $iro-bem-generated-selectors: map-merge($iro-bem-generated-selectors, ($block-id: ())) !global; + vars.$generated-selectors: map-merge(vars.$generated-selectors, ($block-id: ())); } @else { - $selectors: map-get($iro-bem-generated-selectors, $block-id); + $selectors: map-get(vars.$generated-selectors, $block-id); @if index($selectors, $selector) { - @return false 'Entity "#{$type}" with arguments [ #{iro-map-print($args)} ] was already defined.'; + @return false 'Entity "#{$type}" with arguments [ #{functions.map-print($args)} ] was already defined.'; } $selectors: append($selectors, $selector); - $iro-bem-generated-selectors: map-merge($iro-bem-generated-selectors, ($block-id: $selectors)) !global; + vars.$generated-selectors: map-merge(vars.$generated-selectors, ($block-id: $selectors)); } @return true ''; -- cgit v1.2.3-54-g00ecf