github.com/louisevanderlith/droxolite@v1.20.2/menu/menuitem.go (about)

     1  package menu
     2  
     3  import "strings"
     4  
     5  type Item struct {
     6  	ID       string
     7  	Text     string
     8  	Link     string
     9  	Active   bool
    10  	Enabled  bool
    11  	Hidden   bool
    12  	Children []Item `json:",omitempty"`
    13  }
    14  
    15  func NewItem(id, link, text string, children []Item) Item {
    16  	shortName := getUniqueName(text)
    17  	result := Item{
    18  		ID:      id,
    19  		Text:    text,
    20  		Enabled: true,
    21  		Hidden:  false,
    22  		Link:    link,
    23  		Active:  false,
    24  	}
    25  
    26  	if link == "#" {
    27  		result.Link += shortName
    28  	}
    29  
    30  	if children != nil {
    31  		result.Children = children
    32  	}
    33  
    34  	return result
    35  }
    36  
    37  func getUniqueName(raw string) string {
    38  	if len(raw) == 0 {
    39  		return "Home"
    40  	}
    41  
    42  	return strings.ToLower(strings.Replace(raw, " ", "", -1))
    43  }