Skip to content

Commit

Permalink
Merge pull request #904 from quanb-duy/api-ref_shortcode
Browse files Browse the repository at this point in the history
  • Loading branch information
Mara3l authored Nov 18, 2024
2 parents 586320e + 589cef8 commit aa6b50c
Show file tree
Hide file tree
Showing 16 changed files with 139 additions and 88 deletions.
2 changes: 1 addition & 1 deletion docs/class_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ linkTitle: "LINK"
no_list: true
---

{{< python-class "PATH" >}}
{{< api-ref-class "PATH" >}}
2 changes: 1 addition & 1 deletion docs/function_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ superheading: "PARENT."
weight: 100
---

{{< python "PATH" >}}
{{< api-ref "PATH" >}}
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
{{ $context := .context}}
{{ $paragraph := .paragraph}}
{{ $jsonPath := printf "versioned_docs/%s/links.json" (partial "version.html" (dict "context" $context)).dirpath }}

{{ with getJSON (printf "versioned_docs/%s/links.json" (partial "version.html" (dict "context" $context)).dirpath) }}
{{ if fileExists $jsonPath }}

{{ with getJSON $jsonPath }}
{{ $links := . }}

{{ range $name, $data := $links }}
Expand Down Expand Up @@ -36,3 +39,7 @@

{{ $paragraph | safeHTML }}
{{ end }}

{{ else }}
Missing links.json for this version!
{{ end }}
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
{{ $orig_name := .paragraph }}
{{ $context := .context }}
{{ $jsonPath := printf "versioned_docs/%s/links.json" (partial "version.html" (dict "context" $context)).dirpath }}

{{ with getJSON (printf "versioned_docs/%s/links.json" (partial "version.html" (dict "context" $context)).dirpath) }}
{{ if fileExists $jsonPath }}

{{ with getJSON $jsonPath }}
{{ $links := . }}
{{/* We have to handle the case of Optional[name] or list[name] */}}
{{ $name := $orig_name }}
Expand All @@ -19,3 +22,7 @@
{{ $orig_name }}
{{ end }}
{{ end }}

{{ else }}
Missing links.json for this version!
{{ end }}
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,21 @@
<div class="python-ref {{ if (eq $objData.kind " function") }} python-ref-func {{ else }} python-ref-class {{ end }}">
{{ if and (eq $objData.kind "function")}}

{{ $parenthesisArgsString := partial "python-function-parenthesis.html" $objData}}
{{ $parenthesisArgsString := partial "api-ref-function-parenthesis.html" $objData}}
{{ if not $objData.is_property }}
<p><code>
{{ (index (last 1 $path) 0) }}({{- $parenthesisArgsString -}}) -> {{ partial "python-api-link-partial.html" (dict "paragraph" $objData.signature.return_annotation "context" $context) }}
{{ (index (last 1 $path) 0) }}({{- $parenthesisArgsString -}}) -> {{ partial "api-ref-link-partial.html" (dict "paragraph" $objData.signature.return_annotation "context" $context) }}
</code></p>
{{ else }}
<p><code>
{{ (index (last 1 $path) 0) }} -> {{ partial "python-api-link-partial.html" (dict "paragraph" $objData.signature.return_annotation "context" $context) }}
{{ (index (last 1 $path) 0) }} -> {{ partial "api-ref-link-partial.html" (dict "paragraph" $objData.signature.return_annotation "context" $context) }}
</code></p>
{{ end }}

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

Expand All @@ -41,8 +41,8 @@ <h4> Parameters </h4>
{{range $objData.docstring_parsed.params}}
<tr>
<td> {{ .arg_name }} </td>
<td> {{ partial "python-api-link-partial.html" (dict "paragraph" .type_name "context" $context) }} </td>
<td> {{ partial "python-api-link-all-partial.html" (dict "paragraph" (.description | safeHTML) "context" $context) }} </td>
<td> {{ partial "api-ref-link-partial.html" (dict "paragraph" .type_name "context" $context) }} </td>
<td> {{ partial "api-ref-link-all-partial.html" (dict "paragraph" (.description | safeHTML) "context" $context) }} </td>
</tr>
{{end}}
</tbody>
Expand All @@ -63,7 +63,7 @@ <h4> Parameters </h4>
{{range $objData.signature.params}}
<tr>
<td> {{ index . 0 }} </td>
<td> {{ partial "python-api-link-partial.html" (dict "paragraph" (index . 1) "context" $context) }} </td>
<td> {{ partial "api-ref-link-partial.html" (dict "paragraph" (index . 1) "context" $context) }} </td>
<td> <i> None </i> </td>
</tr>
{{end}}
Expand Down Expand Up @@ -101,11 +101,11 @@ <h4> Returns </h4>
<tbody>
<tr>
<td>
{{ partial "python-api-link-partial.html" (dict "paragraph" $typeName "context" $context) }}
{{ partial "api-ref-link-partial.html" (dict "paragraph" $typeName "context" $context) }}
</td>
<td>
{{ if $description }}
{{ partial "python-api-link-all-partial.html" (dict "paragraph" ($objData.docstring_parsed.returns.description | safeHTML) "context" $context) }}
{{ partial "api-ref-link-all-partial.html" (dict "paragraph" ($objData.docstring_parsed.returns.description | safeHTML) "context" $context) }}
{{ else }}
<i> None </i>
{{ end }}
Expand All @@ -124,8 +124,8 @@ <h4> Returns </h4>
<h1> {{index (last 2 $path) 0}}.{{ index (last 1 $path) 0 }} </h1>
{{ if $objData.docstring_parsed }}
<div class="python-ref-description">
<p> {{ partial "python-api-link-all-partial.html" (dict "paragraph" ($objData.docstring_parsed.short_description | safeHTML) "context" $context) }}</p>
<p> {{ partial "python-api-link-all-partial.html" (dict "paragraph" ($objData.docstring_parsed.long_description | safeHTML) "context" $context) }}</p>
<p> {{ partial "api-ref-link-all-partial.html" (dict "paragraph" ($objData.docstring_parsed.short_description | safeHTML) "context" $context) }}</p>
<p> {{ partial "api-ref-link-all-partial.html" (dict "paragraph" ($objData.docstring_parsed.long_description | safeHTML) "context" $context) }}</p>
</div>
{{ end }}
{{end}}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
{{ $path := split .path "." }}
{{ $jsonPath := printf "versioned_docs/%s/data.json" (partial "version.html" (dict "context" .context )).dirpath }}

{{ with getJSON (printf "versioned_docs/%s/data.json") (partial "version.html" (dict "context" .context )).dirpath }}
{{ if fileExists $jsonPath }}

{{ with getJSON $jsonPath }}
{{ $currentData := . }}
{{ range $path }}
{{ if (eq $currentData.kind "class") }}
Expand All @@ -17,6 +20,10 @@


<div class="python-ref">
{{ partial "python-object.html" (dict "object" $objData "path" $path "context" .) }}
{{ partial "api-ref-object-partial.html" (dict "object" $objData "path" $path "context" .) }}
</div>
{{ end }}

{{ else }}
Missing data.json for this version!
{{ end }}
29 changes: 29 additions & 0 deletions docs/layouts/shortcodes/api-ref-base.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{{ $page := . }}
{{ $dirpath := (partial "version.html" (dict "context" .)).dirpath }}

{{ $jsonPath := printf "versioned_docs/%s/data.json" $dirpath }}

{{ if fileExists $jsonPath }}

{{ with getJSON $jsonPath }}
{{ $data := . }}
{{ with getJSON (printf "versioned_docs/%s/links.json" $dirpath) }}
{{ $links := . }}
<style>
html {
scroll-behavior: smooth;
}
</style>
<div class="python-api-ref-link">
{{ range $name, $data := $links }}
{{ $path := $data.path }}
<span style="top: -250px; position: relative;" id="{{ $path }}"></span>
{{ partial "api-ref-partial.html" $path }}
{{ end }}
</div>
{{ end }}
{{ end }}

{{ else }}
Missing data.json for this version!
{{ end }}
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
{{ $path := split (.Get 0) "." }}
{{ $page := .Page }}
{{ $jsonPath := printf "versioned_docs/%s/data.json" (partial "version.html" (dict "context" $page)).dirpath }}

{{ with getJSON (printf "versioned_docs/%s/data.json" (partial "version.html" (dict "context" $page)).dirpath) }}
{{ $currentData := . }}
{{ range $path }}
{{ if (eq $currentData.kind "class") }}
{{ $currentData = $currentData.functions }}
{{ end }}
{{$currentData = index $currentData .}}
{{ if fileExists $jsonPath }}

{{ with getJSON $jsonPath }}
{{ $currentData := . }}
{{ range $path }}
{{ if (eq $currentData.kind "class") }}
{{ $currentData = $currentData.functions }}
{{ end }}
{{$currentData = index $currentData .}}
{{ end }}

{{ $objData := $currentData }}

{{ $publicMethodsCounter := 0 }}
{{ $publicPropertiesCounter := 0 }}
{{ $objData := $currentData }}

{{ range $name, $func := $objData.functions }}
{{ $publicMethodsCounter := 0 }}
{{ $publicPropertiesCounter := 0 }}

{{ range $name, $func := $objData.functions }}
{{ if (not (hasPrefix $name "_"))}}
{{ if $func.is_property }}
{{ $publicPropertiesCounter = add $publicPropertiesCounter 1 }}
Expand All @@ -24,11 +28,10 @@
{{ end }}
{{ end }}

{{ end }}

{{ end }}

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

<h2> Properties </h2>
{{ if gt $publicPropertiesCounter 0 }}
Expand All @@ -45,10 +48,10 @@ <h2> Properties </h2>
<tr>

<td>
{{ partial "python-api-link-partial.html" (dict "paragraph" $name "context" $page) }}
{{ partial "api-ref-link-partial.html" (dict "paragraph" $name "context" $page) }}
</td>
{{ if $func.docstring_parsed }}
<td>{{ partial "python-api-link-all-partial.html" (dict "paragraph" $func.docstring_parsed.short_description "context" $page) }}</td>
<td>{{ partial "api-ref-link-all-partial.html" (dict "paragraph" $func.docstring_parsed.short_description "context" $page) }}</td>
{{ else }}
<td><i>None</i></td>
{{ end }}
Expand Down Expand Up @@ -77,12 +80,12 @@ <h2>Methods</h2>
<tr>

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

<td>{{ partial "python-api-link-partial.html" (dict "paragraph" $name "context" $page) }}({{- $parenthesisArgsString -}})
<td>{{ partial "api-ref-link-partial.html" (dict "paragraph" $name "context" $page) }}({{- $parenthesisArgsString -}})
</td>
{{ if $func.docstring_parsed }}
<td>{{ partial "python-api-link-all-partial.html" (dict "paragraph" $func.docstring_parsed.short_description "context" $page) }}</td>
<td>{{ partial "api-ref-link-all-partial.html" (dict "paragraph" $func.docstring_parsed.short_description "context" $page) }}</td>
{{ else }}
<td><i>None</i></td>
{{ end }}
Expand All @@ -97,3 +100,7 @@ <h2>Methods</h2>

</div>
{{ end }}

{{ else }}
Missing data.json for this version!
{{ end }}
1 change: 1 addition & 0 deletions docs/layouts/shortcodes/api-ref-link.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{ partial "api-ref-link-partial.html" (dict "paragraph" (index .Params 0) "context" .Page)}}
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
{{ $path := split (.Get 0) "." }}
{{ $page := .Page }}
{{ $data := getJSON (printf "versioned_docs/%s/data.json" (partial "version.html" (dict "context" .Page)).dirpath) }}
{{ $jsonPath := printf "versioned_docs/%s/data.json" (partial "version.html" (dict "context" .Page)).dirpath }}

{{ if fileExists $jsonPath }}
{{ $data := getJSON $jsonPath }}


{{ $currentData := $data}}
Expand All @@ -27,10 +30,14 @@
{{ if ne $objName "kind" }}
<tr>
<td>{{$objData.kind}}</td>
<td>{{partial "python-api-link-partial.html" (dict "paragraph" $objName "context" $page) }} </td>
<td>{{partial "api-ref-link-partial.html" (dict "paragraph" $objName "context" $page) }} </td>
</tr>
{{ end }}
{{ end }}
</tbody>
</table>
</div>

{{ else }}
Missing data.json for this version!
{{ end }}
34 changes: 34 additions & 0 deletions docs/layouts/shortcodes/api-ref.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{{ $page := .Page }}
{{ $path := split (.Get 0) "." }}
{{ $version := partial "version.html" (dict "context" $page)}}
{{ $jsonPath := printf "versioned_docs/%s/data.json" $version.dirpath }}

{{ if fileExists $jsonPath }}

{{ if and $version $version.dirpath }}
{{ with getJSON $jsonPath }}
{{ $currentData := .}}
{{ range $path }}
{{ if (eq $currentData.kind "class") }}
{{ $currentData = $currentData.functions }}
{{ end }}
{{$currentData = index $currentData .}}
{{ end }}

{{ $objData := $currentData }}


<div class="python-ref">
{{ partial "api-ref-object-partial.html" (dict "object" $objData "path" $path "context" $page) }}
</div>
{{ end }}

{{ else }}

Problem parsing the data.json!

{{ end }}

{{ else }}
Missing data.json for this version!
{{ end }}
1 change: 0 additions & 1 deletion docs/layouts/shortcodes/python-api-link.html

This file was deleted.

21 changes: 0 additions & 21 deletions docs/layouts/shortcodes/python-api-ref.html

This file was deleted.

26 changes: 0 additions & 26 deletions docs/layouts/shortcodes/python.html

This file was deleted.

2 changes: 1 addition & 1 deletion docs/module_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ linkTitle: "LINK"
no_list: true
---

{{< python-module "PATH" >}}
{{< api-ref-module "PATH" >}}

0 comments on commit aa6b50c

Please sign in to comment.