diff --git a/core/chat/div.go b/core/chat/div.go index 014218ba..5890dd49 100644 --- a/core/chat/div.go +++ b/core/chat/div.go @@ -1,6 +1,7 @@ package chat import ( + "encoding/json" "path" "strings" @@ -28,10 +29,25 @@ func init() { Index.Merge(&ice.Context{Configs: map[string]*ice.Config{ DIV: {Name: "div", Help: "定制", Value: kit.Data( kit.MDB_FIELD, "time,hash,type,name,text", kit.MDB_PATH, ice.USR_PUBLISH, + kit.MDB_TEMPLATE, _div_template, )}, }, Commands: map[string]*ice.Command{ "/div/": {Name: "/div/", Help: "定制", Action: ice.MergeAction(ctx.CmdAction()), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { - m.RenderCmd(m.PrefixKey(), path.Join(arg...)) + switch p := path.Join(arg...); kit.Ext(kit.Select("", p)) { + case "html": + m.RenderDownload(p) + case "css": + m.RenderResult(_div_template, m.Cmdx(nfs.CAT, p), m.Cmdx(nfs.CAT, strings.ReplaceAll(p, ".css", ".js"))) + case "js": + m.RenderResult(_div_template, m.Cmdx(nfs.CAT, strings.ReplaceAll(p, ".js", ".css")), m.Cmdx(nfs.CAT, p)) + case "json": + var res interface{} + err := json.Unmarshal([]byte(m.Cmdx(nfs.CAT, p)), &res) + m.Assert(err) + m.RenderResult(_div_template2, kit.Format(res)) + default: + m.RenderCmd(m.PrefixKey(), p) + } }}, DIV: {Name: "div hash auto", Help: "定制", Action: ice.MergeAction(map[string]*ice.Action{ lex.SPLIT: {Name: "split name=hi text", Help: "生成", Hand: func(m *ice.Message, arg ...string) { @@ -40,18 +56,73 @@ func init() { }}, mdb.CREATE: {Name: "create type=page name=hi text", Help: "创建"}, }, mdb.HashAction(), ctx.CmdAction()), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { - if len(arg) > 0 && strings.HasSuffix(arg[0], ".shy") { + switch kit.Ext(kit.Select("", arg, 0)) { + case "shy": m.Fields(0) m.Option(ice.MSG_DISPLAY, "/plugin/local/chat/div.js") m.Push(kit.MDB_TEXT, _div_parse(m, m.Cmdx(nfs.CAT, arg[0]))) - return - } - if mdb.HashSelect(m, arg...); len(arg) > 0 { - m.Option(ice.MSG_DISPLAY, "/plugin/local/chat/div.js") - m.Action("添加", "保存", "预览") - } else { - m.Action(lex.SPLIT, mdb.CREATE) + default: + if mdb.HashSelect(m, arg...); len(arg) > 0 { + m.Option(ice.MSG_DISPLAY, "/plugin/local/chat/div.js") + m.Action("添加", "保存", "预览") + } else { + m.Action(lex.SPLIT, mdb.CREATE) + } } }}, }}) } + +var _div_template = ` +
+ +