Skip to content

Commit aa6b50c

Browse files
authored
Merge pull request #904 from quanb-duy/api-ref_shortcode
2 parents 586320e + 589cef8 commit aa6b50c

16 files changed

+139
-88
lines changed

docs/class_template.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ linkTitle: "LINK"
33
no_list: true
44
---
55

6-
{{< python-class "PATH" >}}
6+
{{< api-ref-class "PATH" >}}

docs/function_template.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ superheading: "PARENT."
55
weight: 100
66
---
77

8-
{{< python "PATH" >}}
8+
{{< api-ref "PATH" >}}

docs/layouts/partials/python-function-parenthesis.html renamed to docs/layouts/partials/api-ref-function-parenthesis.html

File renamed without changes.

docs/layouts/partials/python-api-link-all-partial.html renamed to docs/layouts/partials/api-ref-link-all-partial.html

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
{{ $context := .context}}
22
{{ $paragraph := .paragraph}}
3+
{{ $jsonPath := printf "versioned_docs/%s/links.json" (partial "version.html" (dict "context" $context)).dirpath }}
34

4-
{{ with getJSON (printf "versioned_docs/%s/links.json" (partial "version.html" (dict "context" $context)).dirpath) }}
5+
{{ if fileExists $jsonPath }}
6+
7+
{{ with getJSON $jsonPath }}
58
{{ $links := . }}
69

710
{{ range $name, $data := $links }}
@@ -36,3 +39,7 @@
3639

3740
{{ $paragraph | safeHTML }}
3841
{{ end }}
42+
43+
{{ else }}
44+
Missing links.json for this version!
45+
{{ end }}

docs/layouts/partials/python-api-link-partial.html renamed to docs/layouts/partials/api-ref-link-partial.html

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
{{ $orig_name := .paragraph }}
22
{{ $context := .context }}
3+
{{ $jsonPath := printf "versioned_docs/%s/links.json" (partial "version.html" (dict "context" $context)).dirpath }}
34

4-
{{ with getJSON (printf "versioned_docs/%s/links.json" (partial "version.html" (dict "context" $context)).dirpath) }}
5+
{{ if fileExists $jsonPath }}
6+
7+
{{ with getJSON $jsonPath }}
58
{{ $links := . }}
69
{{/* We have to handle the case of Optional[name] or list[name] */}}
710
{{ $name := $orig_name }}
@@ -19,3 +22,7 @@
1922
{{ $orig_name }}
2023
{{ end }}
2124
{{ end }}
25+
26+
{{ else }}
27+
Missing links.json for this version!
28+
{{ end }}

docs/layouts/partials/python-object.html renamed to docs/layouts/partials/api-ref-object-partial.html

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,21 @@
66
<div class="python-ref {{ if (eq $objData.kind " function") }} python-ref-func {{ else }} python-ref-class {{ end }}">
77
{{ if and (eq $objData.kind "function")}}
88

9-
{{ $parenthesisArgsString := partial "python-function-parenthesis.html" $objData}}
9+
{{ $parenthesisArgsString := partial "api-ref-function-parenthesis.html" $objData}}
1010
{{ if not $objData.is_property }}
1111
<p><code>
12-
{{ (index (last 1 $path) 0) }}({{- $parenthesisArgsString -}}) -> {{ partial "python-api-link-partial.html" (dict "paragraph" $objData.signature.return_annotation "context" $context) }}
12+
{{ (index (last 1 $path) 0) }}({{- $parenthesisArgsString -}}) -> {{ partial "api-ref-link-partial.html" (dict "paragraph" $objData.signature.return_annotation "context" $context) }}
1313
</code></p>
1414
{{ else }}
1515
<p><code>
16-
{{ (index (last 1 $path) 0) }} -> {{ partial "python-api-link-partial.html" (dict "paragraph" $objData.signature.return_annotation "context" $context) }}
16+
{{ (index (last 1 $path) 0) }} -> {{ partial "api-ref-link-partial.html" (dict "paragraph" $objData.signature.return_annotation "context" $context) }}
1717
</code></p>
1818
{{ end }}
1919

2020
{{ if $objData.docstring_parsed}}
2121
<div class="python-ref-description">
22-
<p> {{ partial "python-api-link-all-partial.html" (dict "paragraph" ($objData.docstring_parsed.short_description | safeHTML) "context" $context) }}</p>
23-
<p> {{ partial "python-api-link-all-partial.html" (dict "paragraph" ($objData.docstring_parsed.long_description | safeHTML) "context" $context)}}</p>
22+
<p> {{ partial "api-ref-link-all-partial.html" (dict "paragraph" ($objData.docstring_parsed.short_description | safeHTML) "context" $context) }}</p>
23+
<p> {{ partial "api-ref-link-all-partial.html" (dict "paragraph" ($objData.docstring_parsed.long_description | safeHTML) "context" $context)}}</p>
2424
</div>
2525
{{ end }}
2626

@@ -41,8 +41,8 @@ <h4> Parameters </h4>
4141
{{range $objData.docstring_parsed.params}}
4242
<tr>
4343
<td> {{ .arg_name }} </td>
44-
<td> {{ partial "python-api-link-partial.html" (dict "paragraph" .type_name "context" $context) }} </td>
45-
<td> {{ partial "python-api-link-all-partial.html" (dict "paragraph" (.description | safeHTML) "context" $context) }} </td>
44+
<td> {{ partial "api-ref-link-partial.html" (dict "paragraph" .type_name "context" $context) }} </td>
45+
<td> {{ partial "api-ref-link-all-partial.html" (dict "paragraph" (.description | safeHTML) "context" $context) }} </td>
4646
</tr>
4747
{{end}}
4848
</tbody>
@@ -63,7 +63,7 @@ <h4> Parameters </h4>
6363
{{range $objData.signature.params}}
6464
<tr>
6565
<td> {{ index . 0 }} </td>
66-
<td> {{ partial "python-api-link-partial.html" (dict "paragraph" (index . 1) "context" $context) }} </td>
66+
<td> {{ partial "api-ref-link-partial.html" (dict "paragraph" (index . 1) "context" $context) }} </td>
6767
<td> <i> None </i> </td>
6868
</tr>
6969
{{end}}
@@ -101,11 +101,11 @@ <h4> Returns </h4>
101101
<tbody>
102102
<tr>
103103
<td>
104-
{{ partial "python-api-link-partial.html" (dict "paragraph" $typeName "context" $context) }}
104+
{{ partial "api-ref-link-partial.html" (dict "paragraph" $typeName "context" $context) }}
105105
</td>
106106
<td>
107107
{{ if $description }}
108-
{{ partial "python-api-link-all-partial.html" (dict "paragraph" ($objData.docstring_parsed.returns.description | safeHTML) "context" $context) }}
108+
{{ partial "api-ref-link-all-partial.html" (dict "paragraph" ($objData.docstring_parsed.returns.description | safeHTML) "context" $context) }}
109109
{{ else }}
110110
<i> None </i>
111111
{{ end }}
@@ -124,8 +124,8 @@ <h4> Returns </h4>
124124
<h1> {{index (last 2 $path) 0}}.{{ index (last 1 $path) 0 }} </h1>
125125
{{ if $objData.docstring_parsed }}
126126
<div class="python-ref-description">
127-
<p> {{ partial "python-api-link-all-partial.html" (dict "paragraph" ($objData.docstring_parsed.short_description | safeHTML) "context" $context) }}</p>
128-
<p> {{ partial "python-api-link-all-partial.html" (dict "paragraph" ($objData.docstring_parsed.long_description | safeHTML) "context" $context) }}</p>
127+
<p> {{ partial "api-ref-link-all-partial.html" (dict "paragraph" ($objData.docstring_parsed.short_description | safeHTML) "context" $context) }}</p>
128+
<p> {{ partial "api-ref-link-all-partial.html" (dict "paragraph" ($objData.docstring_parsed.long_description | safeHTML) "context" $context) }}</p>
129129
</div>
130130
{{ end }}
131131
{{end}}

docs/layouts/partials/python.html renamed to docs/layouts/partials/api-ref-partial.html

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
{{ $path := split .path "." }}
2+
{{ $jsonPath := printf "versioned_docs/%s/data.json" (partial "version.html" (dict "context" .context )).dirpath }}
23

3-
{{ with getJSON (printf "versioned_docs/%s/data.json") (partial "version.html" (dict "context" .context )).dirpath }}
4+
{{ if fileExists $jsonPath }}
5+
6+
{{ with getJSON $jsonPath }}
47
{{ $currentData := . }}
58
{{ range $path }}
69
{{ if (eq $currentData.kind "class") }}
@@ -17,6 +20,10 @@
1720

1821

1922
<div class="python-ref">
20-
{{ partial "python-object.html" (dict "object" $objData "path" $path "context" .) }}
23+
{{ partial "api-ref-object-partial.html" (dict "object" $objData "path" $path "context" .) }}
2124
</div>
2225
{{ end }}
26+
27+
{{ else }}
28+
Missing data.json for this version!
29+
{{ end }}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{{ $page := . }}
2+
{{ $dirpath := (partial "version.html" (dict "context" .)).dirpath }}
3+
4+
{{ $jsonPath := printf "versioned_docs/%s/data.json" $dirpath }}
5+
6+
{{ if fileExists $jsonPath }}
7+
8+
{{ with getJSON $jsonPath }}
9+
{{ $data := . }}
10+
{{ with getJSON (printf "versioned_docs/%s/links.json" $dirpath) }}
11+
{{ $links := . }}
12+
<style>
13+
html {
14+
scroll-behavior: smooth;
15+
}
16+
</style>
17+
<div class="python-api-ref-link">
18+
{{ range $name, $data := $links }}
19+
{{ $path := $data.path }}
20+
<span style="top: -250px; position: relative;" id="{{ $path }}"></span>
21+
{{ partial "api-ref-partial.html" $path }}
22+
{{ end }}
23+
</div>
24+
{{ end }}
25+
{{ end }}
26+
27+
{{ else }}
28+
Missing data.json for this version!
29+
{{ end }}

docs/layouts/shortcodes/python-class.html renamed to docs/layouts/shortcodes/api-ref-class.html

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,25 @@
11
{{ $path := split (.Get 0) "." }}
22
{{ $page := .Page }}
3+
{{ $jsonPath := printf "versioned_docs/%s/data.json" (partial "version.html" (dict "context" $page)).dirpath }}
34

4-
{{ with getJSON (printf "versioned_docs/%s/data.json" (partial "version.html" (dict "context" $page)).dirpath) }}
5-
{{ $currentData := . }}
6-
{{ range $path }}
7-
{{ if (eq $currentData.kind "class") }}
8-
{{ $currentData = $currentData.functions }}
9-
{{ end }}
10-
{{$currentData = index $currentData .}}
5+
{{ if fileExists $jsonPath }}
6+
7+
{{ with getJSON $jsonPath }}
8+
{{ $currentData := . }}
9+
{{ range $path }}
10+
{{ if (eq $currentData.kind "class") }}
11+
{{ $currentData = $currentData.functions }}
12+
{{ end }}
13+
{{$currentData = index $currentData .}}
1114
{{ end }}
1215

13-
{{ $objData := $currentData }}
1416

15-
{{ $publicMethodsCounter := 0 }}
16-
{{ $publicPropertiesCounter := 0 }}
17+
{{ $objData := $currentData }}
1718

18-
{{ range $name, $func := $objData.functions }}
19+
{{ $publicMethodsCounter := 0 }}
20+
{{ $publicPropertiesCounter := 0 }}
21+
22+
{{ range $name, $func := $objData.functions }}
1923
{{ if (not (hasPrefix $name "_"))}}
2024
{{ if $func.is_property }}
2125
{{ $publicPropertiesCounter = add $publicPropertiesCounter 1 }}
@@ -24,11 +28,10 @@
2428
{{ end }}
2529
{{ end }}
2630

27-
{{ end }}
28-
31+
{{ end }}
2932

3033
<div class="python-ref">
31-
{{ partial "python-object.html" (dict "object" $objData "path" $path "context" $page) }}
34+
{{ partial "api-ref-object-partial.html" (dict "object" $objData "path" $path "context" $page) }}
3235

3336
<h2> Properties </h2>
3437
{{ if gt $publicPropertiesCounter 0 }}
@@ -45,10 +48,10 @@ <h2> Properties </h2>
4548
<tr>
4649

4750
<td>
48-
{{ partial "python-api-link-partial.html" (dict "paragraph" $name "context" $page) }}
51+
{{ partial "api-ref-link-partial.html" (dict "paragraph" $name "context" $page) }}
4952
</td>
5053
{{ if $func.docstring_parsed }}
51-
<td>{{ partial "python-api-link-all-partial.html" (dict "paragraph" $func.docstring_parsed.short_description "context" $page) }}</td>
54+
<td>{{ partial "api-ref-link-all-partial.html" (dict "paragraph" $func.docstring_parsed.short_description "context" $page) }}</td>
5255
{{ else }}
5356
<td><i>None</i></td>
5457
{{ end }}
@@ -77,12 +80,12 @@ <h2>Methods</h2>
7780
<tr>
7881

7982
{{ if and (not (hasPrefix $name "_")) (not $func.is_property)}}
80-
{{ $parenthesisArgsString := partial "python-function-parenthesis.html" $func}}
83+
{{ $parenthesisArgsString := partial "api-ref-function-parenthesis.html" $func}}
8184

82-
<td>{{ partial "python-api-link-partial.html" (dict "paragraph" $name "context" $page) }}({{- $parenthesisArgsString -}})
85+
<td>{{ partial "api-ref-link-partial.html" (dict "paragraph" $name "context" $page) }}({{- $parenthesisArgsString -}})
8386
</td>
8487
{{ if $func.docstring_parsed }}
85-
<td>{{ partial "python-api-link-all-partial.html" (dict "paragraph" $func.docstring_parsed.short_description "context" $page) }}</td>
88+
<td>{{ partial "api-ref-link-all-partial.html" (dict "paragraph" $func.docstring_parsed.short_description "context" $page) }}</td>
8689
{{ else }}
8790
<td><i>None</i></td>
8891
{{ end }}
@@ -97,3 +100,7 @@ <h2>Methods</h2>
97100

98101
</div>
99102
{{ end }}
103+
104+
{{ else }}
105+
Missing data.json for this version!
106+
{{ end }}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{{ partial "api-ref-link-partial.html" (dict "paragraph" (index .Params 0) "context" .Page)}}

0 commit comments

Comments
 (0)