Back to Redis

Api Methods Tab

layouts/partials/components/api-methods-tab.html

latest3.0 KB
Original Source

{{/* API Methods tab content - displays client library method signatures for a Redis command Parameters: - commandName: The Redis command name (e.g., "SET", "GET") This partial renders: - A client selector dropdown - Method signatures for the selected client - All client signatures are rendered but hidden, shown via JS based on selection */}} {{ $commandName := .commandName }} {{ $apiMapping := index site.Data "command-api-mapping" }} {{ $apiOverrides := index site.Data "command-api-mapping-overrides" }} {{ $cmdMapping := index $apiMapping $commandName }} {{ $cmdOverrides := index $apiOverrides $commandName }} {{/* Define client order explicitly */}} {{ $clientOrder := slice "Python" "Node.js" "Java-Sync" "Lettuce-Sync" "Java-Async" "Java-Reactive" "Go" "C#-Sync" "C#-Async" "PHP" "Rust-Sync" "Rust-Async" }}

{{/* Client selector */}} Client: {{ range $tabName := $clientOrder }} {{ $config := index site.Params.clientsConfig $tabName }} {{ if $config }} {{ $mappingId := index $config "mappingClientId" }} {{ if and $mappingId (ne $mappingId "") }} {{ $clientName := index $config "clientName" }} {{ $tabName }} ({{ $clientName }}) {{ end }} {{ end }} {{ end }} {{/* Method signatures container - all clients rendered, visibility controlled by JS */}} {{ if or $cmdMapping $cmdOverrides }} {{ $apiCalls := index $cmdMapping "api_calls" }} {{ $overrideApiCalls := index $cmdOverrides "api_calls" }} {{ $first := true }} {{ range $tabName := $clientOrder }} {{ $config := index site.Params.clientsConfig $tabName }} {{ if $config }} {{ $mappingId := index $config "mappingClientId" }} {{ if and $mappingId (ne $mappingId "") }} {{/* Check overrides first, then fall back to generated data */}} {{ $clientSigs := slice }} {{ $overrideSigs := index $overrideApiCalls $mappingId }} {{ if $overrideSigs }} {{ $clientSigs = $overrideSigs }} {{ else }} {{ $clientSigs = index $apiCalls $mappingId }} {{ end }} {{ if $clientSigs }}

{{ range $idx, $sig := $clientSigs }}{{ if gt $idx 0 }}

{{ end }}{{ $params := $sig.params }}{{ $returns := $sig.returns }}{{ $beforeParen := index (split $sig.signature "(") 0 }}{{ $parts := split $beforeParen " " }}{{ $methodName := index $parts (sub (len $parts) 1) }}{{ $methodName }}({{ if and $params (gt (len $params) 0) }}
{{ range $pIdx, $param := $params }} {{ $param.name }}{{ if $param.type }}: {{ $param.type }}{{ end }}{{ if lt $pIdx (sub (len $params) 1) }},{{ end }}{{ if and $param.description (ne $param.description "") }} // {{ $param.description }}{{ end }}
{{ end }}{{ end }}){{ if $returns }} → {{ if reflect.IsMap $returns }}{{ index $returns "type" }}{{ if and (index $returns "description") (ne (index $returns "description") "") }} // {{ index $returns "description" }}{{ end }}{{ else }}{{ $returns }}{{ end }}{{ end }}{{ end }}

{{ else }}

No method signature available for this client.

{{ end }} {{ $first = false }} {{ end }} {{ end }} {{ end }} {{ else }}

No API method signatures available for this command.

{{ end }}