github.com/upcmd/up@v0.8.1-0.20230108151705-ad8b797bf04f/tests/functests/c0083.yml (about)

     1  
     2  notes:
     3    goal:
     4      - skip this
     5      - spike on the auto documentation
     6  
     7  vars:
     8  
     9    doc_meta: |
    10      folder: spike
    11      title: Doco auto generation
    12      head: This is to prototype doco auto generation
    13      head_content: |-
    14        This is to prototype doco auto generation, provided all these meta data, up cmd can help generate
    15        a auto doco
    16  
    17      sections:
    18        - title: Intro
    19          content: |
    20            The up project uses auto generate doco, for community memebers, if you would like to contribute
    21            use case or any interesting usage of up cmd, you could raise a pull request and commit your func
    22            test case and do complete your test and automated regression tests
    23  
    24        - title: How to use?
    25          content: |
    26            Config docs->meta data configuration
    27            add reference link
    28          refs:
    29            - title: main task file
    30              type: yml
    31              link: {{.doc_dir}}/c0083.yml
    32  
    33        - title: Steps
    34          content: |
    35            * Firstly, it will try to create the folder if it does not exist
    36            add reference link
    37          refs:
    38            - title: logfile
    39              type: txt
    40              link: {{.doc_dir}}/c0083.log
    41  
    42      related:
    43        refs:
    44          - title: main task file
    45            link: main.html
    46  
    47    doc_templatex: |
    48       {{.head}}
    49  
    50    doc_template: |
    51      ---
    52      title: "{{.title}}"
    53      date: {{now}}
    54      draft: false
    55  
    56      ---
    57  
    58      ## {{.head}}
    59  
    60      {{.head_content}}
    61  
    62      {{- range $x :=.sections }}
    63  
    64      ### {{$x.title}}
    65  
    66      {{$x.content}}
    67  
    68        {{- range $ref :=.refs }}
    69      ##### ref: {{$ref.title}}
    70  
    71      ```
    72      {{$ref.link |fileContent|indent 4}}
    73      ```
    74        {{- end}}
    75  
    76      {{- end}}
    77  
    78      ### Other references:
    79      {{ with .related }}
    80        {{- range $ref :=.refs }}
    81      {{$ref.title}}: {{$ref.link}}
    82        {{- end}}
    83      {{ end }}
    84  
    85  dvars:
    86    - name: intest
    87      value: '{{ env "GOTEST" |default "false" }}'
    88  
    89  tasks:
    90    -
    91      name: task
    92      task:
    93        -
    94          func: call
    95          do:
    96            - setup
    97            - compose_required_object
    98            - render
    99  
   100    -
   101      name: compose_required_object
   102      desc: prepare the data object for rendering
   103      task:
   104        -
   105          func: cmd
   106          dvars:
   107            - name: doc_meta_yml
   108              expand: 2
   109              value: '{{.doc_meta}}'
   110              flags: [reg, toObj]
   111          do:
   112            - name: print
   113              cmd: '{{.doc_meta_yml}}'
   114  
   115        -
   116          func: cmd
   117          do:
   118            - name: print
   119              desc: shows that reg has set this var to global space
   120              cmd: '{{.doc_meta_yml}}'
   121            - name: printObj
   122              cmd: doc_meta_yml_object
   123  
   124    -
   125      name: setup
   126      task:
   127  
   128        - func: shell
   129          do:
   130            - echo "?intest ->  {{.intest}}"
   131            - pwd
   132          reg: register_render_root
   133  
   134        - func: cmd
   135          do:
   136            - name: print
   137              cmd: 'intest is: [{{.intest}}]'
   138  
   139            - name: reg
   140              cmd:
   141                name: correct_working_dir
   142                desc: the value of .intest is string but not bool so you can not simple use if .intest for condition
   143                value: >-
   144                  {{if eq .intest "true" }}{{.register_render_root.Output}}/../..{{else}}{{.register_render_root.Output}}{{end}}
   145  
   146        - func: cmd
   147          do:
   148            - name: print
   149              cmd: 'root dir is: [{{.register_render_root.Output}}]'
   150  
   151            - name: print
   152              cmd: 'correct working dir is: [{{.correct_working_dir}}]'
   153  
   154            - name: reg
   155              cmd:
   156                name: doc_dir
   157                desc: register a doc_dir to be used in rendering template
   158                value: '{{.correct_working_dir}}/tests/functests'
   159  
   160            - name: print
   161              cmd: 'doc dir is: [{{.doc_dir}}]'
   162  
   163    -
   164      name: render
   165      task:
   166  
   167        -
   168          func: cmd
   169          desc: debug and print doc_template
   170          dvars:
   171            - name: doc_rendered
   172              value: '{{.doc_template}}'
   173          do:
   174            -
   175              name: print
   176              cmd: "{{.doc_template}}"
   177  
   178            -
   179              name: print
   180              cmd: "{{.doc_rendered}}"
   181  
   182        -
   183          func: cmd
   184          desc: |
   185            debug and print doc_template
   186            it is expected no value will be rendered as the
   187            template expecting a data object
   188          dvars:
   189            - name: doc_rendered
   190              value: '{{.doc_template}}'
   191              expand: 2
   192          do:
   193  
   194            -
   195              name: print
   196              desc: it will not be rendered as the variable is not in global space
   197              cmd: "{{.doc_rendered}}"
   198  
   199        -
   200          func: cmd
   201          desc: |
   202            render using doc_meta_yml_object as data rather than the default vas in global space
   203            what happens here is that it will do regular 1 layer expand, then apply another expand
   204            using the specified data object, so you do not need to specify expand: 2 as implicitly
   205            there are actually 2 expansion
   206          dvars:
   207            - name: doc_rendered
   208              value: '{{.doc_template}}'
   209              datakey: doc_meta_yml_object
   210          do:
   211  #          -
   212  #            name: print
   213  #            cmd: "{{.doc_rendered}}"
   214            -
   215              name: writeFile
   216              cmd:
   217                content: "{{.doc_rendered}}"
   218                filename: spike_doc.md
   219  #              dir: '{{env "SPIKE_DOC_PATH"}}/'
   220                dir: /tmp
   221  
   222            -
   223              name: readFile
   224              cmd:
   225                filename: spike_doc.md
   226                dir: /tmp
   227                reg: loaded_doc