summaryrefslogtreecommitdiffstats
path: root/docs/layouts/shortcodes/code-toggle.html
blob: 0b92d520d924c921df98e21b50440e5f9e72ad76 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
{{ $file := .Get "file" }}
{{ $code := "" }}
{{ with .Get "config" }}
  {{ $file = $file | default "config" }}
  {{ $sections := (split . ".") }}
  {{ $configSection := index $.Site.Data.docs.config $sections }}
  {{ $code = dict $sections $configSection  }}
  {{ if $.Get "skipHeader"}}
    {{ $code = $configSection  }}
  {{ end }}
{{ else }}
  {{ $code = $.Inner }}
{{ end  }}
{{ $langs := (slice "yaml" "toml" "json") }}
<div class="code relative" {{ with $file }}id="{{ . | urlize}}"{{ end }}>
  <div class="code-nav flex flex-nowrap items-stretch">
    {{- with $file -}}
      <div class="san-serif f6 dib lh-solid pl2 pv2 mr2">
        {{ . }}.
      </div>
    {{- end -}}
    {{ range $langs }}
      <button data-toggle-tab="{{ . }}" class="tab-button {{ cond (eq . "yaml") "active" ""}} ba san-serif f6 dib lh-solid ph2 pv2">
        {{ . }}
      </button>
      &nbsp;
    {{ end }}
  </div>
  <div class="tab-content">
    {{ range $langs }}
      <div data-pane="{{ . }}" class="code-copy-content nt3 tab-pane {{ cond (eq . "yaml") "active" ""}}">
        {{ highlight ($code | transform.Remarshal . | safeHTML) . ""}}
      </div>
      {{ if ne ($.Get "copy") "false" }}
        <button class="needs-js copy copy-toggle bg-accent-color-dark f6 absolute top-0 right-0 lh-solid hover-bg-primary-color-dark bn white ph3 pv2" title="Copy this code to your clipboard." data-clipboard-action="copy" aria-label="copy button"></button>
        {{/* Functionality located within filesaver.js The copy here is located in the css with .copy class so it can be replaced with JS on success */}}
      {{end}}
    {{ end }}
  </div>
  
</div>