Beispiel #1
0
func (s *Site) getMenusFromConfig() Menus {

	ret := Menus{}

	if menus := viper.GetStringMap("menu"); menus != nil {
		for name, menu := range menus {
			m, err := cast.ToSliceE(menu)
			if err != nil {
				jww.ERROR.Printf("unable to process menus in site config\n")
				jww.ERROR.Println(err)
			} else {
				for _, entry := range m {
					jww.DEBUG.Printf("found menu: %q, in site config\n", name)

					menuEntry := MenuEntry{Menu: name}
					ime, err := cast.ToStringMapE(entry)
					if err != nil {
						jww.ERROR.Printf("unable to process menus in site config\n")
						jww.ERROR.Println(err)
					}

					menuEntry.MarshallMap(ime)
					if ret[name] == nil {
						ret[name] = &Menu{}
					}
					*ret[name] = ret[name].Add(&menuEntry)
				}
			}
		}
		return ret
	}
	return ret
}
Beispiel #2
0
func (s *Site) getMenusFromConfig() Menus {

	ret := Menus{}

	if menus := viper.GetStringMap("menu"); menus != nil {
		for name, menu := range menus {
			m, err := cast.ToSliceE(menu)
			if err != nil {
				jww.ERROR.Printf("unable to process menus in site config\n")
				jww.ERROR.Println(err)
			} else {
				for _, entry := range m {
					jww.DEBUG.Printf("found menu: %q, in site config\n", name)

					menuEntry := MenuEntry{Menu: name}
					ime, err := cast.ToStringMapE(entry)
					if err != nil {
						jww.ERROR.Printf("unable to process menus in site config\n")
						jww.ERROR.Println(err)
					}

					menuEntry.MarshallMap(ime)

					if strings.HasPrefix(menuEntry.Url, "/") {
						// make it match the nodes
						menuEntryUrl := menuEntry.Url
						menuEntryUrl = helpers.UrlizeAndPrep(menuEntryUrl)
						if !s.Info.canonifyUrls {
							menuEntryUrl = helpers.AddContextRoot(string(s.Info.BaseUrl), menuEntryUrl)
						}
						menuEntry.Url = menuEntryUrl
					}

					if ret[name] == nil {
						ret[name] = &Menu{}
					}
					*ret[name] = ret[name].Add(&menuEntry)
				}
			}
		}
		return ret
	}
	return ret
}
Beispiel #3
0
func (c *FlatMapConfig) Flatten(src interface{}) (map[string]interface{}, error) {
	var err error

	result := make(map[string]interface{})

	if reflect.TypeOf(src).Kind() == reflect.Map {
		var s map[string]interface{}
		s, err = cast.ToStringMapE(src)
		if err != nil {
			return result, err
		}

		for k, raw := range s {
			err = c.flatten(result, k, reflect.ValueOf(raw))
			if err != nil {
				break
			}
		}

	} else if reflect.TypeOf(src).Kind() == reflect.Slice {
		var s []interface{}
		s, err = cast.ToSliceE(src)
		if err != nil {
			return result, err
		}

		for i, raw := range s {
			err = c.flatten(result, c.sliceKeyTemplate(i), reflect.ValueOf(raw))
			if err != nil {
				break
			}
		}
	} else {
		err = fmt.Errorf("Unknown type for interface")
	}

	return result, err
}
Beispiel #4
0
func (s *Site) getMenusFromConfig() Menus {

	ret := Menus{}

	if menus := viper.GetStringMap("menu"); menus != nil {
		for name, menu := range menus {
			m, err := cast.ToSliceE(menu)
			if err != nil {
				jww.ERROR.Printf("unable to process menus in site config\n")
				jww.ERROR.Println(err)
			} else {
				for _, entry := range m {
					jww.DEBUG.Printf("found menu: %q, in site config\n", name)

					menuEntry := MenuEntry{Menu: name}
					ime, err := cast.ToStringMapE(entry)
					if err != nil {
						jww.ERROR.Printf("unable to process menus in site config\n")
						jww.ERROR.Println(err)
					}

					menuEntry.MarshallMap(ime)
					if strings.HasPrefix(menuEntry.Url, "/") {
						// make it absolute so it matches the nodes
						menuEntry.Url = s.permalinkStr(menuEntry.Url)
					}
					if ret[name] == nil {
						ret[name] = &Menu{}
					}
					*ret[name] = ret[name].Add(&menuEntry)
				}
			}
		}
		return ret
	}
	return ret
}