-
-
Notifications
You must be signed in to change notification settings - Fork 179
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tab: new shortcode to display single tab #538
- Loading branch information
Showing
12 changed files
with
197 additions
and
55 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
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 |
---|---|---|
@@ -0,0 +1,76 @@ | ||
+++ | ||
description = "Show content in a single tab" | ||
title = "Tab" | ||
+++ | ||
|
||
You can use a `tab` shortcode to display a single tab. | ||
|
||
This is especially useful if you want to flag your code example with an explicit language. | ||
|
||
{{% tab name="c" %}} | ||
|
||
```python | ||
printf("Hello World!"); | ||
``` | ||
|
||
{{% /tab %}} | ||
|
||
## Usage | ||
|
||
While the examples are using shortcodes with named parameter you are free to also call this shortcode from your own partials. | ||
|
||
{{< tabs groupid="shortcode-parameter">}} | ||
{{% tab name="shortcode" %}} | ||
|
||
````go | ||
{{%/* tab name="c" */%}} | ||
```c | ||
printf("Hello World!"); | ||
``` | ||
{{%/* /tab */%}} | ||
```` | ||
|
||
{{% /tab %}} | ||
{{% tab name="partial" %}} | ||
|
||
````go | ||
{{ partial "shortcodes/tab.html" (dict | ||
"context" . | ||
"name" "c" | ||
"content" ("```c\nprintf(\"Hello World!\")\n```" | markdownify) | ||
)}} | ||
```` | ||
|
||
{{% /tab %}} | ||
{{< /tabs >}} | ||
|
||
### Parameter | ||
|
||
| Name | Default | Notes | | ||
|:----------------------|:---------------------|:------------| | ||
| **name** | _<empty>_ | Arbitrary text for the name of the tab. | | ||
| _**<content>**_ | _<empty>_ | Arbitrary text to be displayed in the tab. | | ||
|
||
## Examples | ||
|
||
### Code with collapsed margins | ||
|
||
{{% tab name="Code" %}} | ||
|
||
```python | ||
printf("Hello World!"); | ||
``` | ||
|
||
{{% /tab %}} | ||
|
||
### Mixed content | ||
|
||
{{% tab name="Mixed" %}} | ||
|
||
A tab can not only contain code but arbitrary text. In this case text and code will get a margin. | ||
|
||
```python | ||
printf("Hello World!"); | ||
``` | ||
|
||
{{% /tab %}} |
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
+++ | ||
descrption = "Show rrrambl'n 'n a single tab" | ||
title = "Tab" | ||
+++ | ||
{{< piratify >}} |
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{{- partial "shortcodes/tabs.html" (dict | ||
"context" .context | ||
"groupid" "" | ||
"content" (slice | append (dict "name" (trim .name " ") "content" .content)) | ||
) }} |
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,10 +1,17 @@ | ||
{{- $content := .Inner }} | ||
{{- $name := (.Get "name") }} | ||
{{- $tabs := slice }} | ||
{{- if and .Parent (.Parent.Scratch.Get "tabs") }} | ||
{{- $tabs = .Parent.Scratch.Get "tabs" }} | ||
{{- end }} | ||
{{- $tabs = $tabs | append (dict "name" (trim $name " ") "content" $content) }} | ||
{{- if .Parent }} | ||
{{- if not (.Parent.Scratch.Get "tabs") }} | ||
{{- .Parent.Scratch.Set "tabs" slice }} | ||
{{- end }} | ||
{{- $.Parent.Scratch.Add "tabs" (dict "name" (trim $name " ") "content" $content ) }} | ||
{{- $.Parent.Scratch.Set "tabs" $tabs }} | ||
{{- else }} | ||
{{- errorf "[%s] %q: tab shortcode missing its parent" site.Language.Lang .Page.Path -}} | ||
{{- end}} | ||
{{- $c:=""}}{{/* if no containing tabs shortcode is present, we display this tab as single */}} | ||
{{- partial "shortcodes/tabs.html" (dict | ||
"context" .Page | ||
"groupid" "" | ||
"content" $tabs | ||
) }} | ||
{{- end }} |
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,6 +1,6 @@ | ||
{{- $unused := .Inner }} | ||
{{- partial "shortcodes/tabs.html" (dict | ||
"context" .Page | ||
"content" .Inner | ||
"groupid" ((.Get "groupid") | default (.Get "groupId")) | ||
"tabs" (.Scratch.Get "tabs") | ||
"content" (.Scratch.Get "tabs") | ||
) }} |
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