Ejemplo n.º 1
0
func _url(ctx iface.Context, action_name string, i ...interface{}) string {
	if len(i)%2 == 1 {
		panic("Must be even.")
	}
	nouns := scut.GetNouns(ctx.Options().Document())
	np := ctx.NonPortable()
	hl, err := highlev.New(ctx.Conducting().Hooks(), np.Resource(), nouns, np.Params())
	if err != nil {
		panic(err)
	}
	f := hl.URLE()
	inp := convert.ListToMap(i...)
	return f.UrlString(action_name, inp)
}
Ejemplo n.º 2
0
func getList(ctx iface.Context, noun string, params ...interface{}) []interface{} {
	nouns, ok := ctx.Options().Document().GetM("nouns")
	if !ok {
		panic("Can't find nouns.")
	}
	inp := convert.ListToMap(params...)
	hl, err := highlev.New(ctx.Conducting().Hooks(), "/"+noun, nouns, inp)
	if err != nil {
		panic(err)
	}
	deflev_i, _ := ctx.Options().Document().Get("default_level")
	deflev, _ := numcon.Int(deflev_i)
	ret, err := hl.Run(ctx.Db(), ctx.User(), deflev)
	if err != nil {
		panic(err)
	}
	return ret
}
Ejemplo n.º 3
0
func (h *hook) Fire(args ...interface{}) (string, error) {
	if !h.Has() {
		return "", nil
	}
	if h.hook.SubscriberCount() > 1 {
		return "", fmt.Errorf("More than one subscriber.")
	}
	ma := convert.ListToMap(args...)
	inp := []interface{}{}
	for i, v := range ma {
		h.ctx.ViewContext().Publish(i, v)
		inp = append(inp, v)
	}
	subs := h.hook.Subscribers()
	modName := subs[0].Name()
	if h.ctx.Conducting().Hooks().Module(modName).Instance().HasMethod(h.hookName) {
		h.hook.Fire(inp...)
	}
	return New(h.ctx).ToString([]string{
		modName + "/" + strings.Title(h.hookName),
	})
}
Ejemplo n.º 4
0
// Works from Get or GetSingle only.
func getSub(ctx iface.Context, noun string, params ...interface{}) []interface{} {
	nouns, ok := ctx.Options().Document().GetM("nouns")
	if !ok {
		panic("Can't find nouns.")
	}
	np := ctx.NonPortable()
	hl, err := highlev.New(ctx.Conducting().Hooks(), np.Resource(), nouns, np.Params())
	if err != nil {
		panic(err)
	}
	inp := convert.ListToMap(params...)
	subhl, err := hl.Sub(noun, inp)
	if err != nil {
		panic(err)
	}
	deflev_i, _ := ctx.Options().Document().Get("defaultLevel")
	deflev, _ := numcon.Int(deflev_i)
	ret, err := subhl.Run(ctx.Db(), ctx.User(), deflev)
	if err != nil {
		panic(err)
	}
	return ret
}