Share some list examples between function docs and value docs

This commit is contained in:
Natalie Weizenbaum 2018-10-23 12:24:58 -07:00
parent e397f98b29
commit dbda46cc63
4 changed files with 21 additions and 33 deletions

View File

@ -0,0 +1,9 @@
<% example(autogen_css: false) do %>
@debug index(1px solid red, 1px); // 1
@debug index(1px solid red, solid); // 2
@debug index(1px solid red, dashed); // null
===
@debug index(1px solid red, 1px) // 1
@debug index(1px solid red, solid) // 2
@debug index(1px solid red, dashed) // null
<% end %>

View File

@ -0,0 +1,7 @@
<% example(autogen_css: false) do %>
@debug nth(10px 12px 16px, 2); // 12px
@debug nth([line1, line2, line3], -1); // line3
===
@debug nth(10px 12px 16px, 2) // 12px
@debug nth([line1, line2, line3], -1) // line3
<% end %>

View File

@ -52,17 +52,9 @@ If `$value` doesn't appear in `$list`, this returns [`null`][]. If `$value`
appears multiple times in `$list`, this returns the index of its first
appearance.
[index]: ../values/null
[`null`]: ../values/null
<% example(autogen_css: false) do %>
@debug index(1px solid red, 1px); // 1
@debug index(1px solid red, solid); // 2
@debug index(1px solid red, dashed); // null
===
@debug index(1px solid red, 1px) // 1
@debug index(1px solid red, solid) // 2
@debug index(1px solid red, dashed) // null
<% end %>
<%= partial 'code-snippets/example-list-index' %>
<% end %>
@ -167,15 +159,7 @@ Returns the element of `$list` at [index][] `$n`.
If `$n` is negative, it counts from the end of `$list`. Throws an error if there
is no element at index `$n`.
<% example(autogen_css: false) do %>
@debug nth(10px 20px 30px, 1); // 10px
@debug nth(10px 20px 30px, -1); // 30px
@debug nth((Helvetica, Arial, sans-serif), 3); // sans-serif
===
@debug nth(10px 20px 30px, 1) // 10px
@debug nth(10px 20px 30px, -1) // 30px
@debug nth((Helvetica, Arial, sans-serif), 3) // sans-serif
<% end %>
<%= partial 'code-snippets/example-list-nth' %>
<% end %>

View File

@ -56,13 +56,7 @@ want to get out.
[`nth($list, $n)` function]: ../functions/lists#nth
<% example(autogen_css: false) do %>
@debug nth(10px 12px 16px, 2); // 12px
@debug nth([line1, line2, line3], -1); // line3
===
@debug nth(10px 12px 16px, 2) // 12px
@debug nth([line1, line2, line3], -1) // line3
<% end %>
<%= partial 'code-snippets/example-list-nth' %>
### Do Something for Every Element
@ -100,13 +94,7 @@ to locate in that list, and returns the index of that value.
[`index($list, $value)` function]: ../functions/lists#index
<% example(autogen_css: false) do %>
@debug index(10px 12px 16px, 12px); // 2
@debug index([line1, line2, line3], line3); // 3
===
@debug index(10px 12px 16px, 12px) // 2
@debug index([line1, line2, line3], line3) // 3
<% end %>
<%= partial 'code-snippets/example-list-index' %>
If the value isn't in the list at all, `index()` returns [`null`][]. Because
`null` is [falsey][], you can use `index()` with [`@if`][] or [`if()`][] to