Back to Redis

Commands Foldout

layouts/partials/commands-foldout.html

latest4.1 KB
Original Source

{{/* Commands foldout partial - displays commands with summaries, links, and API method signatures Parameters: - commands: List of command names - id: Unique ID for the codetabs instance - tabTitle: The tab title (e.g., "Python", "Node.js") used to look up mappingClientId */}} {{ $commands := .commands }} {{ $id := .id }} {{ $tabTitle := .tabTitle }} {{/* Get the mappingClientId from clientsConfig based on tabTitle */}} {{ $clientConfig := index site.Params.clientsConfig $tabTitle }} {{ $mappingClientId := "" }} {{ if $clientConfig }} {{ $mappingClientId = index $clientConfig "mappingClientId" }} {{ end }} {{/* Access the command-api-mapping data (using index with hyphenated key) */}} {{ $apiMapping := index site.Data "command-api-mapping" }} {{/* Access overrides (manual corrections that take precedence over generated data) */}} {{ $apiOverrides := index site.Data "command-api-mapping-overrides" }} {{ if $commands }}

▼ Commands: {{ delimit $commands ", " }}

{{ range $commands }} {{ $cmdName := . }} {{/* Try to find command in multiple data files */}} {{ $cmdData := (index site.Data.commands_core $cmdName) | default (index site.Data.commands_redisearch $cmdName) | default (index site.Data.commands_redisjson $cmdName) | default (index site.Data.commands_redistimeseries $cmdName) | default (index site.Data.commands_redisbloom $cmdName) }} {{/* Look up API method signatures for this command and client */}} {{/* Check overrides first, then fall back to generated data */}} {{ $apiSignatures := slice }} {{ if $mappingClientId }} {{/* Try overrides first */}} {{ $overrideFound := false }} {{ if $apiOverrides }} {{ $overrideCmd := index $apiOverrides $cmdName }} {{ if $overrideCmd }} {{ $overrideApiCalls := index $overrideCmd "api_calls" }} {{ if $overrideApiCalls }} {{ $overrideClientSigs := index $overrideApiCalls $mappingClientId }} {{ if $overrideClientSigs }} {{ $apiSignatures = $overrideClientSigs }} {{ $overrideFound = true }} {{ end }} {{ end }} {{ end }} {{ end }} {{/* Fall back to generated data if no override found */}} {{ if and (not $overrideFound) $apiMapping }} {{ $cmdMapping := index $apiMapping $cmdName }} {{ if $cmdMapping }} {{ $apiCalls := index $cmdMapping "api_calls" }} {{ if $apiCalls }} {{ $clientSigs := index $apiCalls $mappingClientId }} {{ if $clientSigs }} {{ $apiSignatures = $clientSigs }} {{ end }} {{ end }} {{ end }} {{ end }} {{ end }} - {{ if $cmdData }}

[{{ $cmdName }}]({{%20absURL%20(printf) {{ if $cmdData.acl_categories }} ( {{ range $idx, $category := $cmdData.acl_categories }} {{ if gt $idx 0 }}, {{ end }} {{ $categoryId := lower (replace $category "@" "") }} [{{ $category }}]({{%20absURL%20(printf "{{ $category }}") {{ end }} ) {{ end }} {{ if $cmdData.summary }} {{ $cmdData.summary }} {{ end }} {{/* Display API method signatures if available - as mini foldout */}} {{ if gt (len $apiSignatures) 0 }} ▶Method{{ if gt (len $apiSignatures) 1 }}s{{ end }}

{{ range $apiSignatures }} {{ $params := .params }} {{ $returns := .returns }} {{/* Extract method name - handle Java-style "ReturnType methodName(" by taking last word */}} {{ $beforeParen := index (split .signature "(") 0 }} {{ $parts := split $beforeParen " " }} {{ $methodName := index $parts (sub (len $parts) 1) }} - {{/* Method name */}} {{ $methodName }}( {{/* Parameters - one per line if we have structured params */}} {{ if and $params (gt (len $params) 0) }} {{ range $idx, $param := $params }} - {{ $param.name }}{{ if $param.type }}: {{ $param.type }}{{ end }}{{ if lt $idx (sub (len $params) 1) }},{{ end }}{{ if and $param.description (ne $param.description "") }} // {{ $param.description }}{{ end }} {{ end }} {{ end }} {{/* Return type - handle both string and object formats */}} {{ 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 }} {{ else }} ) {{ end }} {{ end }}

{{ end }} {{ else }} {{ $cmdName }} {{ end }} {{ end }}

{{ end }}