Skip to content

Commit

Permalink
preprocessor: support hidden uploads
Browse files Browse the repository at this point in the history
This allows guides which only choose to present select files (as opposed
to a full tutorial from start to end) can still be validated as working,
by uploading files which the user does not see. (The files themselves
are not hidden, just the upload block itself is not rendered in the Hugo
output).

Preprocessor-No-Write-Cache: true
Signed-off-by: Paul Jolly <[email protected]>
Change-Id: Ia7289d0fc730c744375c23a4136e57493baa1fcb
Dispatch-Trailer: {"type":"trybot","CL":1177013,"patchset":3,"ref":"refs/changes/13/1177013/3","targetBranch":"alpha"}
  • Loading branch information
myitcv authored and cueckoo committed Feb 19, 2024
1 parent 4e19126 commit e366fe8
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 4 deletions.
8 changes: 6 additions & 2 deletions internal/cmd/preprocessor/cmd/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,12 +216,16 @@ func (rf *rootFile) parse_WithNode(n *parse.WithNode) (node, error) {
// Increment first because we are numbering from 1
rf.stepNumber++
return rf.parse_stepNode(n, rf.stepNumber)
case fnUpload:
case fnUpload, fnHiddenUpload:
hidden := fn.Ident == fnHiddenUpload
t, err := rf.parse_txtarNode(n, fn.Ident, c.Args[1:])
if err != nil {
return nil, err
}
return &uploadNode{txtarNode: t}, nil
return &uploadNode{
txtarNode: t,
hidden: hidden,
}, nil
case fnScript, fnHiddenScript:
hidden := fn.Ident == fnHiddenScript
t, err := rf.parse_txtarNode(n, fn.Ident, c.Args[1:])
Expand Down
1 change: 1 addition & 0 deletions internal/cmd/preprocessor/cmd/rootfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ var (
fnCode: true,
fnStep: true,
fnUpload: true,
fnHiddenUpload: true,
fnScript: true,
fnHiddenScript: true,
"reference": true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ content: dir: page: {
>title: JSON Superset
>---
>{{{with step}}}
>
>{{{with _upload "en" "hidden file"}}}
>-- hidden.txt --
>Secret message
>{{{end}}}
>
>{{{with upload "en" "upload-some-cue"}}}
>#codetab(in.cue) linenos="table"
>-- in.cue --
Expand Down Expand Up @@ -121,6 +127,12 @@ content: dir: page: {
>title: JSON Superset
>---
>{{{with step}}}
>
>{{{with _upload "en" "hidden file"}}}
>-- hidden.txt --
>Secret message
>{{{end}}}
>
>{{{with upload "en" "upload-some-cue"}}}
>#codetab(in.cue) linenos="table"
>-- in.cue --
Expand Down Expand Up @@ -233,12 +245,13 @@ package site
page: {
cache: {
upload: {
"hidden file": "4YPap9a6NsyJd6KTPyStBOl3FcJsYecsnKRpcixFfrY="
"upload-some-cue": "mk/eGLXQi8f2VHFEAJ+OVwSB0C/zK9S8nvtSvKYNyVo="
"upload-some-json": "aOFY1SpvCxmIPWnBoZDfTCvL90OvzbTTD3gqObCa75w="
"in-subdir": "zLF5NHI4Y1eaRJ7n4t6bN//ptgOj2snRyP3DNUSUZrw="
}
multi_step: {
"L4H91P78HIDIAEMM7U0CA93FTU24VD5B7K7E0BRUPJPUM8AV9RV0====": [{
"3UA3H59NARBLHE6A3D5HAM0BD8RJH3L54NR16HOO9JUDU58IM1HG====": [{
doc: """
# script doc comment
#scripttag
Expand Down
13 changes: 12 additions & 1 deletion internal/cmd/preprocessor/cmd/upload_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,17 @@ import (
"bytes"
)

const fnUpload = "upload"
const (
fnUpload = "upload"
fnHiddenUpload = "_upload"
)

type uploadNode struct {
txtarNode

// hidden is set to indicate the script exists for side effects
// only and will not be rendered
hidden bool
}

var _ validatingNode = (*uploadNode)(nil)
Expand All @@ -30,6 +37,10 @@ func (u *uploadNode) nodeType() string {
return "upload"
}

func (u *uploadNode) isHidden() bool {
return u.hidden
}

func (u *uploadNode) validate() {
if l := len(u.analysis.fileNames); l != 1 {
u.errorf("%v: upload nodes can only contain a single file; saw %d", u, l)
Expand Down

0 comments on commit e366fe8

Please sign in to comment.