github.com/mineiros-io/terradoc@v0.0.9-0.20220711062319-018bd4ae81f5/internal/entities/section.go (about) 1 package entities 2 3 // Section represents a `section` block from the input file. 4 type Section struct { 5 // Title is an optional title for the section. 6 Title string `json:"title"` 7 // Content is an optional text content for the section. 8 Content string `json:"content,omitempty"` 9 // Variables is a collection of variable definitions contained in the section block. 10 Variables []Variable `json:"variables,omitempty"` 11 // Ouputs is a collection of output definitions contained in the section block. 12 Outputs []Output `json:"outputs,omitempty"` 13 // SubSections is a collection of nested sections contained in the section block. 14 SubSections []Section `json:"subsections,omitempty"` 15 // Level is the nesting of this section 16 Level int `json:"-"` 17 // TOC is a flag for generating table of contents for nested sections 18 TOC bool `json:"-"` 19 } 20 21 func (s Section) AllVariables() (result VariableCollection) { 22 for _, v := range s.Variables { 23 result = append(result, v) 24 } 25 26 for _, s := range s.SubSections { 27 result = append(result, s.AllVariables()...) 28 } 29 30 return result 31 } 32 33 func (s Section) AllOutputs() (result OutputCollection) { 34 for _, o := range s.Outputs { 35 result = append(result, o) 36 } 37 38 for _, s := range s.SubSections { 39 result = append(result, s.AllOutputs()...) 40 } 41 42 return result 43 }