-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(function/call): handle map type arguments with additional `$…
…arguments` parameter and add spec.
- Loading branch information
1 parent
f125923
commit dc6d444
Showing
3 changed files
with
54 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,55 @@ | ||
// Sass. | ||
@use 'sass:list'; | ||
@use 'sass:map'; | ||
@use 'sass:meta'; | ||
|
||
// Functions. | ||
@use '../../list/get'; | ||
@use '../../list/remove'; | ||
@use '../function.get.function'; | ||
|
||
// Status: DONE | ||
// The `call.arglist()` function calls function of `$name` on `$arglist` with a separator comma where elements are arguments or space where the whole | ||
// list is an argument. | ||
// list is an argument. Arguments can be passed as list or map by `$arguments` parameter. | ||
// @param `$name` Function name to call arguments from `$arglist` as comma-separated arguments or argument. | ||
// @param `$arglist` List on which to call function of `$name`. | ||
// @param `$prefix` Allowed prefixes of the function name. | ||
// @param `$separator` Allowed separators of the function name. | ||
// @param `$functions` Functions instead of global functions retrieved from `function.$functions`. | ||
// @param `$function` Parameter to retrieve function from global `function.$functions`. | ||
// @param `$function` Function name to retrieve from `$functions` if not `null` otherwise from global `function.$functions`. | ||
// @param `$arguments` Additional arguments as `list` or `map` following `$arglist` to pass. | ||
// @returns The returned value is the result of invoked function. | ||
@function arglist( | ||
$name, | ||
$arglist, | ||
$prefix: null, | ||
$separator: null, | ||
$functions: null, | ||
$function: function.get($name, $prefix, $separator, $functions) | ||
$function: function.get($name, $prefix, $separator, $functions), | ||
$arguments: null | ||
) { | ||
@if $name { | ||
@return if( | ||
list.separator($arglist) == comma, | ||
meta.call($function, $arglist...), | ||
meta.call($function, $arglist) | ||
); | ||
@if list.separator($arglist) == comma { | ||
@if $arguments { | ||
$arglist: if( | ||
meta.type-of($arguments) == map, | ||
list.append($arglist, (arguments: $arguments), comma), | ||
list.join($arglist, $arguments, comma) | ||
); | ||
} | ||
@if get.map($arglist) { | ||
// Map type arguments | ||
@if map.has-key(get.map($arglist), arguments) or map.has-key(get.map($arglist), args) { | ||
@return meta.call( | ||
$function, | ||
remove.map($arglist)..., | ||
map.get(get.map($arglist), args) or map.get(get.map($arglist), arguments)... | ||
); | ||
} | ||
} | ||
@return meta.call($function, $arglist...); | ||
} | ||
@return meta.call($function, $arglist); | ||
} | ||
@return null; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters