sass-site/source/documentation/modules/meta.html.md.erb

310 lines
9.1 KiB
Plaintext
Raw Normal View History

2018-10-25 00:01:43 +02:00
---
title: sass:meta
2018-10-25 00:01:43 +02:00
---
<%= partial '../snippets/built-in-module-status' %>
<% function 'meta.call($function, $args...)', 'call($function, $args...)' do %>
2018-10-25 00:01:43 +02:00
<%= partial 'documentation/snippets/call-impl-status' %>
Invokes `$function` with `$args` and returns the result.
The `$function` should be a [function][] returned by
[`meta.get-function()`][].
2018-10-25 00:01:43 +02:00
[function]: ../values/functions
[`meta.get-function()`]: #get-function
2018-10-25 00:01:43 +02:00
<%= partial 'code-snippets/example-first-class-function' %>
<% end %>
<% function 'meta.content-exists()',
'content-exists()',
returns: 'boolean' do %>
2018-10-25 00:01:43 +02:00
Returns whether the current mixin was passed a [`@content` block][].
[`@content` block]: ../at-rules/mixin#content-blocks
Throws an error if called outside of a mixin.
<% example(autogen_css: false) do %>
@mixin debug-content-exists {
@debug meta.content-exists();
2018-10-25 00:01:43 +02:00
@content;
}
@include debug-content-exists; // false
@include debug-content-exists { // true
// Content!
}
===
@mixin debug-content-exists
@debug meta.content-exists()
2018-10-25 00:01:43 +02:00
@content
@include debug-content-exists // false
@include debug-content-exists // true
// Content!
<% end %>
<% end %>
<% function 'meta.feature-exists($feature)',
'feature-exists($feature)',
returns: 'boolean' do %>
2018-10-25 00:01:43 +02:00
Returns whether the current Sass implementation supports `$feature`.
The `$feature` must be a string. The currently recognized features are:
* `global-variable-shadowing`, which means that a local variable will
[shadow][] a global variable unless it has the `!global` flag.
* `extend-selector-pseudoclass`, which means that the [`@extend` rule][] will
affect selectors nested in pseudo-classes like `:not()`.
* `units-level3`, which means that [unit arithmetic][] supports units defined
in [CSS Values and Units Level 3][].
* `at-error`, which means that the [`@error` rule][] is supported.
* `custom-property`, which means that [custom property declaration][] values
don't support any [expressions][] other than [interpolation][].
[shadow]: ../variables#shadowing
[`@extend` rule]: ../at-rules/extend
[unit arithmetic]: ../values/numbers#units
[CSS Values and Units Level 3]: http://www.w3.org/TR/css3-values
[`@error` rule]: ../at-rules/error
[custom property declaration]: ../style-rules/declarations#custom-properties
[expressions]: ../syntax/structure#expressions
[interpolation]: ../interpolation
Returns `false` for any unrecognized `$feature`.
<% example(autogen_css: false) do %>
@debug meta.feature-exists("at-error"); // true
@debug meta.feature-exists("unrecognized"); // false
2018-10-25 00:01:43 +02:00
===
@debug meta.feature-exists("at-error") // true
@debug meta.feature-exists("unrecognized") // false
2018-10-25 00:01:43 +02:00
<% end %>
<% end %>
<% function 'meta.function-exists($name)',
'function-exists($name)',
returns: 'boolean' do %>
2018-10-25 00:01:43 +02:00
Returns whether a function named `$name` is defined, either as a built-in
function or a user-defined function.
<% example(autogen_css: false) do %>
@debug meta.function-exists("scale-color"); // true
@debug meta.function-exists("add"); // false
2018-10-25 00:01:43 +02:00
@function add($num1, $num2) {
@return $num1 + $num2;
}
@debug meta.function-exists("add"); // true
2018-10-25 00:01:43 +02:00
===
@debug meta.function-exists("scale-color") // true
@debug meta.function-exists("add") // false
2018-10-25 00:01:43 +02:00
@function add($num1, $num2)
@return $num1 + $num2
@debug meta.function-exists("add") // true
2018-10-25 00:01:43 +02:00
<% end %>
<% end %>
<% function 'meta.get-function($name, $css: false)',
'get-function($name, $css: false)',
returns: 'function' do %>
2018-10-25 00:01:43 +02:00
Returns the [function][] named `$name`.
[function]: ../values/functions
This can access both built-in and [user-defined][] functions. By default, it
throws an error if `$name` doesn't refer to either a built-in or user-defined
function. However, if `$css` is `true`, it instead returns a
[plain CSS function][].
[user-defined]: ../at-rules/function
2019-09-05 23:47:14 +02:00
[plain CSS function]: ../at-rules/function#plain-css-functions
2018-10-25 00:01:43 +02:00
The returned function can be called using [`meta.call()`](#call).
2018-10-25 00:01:43 +02:00
<%= partial 'code-snippets/example-first-class-function' %>
<% end %>
<% function 'meta.global-variable-exists($name)',
'global-variable-exists($name)',
returns: 'boolean' do %>
2018-10-25 00:01:43 +02:00
Returns whether a [global variable][] named `$name` (without the `$`) exists.
[global variable]: ../variables#scope
See also [`meta.variable-exists()`](#variable-exists).
2018-10-25 00:01:43 +02:00
<% example(autogen_css: false) do %>
@debug meta.global-variable-exists("var1"); // false
2018-10-25 00:01:43 +02:00
$var1: value;
@debug meta.global-variable-exists("var1"); // true
2018-10-25 00:01:43 +02:00
h1 {
// $var2 is local.
$var2: value;
@debug meta.global-variable-exists("var2"); // false
2018-10-25 00:01:43 +02:00
}
===
@debug meta.global-variable-exists("var1") // false
2018-10-25 00:01:43 +02:00
$var1: value
@debug meta.global-variable-exists("var1") // true
2018-10-25 00:01:43 +02:00
h1
// $var2 is local.
$var2: value
@debug meta.global-variable-exists("var2") // false
2018-10-25 00:01:43 +02:00
<% end %>
<% end %>
<% function 'meta.inspect($value)',
'inspect($value)',
returns: 'unquoted string' do %>
2018-10-25 00:01:43 +02:00
Returns a string representation of `$value`.
Returns a representation of *any* Sass value, not just those that can be
represented in CSS. As such, its return value is not guaranteed to be valid
CSS.
<% heads_up do %>
This function is intended for debugging; its output format is not guaranteed
to be consistent across Sass versions or implementations.
<% end %>
<% example(autogen_css: false) do %>
@debug meta.inspect(10px 20px 30px); // unquote("10px 20px 30px")
@debug meta.inspect(("width": 200px)); // unquote('("width": 200px)')
@debug meta.inspect(null); // unquote("null")
@debug meta.inspect("Helvetica"); // unquote('"Helvetica"')
2018-10-25 00:01:43 +02:00
===
@debug meta.inspect(10px 20px 30px) // unquote("10px 20px 30px")
@debug meta.inspect(("width": 200px)) // unquote('("width": 200px)')
@debug meta.inspect(null) // unquote("null")
@debug meta.inspect("Helvetica") // unquote('"Helvetica"')
2018-10-25 00:01:43 +02:00
<% end %>
<% end %>
<% function 'meta.keywords($args)', 'keywords($args)', returns: 'map' do %>
Returns the keywords passed to a mixin or function that takes [arbitrary
arguments][]. The `$args` argument must be an [argument list][].
[arbitrary arguments]: ../at-rules/mixin#taking-arbitrary-arguments
[argument list]: ../values/lists#argument-lists
The keywords are returned as a map from argument names as unquoted strings (not
including `$`) to the values of those arguments.
<%= partial 'code-snippets/example-mixin-arbitrary-keyword-arguments' %>
<% end %>
<% function 'meta.mixin-exists($name)',
'mixin-exists($name)',
returns: 'boolean' do %>
2018-10-25 00:01:43 +02:00
Returns whether a [mixin][] named `$name` exists.
[mixin]: ../at-rules/mixin
<% example(autogen_css: false) do %>
@debug meta.mixin-exists("shadow-none"); // false
2018-10-25 00:01:43 +02:00
@mixin shadow-none {
box-shadow: none;
}
@debug meta.mixin-exists("shadow-none"); // true
2018-10-25 00:01:43 +02:00
===
@debug meta.mixin-exists("shadow-none") // false
2018-10-25 00:01:43 +02:00
@mixin shadow-none
box-shadow: none
@debug meta.mixin-exists("shadow-none") // true
2018-10-25 00:01:43 +02:00
<% end %>
<% end %>
<% function 'meta.type-of($value)',
'type-of($value)',
returns: 'unquoted string' do %>
2018-10-25 00:01:43 +02:00
Returns the type of `$value`.
This can return the following values:
* [`number`](../values/numbers)
* [`string`](../values/strings)
* [`color`](../values/colors)
* [`list`](../values/lists)
* [`map`](../values/maps)
* [`bool`](../values/booleans)
* [`null`](../values/null)
* [`function`](../values/functions)
* [`arglist`](../values/lists#argument-lists)
New possible values may be added in the future. It may return either `list` or
`map` for `()`, depending on whether or not it was returned by a
[map function][].
[map function]: map
<% example(autogen_css: false) do %>
@debug meta.type-of(10px); // number
@debug meta.type-of(10px 20px 30px); // list
@debug meta.type-of(()); // list
2018-10-25 00:01:43 +02:00
===
@debug meta.type-of(10px) // number
@debug meta.type-of(10px 20px 30px) // list
@debug meta.type-of(()) // list
2018-10-25 00:01:43 +02:00
<% end %>
<% end %>
<% function 'meta.variable-exists($name)',
'variable-exists($name)',
returns: 'boolean' do %>
2018-10-25 00:01:43 +02:00
Returns whether a variable named `$name` (without the `$`) exists in the
current [scope][].
[scope]: ../variables#scope
See also [`meta.global-variable-exists()`](#global-variable-exists).
2018-10-25 00:01:43 +02:00
<% example(autogen_css: false) do %>
@debug meta.variable-exists("var1"); // false
2018-10-25 00:01:43 +02:00
$var1: value;
@debug meta.variable-exists("var1"); // true
2018-10-25 00:01:43 +02:00
h1 {
// $var2 is local.
$var2: value;
@debug meta.variable-exists("var2"); // true
2018-10-25 00:01:43 +02:00
}
===
@debug meta.variable-exists("var1") // false
2018-10-25 00:01:43 +02:00
$var1: value
@debug meta.variable-exists("var1") // true
2018-10-25 00:01:43 +02:00
h1
// $var2 is local.
$var2: value
@debug meta.variable-exists("var2") // true
2018-10-25 00:01:43 +02:00
<% end %>
<% end %>