package ice import ( "net/http" "strings" kit "shylinux.com/x/toolkits" ) func AddRender(key string, render func(*Message, string, ...Any) string) { Info.render[key] = render } func Render(m *Message, cmd string, args ...Any) string { if render, ok := Info.render[cmd]; ok { return render(m, cmd, args...) } switch arg := kit.Simple(args...); cmd { case RENDER_ANCHOR: // [name] link p := kit.Select(arg[0], arg, 1) return kit.Format(`%s`, p, arg[0]) case RENDER_BUTTON: list := []string{} for _, k := range args { switch k := k.(type) { case []string: for _, k := range k { list = append(list, Render(m, RENDER_BUTTON, k)) } case string: if strings.HasPrefix(k, "`, k, kit.Select(k, kit.Value(m._cmd.Meta, kit.Keys("_trans", k)), m.Option(MSG_LANGUAGE) != "en"))) } case Map: for k, v := range k { list = append(list, kit.Format(``, k, kit.Select(k, v, m.Option(MSG_LANGUAGE) != "en"))) } } } return strings.Join(list, "") case RENDER_IMAGES: // src [height] if m.Option("height") != "" && m.Option("width") != "" { return kit.Format(``, arg[0], m.Option("height"), m.Option("width")) } if strings.Contains(m.Option(MSG_USERUA), "Mobile") { return kit.Format(``, arg[0], kit.Int(kit.Select(kit.Select("120", m.Option("width")), arg, 1))-24) } return kit.Format(``, arg[0], kit.Int(kit.Select(kit.Select("240", m.Option("height")), arg, 1))/2-24) case RENDER_VIDEOS: // src [height] if m.Option("height") != "" && m.Option("width") != "" { return kit.Format(`