示例#1
0
文件: builtins.go 项目: Laller/chill
func _url(action_name string, r *lang.Route, s *lang.Sentence, i ...interface{}) string {
	f := lang.NewURLEncoder(r, s)
	if len(i)%2 == 1 {
		panic("Must be even.")
	}
	inp := convert.ListToMap(i...)
	return f.UrlString(action_name, inp)
}
示例#2
0
文件: builtins.go 项目: Laller/chill
// Mainly designed to work from Get or GetSingle
func getSub(uni *context.Uni, noun string, params ...interface{}) []interface{} {
	if uni.Route == nil && uni.Sentence == nil {
		panic("Nothing to do here.")
	}
	s := uni.Sentence
	r := uni.Route
	var path string
	var urls []map[string]interface{}
	if s.Verb != "Get" && s.Verb != "GetSingle" {
		path = "/" + strings.Join(r.Words, "/") + "/" + noun
		urls = append(urls, r.Queries...)
		urls = append(urls, convert.ListToMap(params...))
	} else {
		path = "/" + strings.Join(r.Words, "/") + "/" + noun
		urls = append(urls, r.Queries[:len(r.Queries)-1]...)
		urls = append(urls, convert.ListToMap(params...))
	}
	desc, err := glue.Identify(path, uni.Opt["nouns"].(map[string]interface{}), lang.EncodeQueries(urls, false))
	inp, data, err := desc.CreateInputs(uni.FilterCreator)
	if err != nil {
		panic(err)
	}
	if data != nil {
		inp = append(inp, data)
	}
	module := uni.NewModule(desc.VerbLocation)
	if !module.Exists() {
		panic("Module does not exist.")
	}
	ins := module.Instance()
	ret := []interface{}{}
	ret_rec := func(i ...interface{}) {
		ret = i
	}
	ins.Method(uni.Sentence.Verb).Call(ret_rec, inp...)
	return ret
}
示例#3
0
文件: builtins.go 项目: Laller/chill
func getList(uni *context.Uni, noun string, params ...interface{}) []interface{} {
	values := convert.ListToMap(params...)
	desc, err := glue.Identify("/"+noun, uni.Opt["nouns"].(map[string]interface{}), values)
	inp, data, err := desc.CreateInputs(uni.FilterCreator)
	if err != nil {

		panic(err)
	}
	if data != nil {
		inp = append(inp, data)
	}
	module := uni.NewModule(desc.VerbLocation)
	if !module.Exists() {
		panic("Module does not exist.")
	}
	ins := module.Instance()
	ret := []interface{}{}
	ret_rec := func(i ...interface{}) {
		ret = i
	}
	ins.Method("Get").Call(ret_rec, inp...)
	return ret
}