diff --git a/layouts/develop/single.html b/layouts/develop/single.html index 77511c978f..52e6fa0fb5 100644 --- a/layouts/develop/single.html +++ b/layouts/develop/single.html @@ -1,5 +1,6 @@ {{ define "head" }} + {{ end }} {{ define "main" }} diff --git a/layouts/partials/tabbed-clients-example.html b/layouts/partials/tabbed-clients-example.html index 1c7a00d8b2..7218ee5453 100644 --- a/layouts/partials/tabbed-clients-example.html +++ b/layouts/partials/tabbed-clients-example.html @@ -39,6 +39,20 @@ {{ warnf "[tabbed-clients-example] Example not found %q for %q" $id $.Page }} {{ end }} +{{/* Extract executable CLI commands (lines starting with "> " or "redis> ") for Try It button */}} +{{ $tryItCommands := slice }} +{{ if (ne (trim $redisCommands "\n") "") }} + {{ range $line := split (trim $redisCommands "\n") "\n" }} + {{ $trimmedLine := trim $line " " }} + {{ if hasPrefix $trimmedLine "redis> " }} + {{ $tryItCommands = $tryItCommands | append (strings.TrimPrefix "redis> " $trimmedLine) }} + {{ else if hasPrefix $trimmedLine "> " }} + {{ $tryItCommands = $tryItCommands | append (strings.TrimPrefix "> " $trimmedLine) }} + {{ end }} + {{ end }} +{{ end }} + + {{ $tabs := slice }} {{/* Render redis-cli example from inner content if any */}} {{ if (ne (trim $redisCommands "\n") "") }} @@ -66,7 +80,22 @@ {{ if and (gt $redisCommandsLineLimitInt 0) (gt $estimatedVisualLineCount $redisCommandsLineLimitInt) }} {{ $hasCliTrim = true }} {{ end }} - {{ $redisCliContent := highlight $trimmedRedisCommands "plaintext" "linenos=false" }} + {{/* Render the redis-cli tab as an interactive terminal (form.redis-cli is + picked up by cli.js and executed inline). Only redis-cli is interactive; + other language tabs stay as static highlighted code. */}} + {{ $cliCommandLines := $tryItCommands }} + {{ if eq (len $cliCommandLines) 0 }} + {{ range $line := $redisCommandLines }} + {{ $trimmedCliLine := trim $line " \t\r" }} + {{ if $trimmedCliLine }}{{ $cliCommandLines = $cliCommandLines | append $trimmedCliLine }}{{ end }} + {{ end }} + {{ end }} + {{ $cliJoined := delimit $cliCommandLines "\n" }} + {{ $cliFormInner := htmlEscape $cliJoined }} + {{ $cliSourceAttr := replace (htmlEscape $cliJoined) "\n" " " }} + {{ $redisCliContent := printf "
\n%s\n
" $cliSourceAttr $cliFormInner | safeHTML }} + {{/* Trimming applies to static code blocks; the interactive terminal manages its own height. */}} + {{ $hasCliTrim = false }} {{ $cliTab := dict "title" "redis-cli" "displayName" $cliTabName "content" $redisCliContent "limit" $redisCommandsLineLimit "limitInt" $redisCommandsLineLimitInt "lineCount" $redisCommandLineCount "visualLineCount" $estimatedVisualLineCount "hasCliTrim" $hasCliTrim "customFooterLinkText" $cliFooterLinkText "customFooterLinkUrl" $cliFooterLinkUrl }} {{ if gt (len $commands) 0 }} {{ $cliTab = merge $cliTab (dict "commands" $commands) }} @@ -131,4 +160,7 @@ {{ if gt (len $buildsUpon) 0 }} {{ $params = merge $params (dict "buildsUpon" $buildsUpon) }} {{ end }} +{{ if gt (len $tryItCommands) 0 }} + {{ $params = merge $params (dict "tryItCommands" $tryItCommands) }} +{{ end }} {{ partial "tabs/wrapper.html" $params }} diff --git a/layouts/partials/tabs/wrapper.html b/layouts/partials/tabs/wrapper.html index fd9553d09d..87e0782559 100644 --- a/layouts/partials/tabs/wrapper.html +++ b/layouts/partials/tabs/wrapper.html @@ -9,6 +9,7 @@ {{ $description := .description }} {{ $difficulty := .difficulty }} {{ $buildsUpon := .buildsUpon }} +{{ $tryItCommands := .tryItCommands }} {{- /* Build metadata map for each language/client combination */ -}} {{- $codetabsMeta := dict -}} @@ -73,7 +74,7 @@ {{- if $exampleId -}} {{- end -}} -
+
@@ -101,6 +102,21 @@
+ {{/* "Try it" button - opens redis.io/cli with pre-populated commands */}} + {{ if $tryItCommands }} + + {{ end }} {{/* BinderHub "Run in browser" link - shown conditionally based on current tab's binderId */}}