github.com/westcoastroms/westcoastroms-build@v0.0.0-20190928114312-2350e5a73030/build/soong/cmd/soong_build/writedocs.go (about)

     1  // Copyright 2017 Google Inc. All rights reserved.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package main
    16  
    17  import (
    18  	"android/soong/android"
    19  	"bytes"
    20  	"html/template"
    21  	"io/ioutil"
    22  
    23  	"github.com/google/blueprint/bootstrap"
    24  )
    25  
    26  func writeDocs(ctx *android.Context, filename string) error {
    27  	moduleTypeList, err := bootstrap.ModuleTypeDocs(ctx.Context)
    28  	if err != nil {
    29  		return err
    30  	}
    31  
    32  	buf := &bytes.Buffer{}
    33  
    34  	unique := 0
    35  
    36  	tmpl, err := template.New("file").Funcs(map[string]interface{}{
    37  		"unique": func() int {
    38  			unique++
    39  			return unique
    40  		}}).Parse(fileTemplate)
    41  	if err != nil {
    42  		return err
    43  	}
    44  
    45  	err = tmpl.Execute(buf, moduleTypeList)
    46  	if err != nil {
    47  		return err
    48  	}
    49  
    50  	err = ioutil.WriteFile(filename, buf.Bytes(), 0666)
    51  	if err != nil {
    52  		return err
    53  	}
    54  
    55  	return nil
    56  }
    57  
    58  const (
    59  	fileTemplate = `
    60  <html>
    61  <head>
    62  <title>Build Docs</title>
    63  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
    64  <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
    65  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
    66  </head>
    67  <body>
    68  <h1>Build Docs</h1>
    69  <div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true">
    70    {{range .}}
    71      {{ $collapseIndex := unique }}
    72      <div class="panel panel-default">
    73        <div class="panel-heading" role="tab" id="heading{{$collapseIndex}}">
    74          <h2 class="panel-title">
    75            <a class="collapsed" role="button" data-toggle="collapse" data-parent="#accordion" href="#collapse{{$collapseIndex}}" aria-expanded="false" aria-controls="collapse{{$collapseIndex}}">
    76               {{.Name}}
    77            </a>
    78          </h2>
    79        </div>
    80      </div>
    81      <div id="collapse{{$collapseIndex}}" class="panel-collapse collapse" role="tabpanel" aria-labelledby="heading{{$collapseIndex}}">
    82        <div class="panel-body">
    83          <p>{{.Text}}</p>
    84          {{range .PropertyStructs}}
    85            <p>{{.Text}}</p>
    86            {{template "properties" .Properties}}
    87          {{end}}
    88        </div>
    89      </div>
    90    {{end}}
    91  </div>
    92  </body>
    93  </html>
    94  
    95  {{define "properties"}}
    96    <div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true">
    97      {{range .}}
    98        {{$collapseIndex := unique}}
    99        {{if .Properties}}
   100          <div class="panel panel-default">
   101            <div class="panel-heading" role="tab" id="heading{{$collapseIndex}}">
   102              <h4 class="panel-title">
   103                <a class="collapsed" role="button" data-toggle="collapse" data-parent="#accordion" href="#collapse{{$collapseIndex}}" aria-expanded="false" aria-controls="collapse{{$collapseIndex}}">
   104                   {{.Name}}{{range .OtherNames}}, {{.}}{{end}}
   105                </a>
   106              </h4>
   107            </div>
   108          </div>
   109          <div id="collapse{{$collapseIndex}}" class="panel-collapse collapse" role="tabpanel" aria-labelledby="heading{{$collapseIndex}}">
   110            <div class="panel-body">
   111              <p>{{.Text}}</p>
   112              {{range .OtherTexts}}<p>{{.}}</p>{{end}}
   113              {{template "properties" .Properties}}
   114            </div>
   115          </div>
   116        {{else}}
   117          <div>
   118            <h4>{{.Name}}{{range .OtherNames}}, {{.}}{{end}}</h4>
   119            <p>{{.Text}}</p>
   120            {{range .OtherTexts}}<p>{{.}}</p>{{end}}
   121            <p><i>Type: {{.Type}}</i></p>
   122            {{if .Default}}<p><i>Default: {{.Default}}</i></p>{{end}}
   123          </div>
   124        {{end}}
   125      {{end}}
   126    </div>
   127  {{end}}
   128  `
   129  )