From e361a8f73a7c0ef8fa9dc013f136d295a3d01de5 Mon Sep 17 00:00:00 2001 From: Volpeon Date: Wed, 17 Mar 2021 17:56:38 +0100 Subject: Improved property tree function names --- README.md | 12 +++++----- src/_props.scss | 30 ++++++++++++------------ src/props-shortcodes.scss | 26 ++++++++++---------- test/_props.scss | 60 +++++++++++++++++++++++------------------------ 4 files changed, 65 insertions(+), 63 deletions(-) diff --git a/README.md b/README.md index f02f6a7..631af7f 100644 --- a/README.md +++ b/README.md @@ -236,18 +236,18 @@ Example usage: // Usage: p { - color: iro-props-get(--text, 'light'); // #222 - background-color: iro-props-get(--background, 'light'); // #fff + color: iro-props-get-static(--text, 'light'); // #222 + background-color: iro-props-get-static(--background, 'light'); // #fff } a { - color: iro-props-get(--link --idle --text, 'light'); // #000 - border-bottom: 1px solid iro-props-get(--link --idle --underline, 'light'); // #f00 + color: iro-props-get-static(--link --idle --text, 'light'); // #000 + border-bottom: 1px solid iro-props-get-static(--link --idle --underline, 'light'); // #f00 text-decoration: none; &:hover { - color: iro-props-get(--link --hover --text, 'light'); // #f00 - border-bottom-color: iro-props-get(--link --hover --underline, 'light'); // #f00 + color: iro-props-get-static(--link --hover --text, 'light'); // #f00 + border-bottom-color: iro-props-get-static(--link --hover --underline, 'light'); // #f00 } } ``` diff --git a/src/_props.scss b/src/_props.scss index 86a2215..5577f3a 100644 --- a/src/_props.scss +++ b/src/_props.scss @@ -77,7 +77,7 @@ $iro-props-namespace-context-id: 'namespace' !default; /// /// Get the current namespace name. /// -@function iro-props-ns-name() { +@function iro-props-namespace() { $noop: iro-context-assert-stack-must-contain($iro-props-namespace-context-id, 'namespace'); $data: nth(iro-context-get($iro-props-namespace-context-id, 'namespace'), 2); @@ -172,7 +172,7 @@ $iro-props-namespace-context-id: 'namespace' !default; /// /// @throw If there was no match for $key and $default is null /// -@function iro-props-get($key: (), $tree: $iro-props-default-tree, $default: null, $global: false) { +@function iro-props-get-static($key: (), $tree: $iro-props-default-tree, $default: null, $global: false) { @if not map-has-key($iro-props-trees, $tree) { @error 'Unknown tree "#{$tree}".'; } @@ -205,9 +205,9 @@ $iro-props-namespace-context-id: 'namespace' !default; @if type-of($result) == list and nth($result, 1) == 'iro-prop-ref' { @if length($result) == 2 { - $result: iro-props-get($tree: nth($result, 2), $global: true); + $result: iro-props-get-static($tree: nth($result, 2), $global: true); } @else { - $result: iro-props-get(nth($result, 3), nth($result, 2), $global: true); + $result: iro-props-get-static(nth($result, 3), nth($result, 2), $global: true); } } } @else { @@ -223,9 +223,9 @@ $iro-props-namespace-context-id: 'namespace' !default; @if type-of($result) == list and nth($result, 1) == 'iro-prop-ref' { @if length($result) == 2 { - $result: iro-props-get($tree: nth($result, 2), $global: true); + $result: iro-props-get-static($tree: nth($result, 2), $global: true); } @else { - $result: iro-props-get(nth($result, 3), nth($result, 2), $global: true); + $result: iro-props-get-static(nth($result, 3), nth($result, 2), $global: true); } } } @@ -250,9 +250,9 @@ $iro-props-namespace-context-id: 'namespace' !default; /// /// @return {string} var() /// -@function iro-props-get-native($key, $tree: null, $default: null, $global: false) { +@function iro-props-get($key, $tree: $iro-props-default-tree, $default: null, $global: false) { @if $tree != null { - $noop: iro-props-get($key, $tree, $default); + $noop: iro-props-get-static($key, $tree, $default); } @if not $global { @@ -295,8 +295,8 @@ $iro-props-namespace-context-id: 'namespace' !default; /// @param {string} $tree [$iro-props-default-tree] - ID of the property tree to use /// @param {string} $root [()] - Sub-tree to use for assignment /// -@mixin iro-props-assign-native($tree: $iro-props-default-tree, $root: (), $skip: (), $prefix: '', $global: false) { - $map: iro-props-get($root, $tree); +@mixin iro-props-assign($tree: $iro-props-default-tree, $root: (), $skip: (), $prefix: '', $global: false) { + $map: iro-props-get-static($root, $tree); $map: map-remove($map, $skip...); @if type-of($prefix) == list { @@ -311,22 +311,22 @@ $iro-props-namespace-context-id: 'namespace' !default; } } - @include iro-props-assign-native-internal($map, $prefix); + @include iro-props-assign-internal($map, $prefix); } /// /// @access private /// -@mixin iro-props-assign-native-internal($map, $prefix: '', $ref-depth: $iro-props-native-assing-max-depth) { +@mixin iro-props-assign-internal($map, $prefix: '', $ref-depth: $iro-props-native-assing-max-depth) { @each $key, $value in $map { $rd: $ref-depth; @if type-of($value) == list and nth($value, 1) == 'iro-prop-ref' { @if $ref-depth != 0 { $rd: $rd - 1; @if length($value) == 2 { - $value: iro-props-get($tree: nth($value, 2)); + $value: iro-props-get-static($tree: nth($value, 2)); } @else { - $value: iro-props-get(nth($value, 3), nth($value, 2)); + $value: iro-props-get-static(nth($value, 3), nth($value, 2)); } } @else { $value: null; @@ -335,7 +335,7 @@ $iro-props-namespace-context-id: 'namespace' !default; @if type-of($value) != map { #{$prefix + $key}: #{$value}; } @else { - @include iro-props-assign-native-internal($value, $prefix + $key, $rd); + @include iro-props-assign-internal($value, $prefix + $key, $rd); } } } diff --git a/src/props-shortcodes.scss b/src/props-shortcodes.scss index 2c678a7..e3e3d06 100644 --- a/src/props-shortcodes.scss +++ b/src/props-shortcodes.scss @@ -10,14 +10,16 @@ /// @alias iro-props-namespace /// @mixin namespace($name) { - @include iro-props-namespace($name); + @include iro-props-namespace($name) { + @content; + } } /// -/// @alias iro-props-ns-name +/// @alias iro-props-namespace /// @function namespace() { - @return iro-props-ns-name(); + @return iro-props-namespace(); } /// @@ -49,24 +51,24 @@ } /// -/// @alias iro-props-get +/// @alias iro-props-get-static /// -@function prop($key: (), $tree: $iro-props-default-tree, $default: null, $global: false) { - @return iro-props-get($key, $tree, $default, $global); +@function static($key: (), $tree: $iro-props-default-tree, $default: null, $global: false) { + @return iro-props-get-static($key, $tree, $default, $global); } /// -/// @alias iro-props-get-native +/// @alias iro-props-get /// -@function n-prop($key, $tree: null, $default: null, $global: false) { - @return iro-props-get-native($key, $tree, $default, $global); +@function prop($key, $tree: $iro-props-default-tree, $default: null, $global: false) { + @return iro-props-get($key, $tree, $default, $global); } /// -/// @alias iro-props-assign-native +/// @alias iro-props-assign /// -@mixin n-assign($tree: $iro-props-default-tree, $root: (), $skip: (), $prefix: '', $global: false) { - @include iro-props-assign-native($tree, $root, $skip, $prefix, $global); +@mixin assign($tree: $iro-props-default-tree, $root: (), $skip: (), $prefix: '', $global: false) { + @include iro-props-assign($tree, $root, $skip, $prefix, $global); } /// diff --git a/test/_props.scss b/test/_props.scss index 982fc2f..021ed4c 100644 --- a/test/_props.scss +++ b/test/_props.scss @@ -41,7 +41,7 @@ ); @include assert-equal(iro-props-store($map), null, 'Save default tree'); - @include assert-equal(iro-props-clear(), null, 'Delete default tree'); + @include assert-equal(iro-props-clear(), null, 'Delete default tree'); } @include it('Read') { @@ -85,20 +85,20 @@ @include assert-equal(iro-props-store($map3, 'namespaced'), null, 'Save "namespaced" tree'); } - @include assert-equal(iro-props-get(--background), map-get($map1, --background), 'Get --background in default'); - @include assert-equal(iro-props-get(--buttons --primary --background), map-get(map-get(map-get($map1, --buttons), --primary), --background), 'Get --buttons --primary --background in default'); - @include assert-equal(iro-props-get(--box, $default: false), false, 'Get nonexistent in default'); + @include assert-equal(iro-props-get-static(--background), map-get($map1, --background), 'Get --background in default'); + @include assert-equal(iro-props-get-static(--buttons --primary --background), map-get(map-get(map-get($map1, --buttons), --primary), --background), 'Get --buttons --primary --background in default'); + @include assert-equal(iro-props-get-static(--box, $default: false), false, 'Get nonexistent in default'); - @include assert-equal(iro-props-get(--background, 'test'), map-get($map2, --background), 'Get --background in "test"'); - @include assert-equal(iro-props-get(--buttons --primary --background, 'test'), map-get(map-get(map-get($map2, --buttons), --primary), --background), 'Get --buttons --primary --background in "test"'); - @include assert-equal(iro-props-get(--box, 'test', $default: false), false, 'Get nonexistent in "test"'); + @include assert-equal(iro-props-get-static(--background, 'test'), map-get($map2, --background), 'Get --background in "test"'); + @include assert-equal(iro-props-get-static(--buttons --primary --background, 'test'), map-get(map-get(map-get($map2, --buttons), --primary), --background), 'Get --buttons --primary --background in "test"'); + @include assert-equal(iro-props-get-static(--box, 'test', $default: false), false, 'Get nonexistent in "test"'); - @include assert-equal(iro-props-get(--background, 'namespaced', $default: false), false, 'Get --background in "namespaced"'); - @include assert-equal(iro-props-get(--ns --background, 'namespaced'), map-get($map3, --background), 'Get --ns --background in "namespaced"'); + @include assert-equal(iro-props-get-static(--background, 'namespaced', $default: false), false, 'Get --background in "namespaced"'); + @include assert-equal(iro-props-get-static(--ns --background, 'namespaced'), map-get($map3, --background), 'Get --ns --background in "namespaced"'); @include iro-props-namespace('ns') { - @include assert-equal(iro-props-get(--background, 'namespaced'), map-get($map3, --background), 'Get namespaced --background in "namespaced"'); - @include assert-equal(iro-props-get(--buttons --primary --background, 'namespaced'), map-get(map-get(map-get($map3, --buttons), --primary), --background), 'Get namespaced --buttons --primary --background in "namespaced"'); - @include assert-equal(iro-props-get(--box, 'namespaced', $default: false), false, 'Get namespaced nonexistent in "namespaced"'); + @include assert-equal(iro-props-get-static(--background, 'namespaced'), map-get($map3, --background), 'Get namespaced --background in "namespaced"'); + @include assert-equal(iro-props-get-static(--buttons --primary --background, 'namespaced'), map-get(map-get(map-get($map3, --buttons), --primary), --background), 'Get namespaced --buttons --primary --background in "namespaced"'); + @include assert-equal(iro-props-get-static(--box, 'namespaced', $default: false), false, 'Get namespaced nonexistent in "namespaced"'); } @include assert-equal(iro-props-clear(), null, 'Delete default tree'); @@ -130,10 +130,10 @@ @include assert-equal(iro-props-store($map1), null, 'Save default tree'); @include assert-equal(iro-props-store($map2, $merge: true), null, 'Overwrite default tree'); - @include assert-equal(iro-props-get(), iro-map-merge-recursive($map1, $map2), 'After update, get whole map'); - @include assert-equal(iro-props-get(--background), map-get($map2, --background), 'After update, get --background'); - @include assert-equal(iro-props-get(--text), map-get($map2, --text), 'After update, get --text'); - @include assert-equal(iro-props-get(--buttons --primary --text), map-get(map-get(map-get($map1, --buttons), --primary), --text), 'After update, get --buttons --primary --text'); + @include assert-equal(iro-props-get-static(), iro-map-merge-recursive($map1, $map2), 'After update, get whole map'); + @include assert-equal(iro-props-get-static(--background), map-get($map2, --background), 'After update, get --background'); + @include assert-equal(iro-props-get-static(--text), map-get($map2, --text), 'After update, get --text'); + @include assert-equal(iro-props-get-static(--buttons --primary --text), map-get(map-get(map-get($map1, --buttons), --primary), --text), 'After update, get --buttons --primary --text'); @include assert-equal(iro-props-clear(), null, 'Delete default tree'); } @@ -158,7 +158,7 @@ @include iro-props-store($map); @include output { - @include iro-props-assign-native; + @include iro-props-assign; } @include expect { @@ -177,7 +177,7 @@ @include iro-props-store($map); @include output { - @include iro-props-assign-native($skip: --buttons); + @include iro-props-assign($skip: --buttons); } @include expect { @@ -194,7 +194,7 @@ } @include output { - @include iro-props-assign-native; + @include iro-props-assign; } @include expect { @@ -228,12 +228,12 @@ @include assert-equal(iro-props-store($map), null, 'Save default tree'); - @include assert-equal(iro-props-get-native(--background), var(--background), 'Get --background'); - @include assert-equal(iro-props-get-native(--buttons --primary --text), var(--buttons--primary--text), 'Get --buttons --primary --text'); - @include assert-equal(iro-props-get-native(--buttons --secondary --text, $default: false), var(--buttons--secondary--text, false), 'Get --buttons --secondary --text with default'); + @include assert-equal(iro-props-get(--background), var(--background), 'Get --background'); + @include assert-equal(iro-props-get(--buttons --primary --text), var(--buttons--primary--text), 'Get --buttons --primary --text'); + @include assert-equal(iro-props-get(--buttons --secondary --text, $default: false), var(--buttons--secondary--text, false), 'Get --buttons --secondary --text with default'); @include iro-props-namespace('buttons') { - @include assert-equal(iro-props-get-native(--primary --text), var(--buttons--primary--text), 'Get via namespace "buttons" --primary --text'); - @include assert-equal(iro-props-get-native(--secondary --text, $default: false), var(--buttons--secondary--text, false), 'Get via namespace "buttons" --secondary --text with default'); + @include assert-equal(iro-props-get(--primary --text), var(--buttons--primary--text), 'Get via namespace "buttons" --primary --text'); + @include assert-equal(iro-props-get(--secondary --text, $default: false), var(--buttons--secondary--text, false), 'Get via namespace "buttons" --secondary --text with default'); } @include assert-equal(iro-props-clear(), null, 'Delete default tree'); @@ -264,16 +264,16 @@ @include assert-equal(iro-props-store($map1), null, 'Save default tree'); @include assert-equal(iro-props-store($map2, 'second'), null, 'Save "second" tree'); - @include assert-equal(iro-props-get(--buttons --primary --background, 'second'), map-get($map1, --background), 'Get referenced value'); - @include assert-equal(iro-props-get-native(--buttons --primary --background, 'second'), var(--buttons--primary--background), 'Get referenced value, native'); + @include assert-equal(iro-props-get-static(--buttons --primary --background, 'second'), map-get($map1, --background), 'Get referenced value'); + @include assert-equal(iro-props-get(--buttons --primary --background, 'second'), var(--buttons--primary--background), 'Get referenced value, native'); - @include assert-equal(iro-props-get(--buttons --default, 'second'), map-get(map-get($map1, --buttons), --primary), 'Get referenced subtree, whole'); - @include assert-equal(iro-props-get(--buttons --default --background, 'second'), map-get(map-get(map-get($map1, --buttons), --primary), --background), 'Get referenced subtree, inner value'); - @include assert-equal(iro-props-get-native(--buttons --default --background, 'second'), var(--buttons--default--background), 'Get referenced subtree, native'); + @include assert-equal(iro-props-get-static(--buttons --default, 'second'), map-get(map-get($map1, --buttons), --primary), 'Get referenced subtree, whole'); + @include assert-equal(iro-props-get-static(--buttons --default --background, 'second'), map-get(map-get(map-get($map1, --buttons), --primary), --background), 'Get referenced subtree, inner value'); + @include assert-equal(iro-props-get(--buttons --default --background, 'second'), var(--buttons--default--background), 'Get referenced subtree, native'); @include assert('Native assignment') { @include output { - @include iro-props-assign-native('second'); + @include iro-props-assign('second'); } @include expect { -- cgit v1.2.3-54-g00ecf