sass-site/source/_includes/code_snippets/example-first-class-function.liquid

53 lines
1.5 KiB
Plaintext
Raw Normal View History

2023-05-29 22:19:19 +02:00
{% codeExample 'first-class-function' %}
@use "sass:list";
@use "sass:meta";
@use "sass:string";
/// Return a copy of $list with all elements for which $condition returns `true`
/// removed.
@function remove-where($list, $condition) {
$new-list: ();
$separator: list.separator($list);
@each $element in $list {
@if not meta.call($condition, $element) {
$new-list: list.append($new-list, $element, $separator: $separator);
}
2023-05-29 22:19:19 +02:00
}
@return $new-list;
2023-05-29 22:19:19 +02:00
}
$fonts: Tahoma, Geneva, "Helvetica Neue", Helvetica, Arial, sans-serif;
2023-05-29 22:19:19 +02:00
2023-06-10 16:28:55 +02:00
.content {
@function contains-helvetica($string) {
@return string.index($string, "Helvetica");
}
font-family: remove-where($fonts, meta.get-function("contains-helvetica"));
2023-05-29 22:19:19 +02:00
}
===
@use "sass:list"
@use "sass:meta"
@use "sass:string"
2023-05-29 22:19:19 +02:00
/// Return a copy of $list with all elements for which $condition returns `true`
/// removed.
@function remove-where($list, $condition)
$new-list: ()
$separator: list.separator($list)
@each $element in $list
@if not meta.call($condition, $element)
$new-list: list.append($new-list, $element, $separator: $separator)
2023-05-29 22:19:19 +02:00
@return $new-list
2023-05-29 22:19:19 +02:00
$fonts: Tahoma, Geneva, "Helvetica Neue", Helvetica, Arial, sans-serif
2023-05-29 22:19:19 +02:00
.content
@function contains-helvetica($string)
@return string.index($string, "Helvetica")
2023-05-29 22:19:19 +02:00
font-family: remove-where($fonts, meta.get-function("contains-helvetica"))
2023-05-29 22:19:19 +02:00
{% endcodeExample %}