mirror of
https://shylinux.com/x/icebergs
synced 2025-04-26 01:24:05 +08:00
opt chat.div
This commit is contained in:
parent
50f7e56449
commit
52cb99bfc4
@ -8,31 +8,42 @@ import (
|
||||
kit "shylinux.com/x/toolkits"
|
||||
)
|
||||
|
||||
func _split_deep(m *ice.Message, text string) (deep int) {
|
||||
for _, c := range text {
|
||||
switch c {
|
||||
case '\t':
|
||||
deep += 4
|
||||
case ' ':
|
||||
deep++
|
||||
default:
|
||||
return
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
func _split_list(m *ice.Message, file string, arg ...string) {
|
||||
const DEEP = "_deep"
|
||||
list := []interface{}{kit.Data(DEEP, -1)}
|
||||
list := kit.List(kit.Data(DEEP, -1))
|
||||
m.Cmd(nfs.CAT, file, func(text string) {
|
||||
if text = kit.Split(text, "#", "#")[0]; strings.TrimSpace(text) == "" {
|
||||
return
|
||||
}
|
||||
|
||||
deep := 0
|
||||
for _, c := range text {
|
||||
switch c {
|
||||
case '\t':
|
||||
deep += 4
|
||||
case ' ':
|
||||
deep++
|
||||
}
|
||||
}
|
||||
deep := _split_deep(m, text)
|
||||
data := kit.Data(DEEP, deep)
|
||||
|
||||
ls := kit.Split(text)
|
||||
switch cb := m.OptionCB(SPLIT).(type) {
|
||||
case func([]string, map[string]interface{}) []string:
|
||||
ls = cb(ls, data)
|
||||
}
|
||||
|
||||
for _, k := range arg {
|
||||
if kit.Value(data, kit.Keym(k), kit.Select("", ls, 0)); len(ls) > 0 {
|
||||
ls = ls[1:]
|
||||
}
|
||||
}
|
||||
|
||||
for i := 0; i < len(ls)-1; i += 2 {
|
||||
kit.Value(data, kit.Keym(ls[i]), ls[i+1])
|
||||
}
|
||||
@ -46,7 +57,7 @@ func _split_list(m *ice.Message, file string, arg ...string) {
|
||||
list = list[:len(list)-1]
|
||||
}
|
||||
})
|
||||
m.Echo(kit.Formats(list[:1]))
|
||||
m.Echo(kit.Format(list[0]))
|
||||
}
|
||||
|
||||
const SPLIT = "split"
|
||||
@ -56,7 +67,7 @@ func init() {
|
||||
SPLIT: {Name: "split", Help: "解析", Value: kit.Data()},
|
||||
}, Commands: map[string]*ice.Command{
|
||||
SPLIT: {Name: "split path key auto", Help: "解析", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
if len(arg) == 0 || strings.HasSuffix(arg[0], "/") {
|
||||
if len(arg) == 0 || strings.HasSuffix(arg[0], ice.PS) {
|
||||
m.Cmdy(nfs.DIR, arg)
|
||||
return
|
||||
}
|
||||
|
@ -48,6 +48,10 @@ func _cat_right(m *ice.Message, name string) bool {
|
||||
return true
|
||||
}
|
||||
func _cat_find(m *ice.Message, name string) io.ReadCloser {
|
||||
if m.Option(CAT_CONTENT) != "" {
|
||||
return NewReadCloser(bytes.NewBufferString(m.Option(CAT_CONTENT)))
|
||||
}
|
||||
|
||||
if f, e := os.Open(path.Join(m.Option(DIR_ROOT), name)); e == nil {
|
||||
return f
|
||||
}
|
||||
@ -118,7 +122,8 @@ const (
|
||||
LINE = "line"
|
||||
SIZE = "size"
|
||||
|
||||
CAT_LOCAL = "cat_local"
|
||||
CAT_LOCAL = "cat_local"
|
||||
CAT_CONTENT = "cat_content"
|
||||
)
|
||||
const CAT = "cat"
|
||||
|
||||
|
@ -2,6 +2,7 @@ package chat
|
||||
|
||||
import (
|
||||
"path"
|
||||
"strings"
|
||||
|
||||
ice "shylinux.com/x/icebergs"
|
||||
"shylinux.com/x/icebergs/base/ctx"
|
||||
@ -11,41 +12,14 @@ import (
|
||||
kit "shylinux.com/x/toolkits"
|
||||
)
|
||||
|
||||
func _div_deep(str string) int {
|
||||
for i, c := range str {
|
||||
if c != ' ' {
|
||||
return i
|
||||
}
|
||||
}
|
||||
return 0
|
||||
}
|
||||
func _div_parse(m *ice.Message, root map[string]interface{}, list []string) int {
|
||||
var last map[string]interface{}
|
||||
deep := _div_deep(list[0])
|
||||
for i := 0; i < len(list); i++ {
|
||||
if d := _div_deep(list[i]); d < deep {
|
||||
return i
|
||||
} else if d > deep {
|
||||
i += _div_parse(m, last, list[i:]) - 1
|
||||
continue
|
||||
}
|
||||
|
||||
ls := kit.Split(list[i])
|
||||
func _div_parse(m *ice.Message, text string) string {
|
||||
m.Option(nfs.CAT_CONTENT, text)
|
||||
return m.Cmdx(lex.SPLIT, "", "index", "args", func(ls []string, meta map[string]interface{}) []string {
|
||||
if ls[0] == "_span" {
|
||||
ls = append([]string{"", "", "style", kit.Select("span", ls, 1)}, kit.Slice(ls, 2)...)
|
||||
}
|
||||
meta := kit.Dict(
|
||||
"index", kit.Select("", ls, 0),
|
||||
"args", kit.Select("", ls, 1),
|
||||
"name", "hi",
|
||||
)
|
||||
for i := 2; i < len(ls); i += 2 {
|
||||
meta[ls[i]] = ls[i+1]
|
||||
}
|
||||
last = kit.Dict("meta", meta, "list", kit.List())
|
||||
kit.Value(root, "list.-2", last)
|
||||
}
|
||||
return len(list)
|
||||
return ls
|
||||
})
|
||||
}
|
||||
|
||||
const DIV = "div"
|
||||
@ -53,36 +27,31 @@ const DIV = "div"
|
||||
func init() {
|
||||
Index.Merge(&ice.Context{Configs: map[string]*ice.Config{
|
||||
DIV: {Name: "div", Help: "定制", Value: kit.Data(
|
||||
kit.MDB_SHORT, "", kit.MDB_FIELD, "time,hash,type,name,text",
|
||||
kit.MDB_PATH, ice.USR_PUBLISH,
|
||||
kit.MDB_FIELD, "time,hash,type,name,text", kit.MDB_PATH, ice.USR_PUBLISH,
|
||||
)},
|
||||
}, 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...))
|
||||
}},
|
||||
DIV: {Name: "div hash auto", Help: "定制", Action: ice.MergeAction(map[string]*ice.Action{
|
||||
lex.SPLIT: {Name: "split name=some text", Help: "生成", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Fields(0)
|
||||
node := kit.Data(m.OptionSimple(kit.MDB_NAME))
|
||||
_div_parse(m, node, kit.Split(m.Option(kit.MDB_TEXT), ice.NL, ice.NL, ice.NL))
|
||||
m.ProcessDisplay("/plugin/local/chat/div.js")
|
||||
m.Push(kit.MDB_TEXT, kit.Formats(node))
|
||||
lex.SPLIT: {Name: "split name=hi text", Help: "生成", Hand: func(m *ice.Message, arg ...string) {
|
||||
h := m.Cmdx(DIV, mdb.CREATE, m.OptionSimple(kit.MDB_NAME), kit.MDB_TEXT, _div_parse(m, m.Option(kit.MDB_TEXT)))
|
||||
m.ProcessRewrite(kit.MDB_HASH, h)
|
||||
}},
|
||||
mdb.CREATE: {Name: "create type=page name=hi.html text", Help: "创建"},
|
||||
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") {
|
||||
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 {
|
||||
if m.Option(ice.MSG_DISPLAY, "/plugin/local/chat/div.js"); m.Length() == 0 {
|
||||
m.Cmdy(DIV, lex.SPLIT, ice.Option{kit.MDB_TEXT, m.Cmdx(nfs.CAT, arg[0])})
|
||||
return
|
||||
}
|
||||
m.Option(ice.MSG_DISPLAY, "/plugin/local/chat/div.js")
|
||||
m.Action("添加", "保存", "预览")
|
||||
} else {
|
||||
m.Action(lex.SPLIT, mdb.CREATE)
|
||||
}
|
||||
m.Table(func(index int, value map[string]string, head []string) {
|
||||
m.PushAnchor("/" + path.Join(ice.PUBLISH, value[kit.MDB_NAME]))
|
||||
})
|
||||
m.PushAction(mdb.REMOVE)
|
||||
}},
|
||||
"/div/": {Name: "/div/", Help: "定制", Action: ice.MergeAction(ctx.CmdAction()), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
m.RenderCmd(m.Prefix(DIV), path.Join(arg...))
|
||||
}},
|
||||
}})
|
||||
}
|
||||
|
@ -77,10 +77,15 @@ func init() {
|
||||
_task_modify(m, STATUS, CANCEL)
|
||||
}},
|
||||
mdb.EXPORT: {Name: "export", Help: "导出", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.OptionFields(kit.MDB_ZONE, "time,id,type,name,text,level,status,score,begin_time,close_time,extra")
|
||||
m.OptionFields(kit.MDB_ZONE, "time,id,type,name,text,level,status,score,begin_time,close_time")
|
||||
m.Cmdy(mdb.EXPORT, m.Prefix(TASK), "", mdb.ZONE)
|
||||
m.ProcessRefresh30ms()
|
||||
}},
|
||||
mdb.IMPORT: {Name: "import", Help: "导入", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.OptionFields(kit.MDB_ZONE)
|
||||
m.Cmdy(mdb.IMPORT, m.Prefix(TASK), "", mdb.ZONE)
|
||||
m.ProcessRefresh30ms()
|
||||
}},
|
||||
|
||||
BEGIN: {Name: "begin", Help: "开始", Hand: func(m *ice.Message, arg ...string) {
|
||||
_task_modify(m, STATUS, PROCESS)
|
||||
|
Loading…
x
Reference in New Issue
Block a user