Пример #1
0
func TestSingular(t *testing.T) {
	for key, value := range inflections {
		if v := inflection.Singular(strings.ToUpper(value)); v != strings.ToUpper(key) {
			t.Errorf("%v's singular should be %v, but got %v", strings.ToUpper(value), strings.ToUpper(key), v)
		}

		if v := inflection.Singular(strings.Title(value)); v != strings.Title(key) {
			t.Errorf("%v's singular should be %v, but got %v", strings.Title(value), strings.Title(key), v)
		}

		if v := inflection.Singular(value); v != key {
			t.Errorf("%v's singular should be %v, but got %v", value, key, v)
		}
	}
}
Пример #2
0
func (admin *Admin) AddResource(value interface{}, config ...*Config) *Resource {
	res := admin.NewResource(value, config...)

	if !res.Config.Invisible {
		var menuName string
		if res.Config.Singleton {
			menuName = inflection.Singular(res.Name)
		} else {
			menuName = inflection.Plural(res.Name)
		}

		menu := &Menu{rawPath: res.ToParam(), Name: menuName}
		admin.menus = appendMenu(admin.menus, res.Config.Menu, menu)
	}

	admin.resources = append(admin.resources, res)
	return res
}
Пример #3
0
func Singular(s string) string {
	return inflection.Singular(s)
}
Пример #4
0
func (res Resource) ToParam() string {
	if res.Config.Singleton == true {
		return utils.ToParamString(inflection.Singular(res.Name))
	}
	return utils.ToParamString(inflection.Plural(res.Name))
}