From 51eb0852c2fec03bc0f6d9ecafa2d1b03a7ac38d Mon Sep 17 00:00:00 2001 From: harveyshao Date: Mon, 1 Nov 2021 19:22:12 +0800 Subject: [PATCH] opt wiki --- core/team/plan.js | 4 +- core/wiki/brief.go | 21 +++--- core/wiki/chart.go | 172 +++++++++++++++++++++------------------------ core/wiki/data.go | 35 +++++---- core/wiki/draw.go | 35 +++++---- core/wiki/feel.go | 31 ++++---- core/wiki/field.go | 35 +++++---- core/wiki/image.go | 35 +++++---- core/wiki/json.go | 49 +++++++------ core/wiki/local.go | 23 +++--- core/wiki/order.go | 21 +++--- core/wiki/refer.go | 21 +++--- core/wiki/shell.go | 23 +++--- core/wiki/spark.go | 83 ++++++++++------------ core/wiki/table.go | 31 ++++---- core/wiki/title.go | 15 ++-- core/wiki/video.go | 29 ++++---- core/wiki/wiki.go | 39 ++++++---- core/wiki/wiki.shy | 15 ++-- core/wiki/word.go | 50 +------------ misc/git/spide.go | 2 +- 21 files changed, 337 insertions(+), 432 deletions(-) diff --git a/core/team/plan.js b/core/team/plan.js index c31d9bc7..f4d9191b 100644 --- a/core/team/plan.js +++ b/core/team/plan.js @@ -22,8 +22,8 @@ Volcanos("onimport", {help: "导入数据", list: [], _init: function(can, msg, return can.onimport._task(can, msg, get(begin_time, col, row, hash), set(begin_time, col, row)) })} }) }]) - can.core.Timer(10, function() { - var target = can.sup.task._target||can.sup.task._target + can.core.Timer(10, function() { if (!can.sup.task) { return } + var target = can.sup.task._target||can.task._target can.sup.task = null, target.click() can.Status("count", msg.Length()) }) diff --git a/core/wiki/brief.go b/core/wiki/brief.go index 9870b716..c857b2a7 100644 --- a/core/wiki/brief.go +++ b/core/wiki/brief.go @@ -8,16 +8,13 @@ import ( const BRIEF = "brief" func init() { - Index.Merge(&ice.Context{ - Commands: map[string]*ice.Command{ - BRIEF: {Name: "brief text", Help: "摘要", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { - _wiki_template(m, cmd, "", arg[0], arg[1:]...) - }}, - }, - Configs: map[string]*ice.Config{ - BRIEF: {Name: BRIEF, Help: "摘要", Value: kit.Data( - kit.MDB_TEMPLATE, `

{{.Option "text"}}

`, - )}, - }, - }) + Index.Merge(&ice.Context{Commands: map[string]*ice.Command{ + BRIEF: {Name: "brief text", Help: "摘要", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { + _wiki_template(m, cmd, "", arg[0], arg[1:]...) + }}, + }, Configs: map[string]*ice.Config{ + BRIEF: {Name: BRIEF, Help: "摘要", Value: kit.Data( + kit.MDB_TEMPLATE, `

{{.Option "text"}}

`, + )}, + }}) } diff --git a/core/wiki/chart.go b/core/wiki/chart.go index 69afe4d1..56a8d813 100644 --- a/core/wiki/chart.go +++ b/core/wiki/chart.go @@ -2,6 +2,7 @@ package wiki import ( ice "shylinux.com/x/icebergs" + "shylinux.com/x/icebergs/base/cli" kit "shylinux.com/x/toolkits" "strings" @@ -38,22 +39,22 @@ type Block struct { func (b *Block) Init(m *ice.Message, arg ...string) Chart { b.Text = kit.Select(b.Text, arg, 0) - b.FontSize = kit.Int(kit.Select(m.Option("font-size"), kit.Select(kit.Format(b.FontSize), arg, 1))) - b.FontColor = kit.Select(m.Option("stroke"), kit.Select(b.FontColor, arg, 2)) - b.BackGround = kit.Select(m.Option("fill"), kit.Select(b.BackGround, arg, 3)) - b.Padding = kit.Int(kit.Select(m.Option("padding"), kit.Select(kit.Format(b.Padding), arg, 4))) - b.MarginX = kit.Int(kit.Select(m.Option("marginx"), kit.Select(kit.Format(b.MarginX), arg, 5))) - b.MarginY = kit.Int(kit.Select(m.Option("marginy"), kit.Select(kit.Format(b.MarginY), arg, 5))) + b.FontSize = kit.Int(kit.Select(m.Option(FONT_SIZE), kit.Select(kit.Format(b.FontSize), arg, 1))) + b.FontColor = kit.Select(m.Option(STROKE), kit.Select(b.FontColor, arg, 2)) + b.BackGround = kit.Select(m.Option(FILL), kit.Select(b.BackGround, arg, 3)) + b.Padding = kit.Int(kit.Select(m.Option(PADDING), kit.Select(kit.Format(b.Padding), arg, 4))) + b.MarginX = kit.Int(kit.Select(m.Option(MARGINX), kit.Select(kit.Format(b.MarginX), arg, 5))) + b.MarginY = kit.Int(kit.Select(m.Option(MARGINY), kit.Select(kit.Format(b.MarginY), arg, 5))) return b } func (b *Block) Data(m *ice.Message, root interface{}) Chart { - b.Text = kit.Select(b.Text, kit.Value(root, "text")) + b.Text = kit.Select(b.Text, kit.Value(root, kit.MDB_TEXT)) kit.Fetch(root, func(key string, value string) { switch key { - case "fg": - b.TextData += kit.Format("%s='%s' ", "fill", value) - case "bg": - b.RectData += kit.Format("%s='%s' ", "fill", value) + case FG: + b.TextData += kit.Format("%s='%s' ", FILL, value) + case BG: + b.RectData += kit.Format("%s='%s' ", FILL, value) } }) kit.Fetch(kit.Value(root, "data"), func(key string, value string) { @@ -71,7 +72,7 @@ func (b *Block) Draw(m *ice.Message, x, y int) Chart { } m.Echo(``, x+b.MarginX/2, y+b.MarginY/2, b.GetWidth(), b.GetHeight(), b.BackGround, b.RectData) - m.Echo("\n") + m.Echo(ice.NL) m.Echo(`%v`, x+b.GetWidths()/2, y+b.GetHeights()/2+float, b.FontColor, b.FontColor, b.TextData, b.Text) m.Echo("\n") @@ -109,19 +110,19 @@ type Label struct { func (b *Label) Init(m *ice.Message, arg ...string) Chart { b.Text = kit.Select(b.Text, arg, 0) - b.FontSize = kit.Int(m.Option("font-size")) - b.Padding = kit.Int(m.Option("padding")) - b.MarginX = kit.Int(m.Option("marginx")) - b.MarginY = kit.Int(m.Option("marginy")) + b.FontSize = kit.Int(m.Option(FONT_SIZE)) + b.Padding = kit.Int(m.Option(PADDING)) + b.MarginX = kit.Int(m.Option(MARGINX)) + b.MarginY = kit.Int(m.Option(MARGINY)) // 解析数据 b.max = map[int]int{} - for _, v := range strings.Split(arg[0], "\n") { - l := kit.Split(v, " ", " ") + for _, v := range strings.Split(arg[0], ice.NL) { + l := kit.Split(v, ice.SP, ice.SP) for i, v := range l { switch data := kit.Parse(nil, "", kit.Split(v)...).(type) { case map[string]interface{}: - v = kit.Select("", data["text"]) + v = kit.Select("", data[kit.MDB_TEXT]) } if w := b.GetWidth(v); w > b.max[i] { @@ -157,9 +158,9 @@ func (b *Label) Draw(m *ice.Message, x, y int) Chart { if w := kit.Int(kit.Value(order, "index")); w != 0 && i%w == 0 { for k, v := range order { switch k { - case "fg": + case FG: item.FontColor = kit.Format(v) - case "bg": + case BG: item.BackGround = kit.Format(v) } } @@ -168,13 +169,13 @@ func (b *Label) Draw(m *ice.Message, x, y int) Chart { switch data := kit.Parse(nil, "", kit.Split(text)...).(type) { case map[string]interface{}: - item.Init(m, kit.Select(text, data["text"])).Data(m, data) + item.Init(m, kit.Select(text, data[kit.MDB_TEXT])).Data(m, data) default: item.Init(m, text) } // 输出 - switch m.Option("compact") { + switch m.Option(COMPACT) { case "max": item.Width = b.Width/len(line) - b.MarginX case ice.TRUE: @@ -200,10 +201,10 @@ type Chain struct { } func (b *Chain) Init(m *ice.Message, arg ...string) Chart { - b.FontSize = kit.Int(m.Option("font-size")) - b.Padding = kit.Int(m.Option("padding")) - b.MarginX = kit.Int(m.Option("marginx")) - b.MarginY = kit.Int(m.Option("marginy")) + b.FontSize = kit.Int(m.Option(FONT_SIZE)) + b.Padding = kit.Int(m.Option(PADDING)) + b.MarginX = kit.Int(m.Option(MARGINX)) + b.MarginY = kit.Int(m.Option(MARGINY)) // 解析数据 b.data = kit.Parse(nil, "", b.show(m, arg[0])...).(map[string]interface{}) @@ -222,7 +223,7 @@ func (b *Chain) Draw(m *ice.Message, x, y int) Chart { } func (b *Chain) show(m *ice.Message, str string) (res []string) { miss := []int{} - for _, line := range kit.Split(str, "\n", "\n") { + for _, line := range kit.Split(str, ice.NL, ice.NL) { // 计算缩进 dep := 0 loop: @@ -269,7 +270,7 @@ func (b *Chain) size(m *ice.Message, root map[string]interface{}, depth int, wid meta := root[kit.MDB_META].(map[string]interface{}) // 最大宽度 - if w := b.GetWidths(kit.Format(meta["text"])); w > width[depth] { + if w := b.GetWidths(kit.Format(meta[kit.MDB_TEXT])); w > width[depth] { width[depth] = w } @@ -283,7 +284,7 @@ func (b *Chain) size(m *ice.Message, root map[string]interface{}, depth int, wid height = 1 } - meta["height"] = height + meta[HEIGHT] = height return height } func (b *Chain) draw(m *ice.Message, root map[string]interface{}, depth int, width map[int]int, x, y int, p *Block) int { @@ -292,19 +293,19 @@ func (b *Chain) draw(m *ice.Message, root map[string]interface{}, depth int, wid // 当前节点 item := &Block{ - BackGround: kit.Select(b.BackGround, kit.Select(p.BackGround, meta["bg"])), - FontColor: kit.Select(b.FontColor, kit.Select(p.FontColor, meta["fg"])), + BackGround: kit.Select(b.BackGround, kit.Select(p.BackGround, meta[BG])), + FontColor: kit.Select(b.FontColor, kit.Select(p.FontColor, meta[FG])), FontSize: b.FontSize, Padding: b.Padding, MarginX: b.MarginX, MarginY: b.MarginY, } - if m.Option("compact") != ice.TRUE { + if m.Option(COMPACT) != ice.TRUE { item.Width = b.max[depth] } item.x = x - item.y = y + (kit.Int(meta["height"])-1)*b.GetHeights()/2 - item.Init(m, kit.Format(meta["text"])).Data(m, meta) + item.y = y + (kit.Int(meta[HEIGHT])-1)*b.GetHeights()/2 + item.Init(m, kit.Format(meta[kit.MDB_TEXT])).Data(m, meta) item.Draw(m, item.x, item.y) if p != nil && p.y != 0 { @@ -328,35 +329,6 @@ func (b *Chain) draw(m *ice.Message, root map[string]interface{}, depth int, wid return h } -// 栈 -func Stack(m *ice.Message, name string, level int, data interface{}) { - style := []string{} - kit.Fetch(kit.Value(data, "meta"), func(key string, value string) { - switch key { - case "bg": - style = append(style, "background:"+value) - case "fg": - style = append(style, "color:"+value) - } - }) - - l, ok := kit.Value(data, "list").([]interface{}) - if !ok || len(l) == 0 { - m.Echo(`
o %s
`, name, strings.Join(style, ";"), kit.Value(data, "meta.text")) - return - } - m.Echo(`
%s %s
`, - kit.Select("span", "fold", level > 2), name, strings.Join(style, ";"), kit.Select("v", ">", level > 2), kit.Value(data, "meta.text")) - - m.Echo("") -} - func _chart_show(m *ice.Message, kind, text string, arg ...string) { var chart Chart switch kind { @@ -367,34 +339,34 @@ func _chart_show(m *ice.Message, kind, text string, arg ...string) { } // 扩展参数 - m.Option("font-size", "24") - m.Option("stroke", "blue") - m.Option("fill", "yellow") + m.Option(FONT_SIZE, "24") + m.Option(STROKE, cli.BLUE) + m.Option(FILL, cli.YELLOW) // 扩展参数 - m.Option("style", "") - m.Option("stroke-width", "2") - m.Option("font-family", "monospace") + m.Option(STYLE, "") + m.Option(STROKE_WIDTH, "2") + m.Option(FONT_FAMILY, "monospace") // 扩展参数 - m.Option("compact", ice.FALSE) - m.Option("padding", "10") - m.Option("marginx", "10") - m.Option("marginy", "10") + m.Option(COMPACT, ice.FALSE) + m.Option(PADDING, "10") + m.Option(MARGINX, "10") + m.Option(MARGINY, "10") // m.Option("font-family", kit.Select("", "monospace", len(text) == len([]rune(text)))) for i := 0; i < len(arg)-1; i++ { m.Option(arg[i], arg[i+1]) } - if m.Option("bg") != "" { - m.Option("fill", m.Option("bg")) + if m.Option(BG) != "" { + m.Option(FILL, m.Option(BG)) } - if m.Option("fg") != "" { - m.Option("stroke", m.Option("fg")) + if m.Option(FG) != "" { + m.Option(STROKE, m.Option(FG)) } // 计算尺寸 chart.Init(m, text) - m.Option("width", chart.GetWidth()) - m.Option("height", chart.GetHeight()) + m.Option(WIDTH, chart.GetWidth()) + m.Option(HEIGHT, chart.GetHeight()) // 渲染引擎 _wiki_template(m, CHART, "", text) @@ -403,27 +375,43 @@ func _chart_show(m *ice.Message, kind, text string, arg ...string) { } const ( + FG = "fg" + BG = "bg" + FILL = "fill" + STROKE = "stroke" + + STYLE = "style" + WIDTH = "width" + HEIGHT = "height" + PADDING = "padding" + MARGINX = "marginx" + MARGINY = "marginy" + + FONT_SIZE = "font-size" + FONT_FAMILY = "font-family" + + STROKE_WIDTH = "stroke-width" + + COMPACT = "compact" + LABEL = "label" CHAIN = "chain" ) const CHART = "chart" func init() { - Index.Merge(&ice.Context{ - Commands: map[string]*ice.Command{ - CHART: {Name: "chart label|chain text", Help: "图表", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { - _chart_show(m, arg[0], strings.TrimSpace(arg[1]), arg[2:]...) - }}, - }, - Configs: map[string]*ice.Config{ - CHART: {Name: CHART, Help: "图表", Value: kit.Data( - kit.MDB_TEMPLATE, ``, - )}, - }, - }) + )}, + }}) } diff --git a/core/wiki/data.go b/core/wiki/data.go index 155000bf..2745213d 100644 --- a/core/wiki/data.go +++ b/core/wiki/data.go @@ -9,24 +9,21 @@ import ( const DATA = "data" func init() { - Index.Merge(&ice.Context{ - Configs: map[string]*ice.Config{ - DATA: {Name: DATA, Help: "数据表格", Value: kit.Data( - kit.MDB_PATH, ice.USR_LOCAL_EXPORT, kit.MDB_REGEXP, ".*\\.csv", - )}, - }, - Commands: map[string]*ice.Command{ - DATA: {Name: "data path auto", Help: "数据表格", Meta: kit.Dict( - ice.Display("/plugin/local/wiki/data.js"), - ), Action: map[string]*ice.Action{ - nfs.SAVE: {Name: "save path text", Help: "保存", Hand: func(m *ice.Message, arg ...string) { - _wiki_save(m, DATA, arg[0], arg[1]) - }}, - }, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { - if !_wiki_list(m, DATA, kit.Select("./", arg, 0)) { - m.CSV(m.Cmd(nfs.CAT, arg[0]).Result()) - } + Index.Merge(&ice.Context{Configs: map[string]*ice.Config{ + DATA: {Name: DATA, Help: "数据表格", Value: kit.Data( + kit.MDB_PATH, ice.USR_LOCAL_EXPORT, kit.MDB_REGEXP, ".*\\.csv", + )}, + }, Commands: map[string]*ice.Command{ + DATA: {Name: "data path auto", Help: "数据表格", Meta: kit.Dict( + ice.Display("/plugin/local/wiki/data.js"), + ), Action: map[string]*ice.Action{ + nfs.SAVE: {Name: "save path text", Help: "保存", Hand: func(m *ice.Message, arg ...string) { + _wiki_save(m, m.CommandKey(), arg[0], arg[1]) }}, - }, - }) + }, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { + if !_wiki_list(m, m.CommandKey(), kit.Select("./", arg, 0)) { + m.CSV(m.Cmd(nfs.CAT, arg[0]).Result()) + } + }}, + }}) } diff --git a/core/wiki/draw.go b/core/wiki/draw.go index 1f341254..9bf01ce4 100644 --- a/core/wiki/draw.go +++ b/core/wiki/draw.go @@ -11,24 +11,21 @@ import ( const DRAW = "draw" func init() { - Index.Merge(&ice.Context{ - Configs: map[string]*ice.Config{ - DRAW: {Name: DRAW, Help: "思维导图", Value: kit.Data( - kit.MDB_PATH, "", kit.MDB_REGEXP, ".*\\.svg", - )}, - }, - Commands: map[string]*ice.Command{ - DRAW: {Name: "draw path=src/main.svg refresh:button=auto 编辑 save 项目 参数", Help: "思维导图", Meta: kit.Dict( - ice.Display("/plugin/local/wiki/draw.js"), - ), Action: map[string]*ice.Action{ - nfs.SAVE: {Name: "save path", Help: "保存", Hand: func(m *ice.Message, arg ...string) { - _wiki_save(m, DRAW, path.Join(arg...), m.Option(kit.MDB_CONTENT)) - }}, - }, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { - if !_wiki_list(m, DRAW, kit.Select("./", path.Join(arg...))) { - _wiki_show(m, DRAW, path.Join(arg...)) - } + Index.Merge(&ice.Context{Configs: map[string]*ice.Config{ + DRAW: {Name: DRAW, Help: "思维导图", Value: kit.Data( + kit.MDB_PATH, "", kit.MDB_REGEXP, ".*\\.svg", + )}, + }, Commands: map[string]*ice.Command{ + DRAW: {Name: "draw path=src/main.svg refresh:button=auto 编辑 save 项目 参数", Help: "思维导图", Meta: kit.Dict( + ice.Display("/plugin/local/wiki/draw.js"), + ), Action: map[string]*ice.Action{ + nfs.SAVE: {Name: "save path", Help: "保存", Hand: func(m *ice.Message, arg ...string) { + _wiki_save(m, DRAW, path.Join(arg...), m.Option(kit.MDB_CONTENT)) }}, - }, - }) + }, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { + if !_wiki_list(m, DRAW, kit.Select("./", path.Join(arg...))) { + _wiki_show(m, DRAW, path.Join(arg...)) + } + }}, + }}) } diff --git a/core/wiki/feel.go b/core/wiki/feel.go index 61f856d6..bf7178db 100644 --- a/core/wiki/feel.go +++ b/core/wiki/feel.go @@ -9,22 +9,19 @@ import ( const FEEL = "feel" func init() { - Index.Merge(&ice.Context{ - Configs: map[string]*ice.Config{ - FEEL: {Name: FEEL, Help: "影音媒体", Value: kit.Data( - kit.MDB_PATH, ice.USR_LOCAL_IMAGE, kit.MDB_REGEXP, ".*.(png|PNG|jpg|JPG|jpeg|mp4|m4v|MOV)", - )}, - }, - Commands: map[string]*ice.Command{ - FEEL: {Name: "feel path auto upload 上一页 下一页 参数", Help: "影音媒体", Meta: kit.Dict( - ice.Display("/plugin/local/wiki/feel.js"), - ), Action: map[string]*ice.Action{ - web.UPLOAD: {Name: "upload", Help: "上传", Hand: func(m *ice.Message, arg ...string) { - _wiki_upload(m, FEEL, m.Option(kit.MDB_PATH)) - }}, - }, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { - _wiki_list(m, FEEL, kit.Select("./", arg, 0)) + Index.Merge(&ice.Context{Configs: map[string]*ice.Config{ + FEEL: {Name: FEEL, Help: "影音媒体", Value: kit.Data( + kit.MDB_PATH, ice.USR_LOCAL_IMAGE, kit.MDB_REGEXP, ".*.(png|PNG|jpg|JPG|jpeg|mp4|m4v|MOV)", + )}, + }, Commands: map[string]*ice.Command{ + FEEL: {Name: "feel path auto upload 上一页 下一页 参数", Help: "影音媒体", Meta: kit.Dict( + ice.Display("/plugin/local/wiki/feel.js"), + ), Action: map[string]*ice.Action{ + web.UPLOAD: {Name: "upload", Help: "上传", Hand: func(m *ice.Message, arg ...string) { + _wiki_upload(m, m.CommandKey(), m.Option(kit.MDB_PATH)) }}, - }, - }) + }, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { + _wiki_list(m, m.CommandKey(), kit.Select("./", arg, 0)) + }}, + }}) } diff --git a/core/wiki/field.go b/core/wiki/field.go index 3a457c88..68b52df1 100644 --- a/core/wiki/field.go +++ b/core/wiki/field.go @@ -37,7 +37,7 @@ func _field_show(m *ice.Message, name, text string, arg ...string) { } }) - name = strings.ReplaceAll(name, " ", "_") + name = strings.ReplaceAll(name, ice.SP, "_") meta[kit.MDB_NAME] = name meta[kit.MDB_INDEX] = text @@ -96,29 +96,26 @@ const ( const FIELD = "field" func init() { - Index.Merge(&ice.Context{ - Commands: map[string]*ice.Command{ - FIELD: {Name: "field [name] cmd", Help: "插件", Action: map[string]*ice.Action{ - ice.RUN: {Name: "run", Help: "执行", Hand: func(m *ice.Message, arg ...string) { - m.Cmdy(arg) - }}, - }, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { - if arg = _name(m, arg); strings.Contains(arg[1], "\n") { - arg = append([]string{arg[0], "web.chat.div", "auto.cmd", "make", "opts.line", arg[1]}, arg[2:]...) - } - _field_show(m, arg[0], arg[1], arg[2:]...) + Index.Merge(&ice.Context{Commands: map[string]*ice.Command{ + FIELD: {Name: "field [name] cmd", Help: "插件", Action: map[string]*ice.Action{ + ice.RUN: {Name: "run", Help: "执行", Hand: func(m *ice.Message, arg ...string) { + m.Cmdy(arg) }}, - }, - Configs: map[string]*ice.Config{ - FIELD: {Name: FIELD, Help: "插件", Value: kit.Data( - kit.MDB_TEMPLATE, `
+ }, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { + if arg = _name(m, arg); strings.Contains(arg[1], ice.NL) { + arg = append([]string{arg[0], "web.chat.div", "auto.cmd", "split", "opts.text", arg[1]}, arg[2:]...) + } + _field_show(m, arg[0], arg[1], arg[2:]...) + }}, + }, Configs: map[string]*ice.Config{ + FIELD: {Name: FIELD, Help: "插件", Value: kit.Data( + kit.MDB_TEMPLATE, `
{{.Option "name"}}
`, - )}, - }, - }) + )}, + }}) } diff --git a/core/wiki/image.go b/core/wiki/image.go index eccb2c11..11b34501 100644 --- a/core/wiki/image.go +++ b/core/wiki/image.go @@ -20,24 +20,21 @@ const ( const IMAGE = "image" func init() { - Index.Merge(&ice.Context{ - Commands: map[string]*ice.Command{ - ice.CTX_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { - m.Cmd(mdb.RENDER, mdb.CREATE, PNG, m.Prefix(IMAGE)) + Index.Merge(&ice.Context{Commands: map[string]*ice.Command{ + ice.CTX_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { + m.Cmd(mdb.RENDER, mdb.CREATE, PNG, m.Prefix(IMAGE)) + }}, + IMAGE: {Name: "image url", Help: "图片", Action: map[string]*ice.Action{ + mdb.RENDER: {Name: "render", Help: "渲染", Hand: func(m *ice.Message, arg ...string) { + _image_show(m, path.Join(arg[2], arg[1])) }}, - IMAGE: {Name: "image url", Help: "图片", Action: map[string]*ice.Action{ - mdb.RENDER: {Name: "render", Help: "渲染", Hand: func(m *ice.Message, arg ...string) { - _image_show(m, path.Join(arg[2], arg[1])) - }}, - }, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { - _image_show(m, arg[0], arg[1:]...) - }}, - }, - Configs: map[string]*ice.Config{ - IMAGE: {Name: IMAGE, Help: "图片", Value: kit.Data( - kit.MDB_TEMPLATE, ``, - kit.MDB_PATH, ice.USR_LOCAL_IMAGE, - )}, - }, - }) + }, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { + _image_show(m, arg[0], arg[1:]...) + }}, + }, Configs: map[string]*ice.Config{ + IMAGE: {Name: IMAGE, Help: "图片", Value: kit.Data( + kit.MDB_TEMPLATE, ``, + kit.MDB_PATH, ice.USR_LOCAL_IMAGE, + )}, + }}) } diff --git a/core/wiki/json.go b/core/wiki/json.go index aa79b514..42fb96e1 100644 --- a/core/wiki/json.go +++ b/core/wiki/json.go @@ -50,30 +50,29 @@ func _json_show(m *ice.Message, data interface{}) { const JSON = "json" func init() { - Index.Merge(&ice.Context{ - Configs: map[string]*ice.Config{ - JSON: {Name: JSON, Help: "数据结构", Value: kit.Data( - kit.MDB_PATH, ice.USR_LOCAL_EXPORT, kit.MDB_REGEXP, ".*\\.json", - )}, - }, - Commands: map[string]*ice.Command{ - JSON: {Name: "json path auto", Help: "数据结构", Meta: kit.Dict(ice.Display("/plugin/local/wiki/json.js")), Action: map[string]*ice.Action{ - nfs.SAVE: {Name: "save path text", Help: "保存", Hand: func(m *ice.Message, arg ...string) { - _wiki_save(m, JSON, arg[0], arg[1]) - }}, - ice.RUN: {Name: "run", Help: "执行", Hand: func(m *ice.Message, arg ...string) { - var data interface{} - json.Unmarshal([]byte(m.Cmdx(arg)), &data) - m.Option("type", "json") - m.RenderTemplate(`
`) - _json_show(m, data) - m.Echo(`
`) - }}, - }, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { - if !_wiki_list(m, JSON, kit.Select("./", arg, 0)) { - m.Cmdy(nfs.CAT, arg[0]) - } + Index.Merge(&ice.Context{Configs: map[string]*ice.Config{ + JSON: {Name: JSON, Help: "数据结构", Value: kit.Data( + kit.MDB_PATH, ice.USR_LOCAL_EXPORT, kit.MDB_REGEXP, ".*\\.json", + )}, + }, Commands: map[string]*ice.Command{ + JSON: {Name: "json path auto", Help: "数据结构", Meta: kit.Dict( + ice.Display("/plugin/local/wiki/json.js"), + ), Action: map[string]*ice.Action{ + nfs.SAVE: {Name: "save path text", Help: "保存", Hand: func(m *ice.Message, arg ...string) { + _wiki_save(m, JSON, arg[0], arg[1]) }}, - }, - }) + ice.RUN: {Name: "run", Help: "执行", Hand: func(m *ice.Message, arg ...string) { + var data interface{} + json.Unmarshal([]byte(m.Cmdx(arg)), &data) + m.Option("type", "json") + m.RenderTemplate(`
`) + _json_show(m, data) + m.Echo(`
`) + }}, + }, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { + if !_wiki_list(m, JSON, kit.Select("./", arg, 0)) { + m.Cmdy(nfs.CAT, arg[0]) + } + }}, + }}) } diff --git a/core/wiki/local.go b/core/wiki/local.go index 6274af3f..dd1ef061 100644 --- a/core/wiki/local.go +++ b/core/wiki/local.go @@ -14,17 +14,14 @@ func _local_show(m *ice.Message, name, text string, arg ...string) { const LOCAL = "local" func init() { - Index.Merge(&ice.Context{ - Commands: map[string]*ice.Command{ - LOCAL: {Name: "local [name] file", Help: "文件", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { - arg = _name(m, arg) - _local_show(m, arg[0], kit.Select(arg[0], arg[1]), arg[2:]...) - }}, - }, - Configs: map[string]*ice.Config{ - LOCAL: {Name: LOCAL, Help: "文件", Value: kit.Data( - kit.MDB_TEMPLATE, `{{range $index, $value := .Optionv "input"}}{{$value}}{{end}}`, - )}, - }, - }) + Index.Merge(&ice.Context{Commands: map[string]*ice.Command{ + LOCAL: {Name: "local [name] file", Help: "文件", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { + arg = _name(m, arg) + _local_show(m, arg[0], kit.Select(arg[0], arg[1]), arg[2:]...) + }}, + }, Configs: map[string]*ice.Config{ + LOCAL: {Name: LOCAL, Help: "文件", Value: kit.Data( + kit.MDB_TEMPLATE, `{{range $index, $value := .Optionv "input"}}{{$value}}{{end}}`, + )}, + }}) } diff --git a/core/wiki/order.go b/core/wiki/order.go index 7e54c720..b48dcfa8 100644 --- a/core/wiki/order.go +++ b/core/wiki/order.go @@ -15,16 +15,13 @@ func _order_show(m *ice.Message, text string, arg ...string) { const ORDER = "order" func init() { - Index.Merge(&ice.Context{ - Commands: map[string]*ice.Command{ - ORDER: {Name: "order `[item\n]...`", Help: "列表", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { - _order_show(m, arg[0], arg[1:]...) - }}, - }, - Configs: map[string]*ice.Config{ - ORDER: {Name: ORDER, Help: "列表", Value: kit.Data( - kit.MDB_TEMPLATE, ``, - )}, - }, - }) + Index.Merge(&ice.Context{Commands: map[string]*ice.Command{ + ORDER: {Name: "order `[item\n]...`", Help: "列表", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { + _order_show(m, arg[0], arg[1:]...) + }}, + }, Configs: map[string]*ice.Config{ + ORDER: {Name: ORDER, Help: "列表", Value: kit.Data( + kit.MDB_TEMPLATE, ``, + )}, + }}) } diff --git a/core/wiki/refer.go b/core/wiki/refer.go index a162ba4d..98a69e1c 100644 --- a/core/wiki/refer.go +++ b/core/wiki/refer.go @@ -24,16 +24,13 @@ func _refer_show(m *ice.Message, text string, arg ...string) { const REFER = "refer" func init() { - Index.Merge(&ice.Context{ - Commands: map[string]*ice.Command{ - REFER: {Name: "refer `[[name] url\n]...`", Help: "参考", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { - _refer_show(m, arg[0], arg[1:]...) - }}, - }, - Configs: map[string]*ice.Config{ - REFER: {Name: REFER, Help: "参考", Value: kit.Data( - kit.MDB_TEMPLATE, ``, - )}, - }, - }) + Index.Merge(&ice.Context{Commands: map[string]*ice.Command{ + REFER: {Name: "refer `[[name] url\n]...`", Help: "参考", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { + _refer_show(m, arg[0], arg[1:]...) + }}, + }, Configs: map[string]*ice.Config{ + REFER: {Name: REFER, Help: "参考", Value: kit.Data( + kit.MDB_TEMPLATE, ``, + )}, + }}) } diff --git a/core/wiki/shell.go b/core/wiki/shell.go index e53354cd..8d7e165f 100644 --- a/core/wiki/shell.go +++ b/core/wiki/shell.go @@ -18,18 +18,15 @@ const ( const SHELL = "shell" func init() { - Index.Merge(&ice.Context{ - Commands: map[string]*ice.Command{ - SHELL: {Name: "shell [name] cmd", Help: "命令", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { - arg = _name(m, arg) - _shell_show(m, arg[0], kit.Select(arg[0], arg[1]), arg[2:]...) - }}, - }, - Configs: map[string]*ice.Config{ - SHELL: {Name: SHELL, Help: "命令", Value: kit.Data( - kit.MDB_TEMPLATE, `$ {{.Option "input"}} # {{.Option "name"}} + Index.Merge(&ice.Context{Commands: map[string]*ice.Command{ + SHELL: {Name: "shell [name] cmd", Help: "命令", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { + arg = _name(m, arg) + _shell_show(m, arg[0], kit.Select(arg[0], arg[1]), arg[2:]...) + }}, + }, Configs: map[string]*ice.Config{ + SHELL: {Name: SHELL, Help: "命令", Value: kit.Data( + kit.MDB_TEMPLATE, `$ {{.Option "input"}} # {{.Option "name"}} {{.Option "output"}}`, - )}, - }, - }) + )}, + }}) } diff --git a/core/wiki/spark.go b/core/wiki/spark.go index 842d0325..e2bc9ffb 100644 --- a/core/wiki/spark.go +++ b/core/wiki/spark.go @@ -14,7 +14,7 @@ func _spark_show(m *ice.Message, name, text string, arg ...string) { return } - prompt := kit.Select(name+"> ", m.Conf(SPARK, kit.Keym(ssh.PROMPT, name))) + prompt := kit.Select(name+"> ", m.Config(kit.Keys(ssh.PROMPT, name))) m.Echo(`
`, name) defer m.Echo("
") @@ -23,7 +23,7 @@ func _spark_show(m *ice.Message, name, text string, arg ...string) { return } - for _, l := range strings.Split(text, "\n") { + for _, l := range strings.Split(text, ice.NL) { m.Echo("
") m.Echo("") m.Echo("").Echo(l).Echo("") @@ -33,54 +33,47 @@ func _spark_show(m *ice.Message, name, text string, arg ...string) { const ( PROMPT = "prompt" -) - -const ( - SSH_SHELL = "shell" - SSH_BREAK = "break" + BREAK = "break" ) const SPARK = "spark" func init() { - Index.Merge(&ice.Context{ - Commands: map[string]*ice.Command{ - ice.CTX_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { - ice.AddRender(ice.RENDER_SCRIPT, func(m *ice.Message, cmd string, args ...interface{}) string { - arg := kit.Simple(args...) - if len(arg) == 1 && arg[0] != SSH_BREAK { - arg = []string{SSH_SHELL, arg[0]} - } - list := []string{kit.Format(`
`, arg[0])} - for _, l := range strings.Split(strings.Join(arg[1:], "\n"), "\n") { - switch list = append(list, "
"); arg[0] { - case SSH_SHELL: - list = append(list, "") - default: - list = append(list, "") - } - list = append(list, "", l, "") - list = append(list, "
") - } - list = append(list, "
") - return strings.Join(list, "") - }) - }}, - SPARK: {Name: "spark [name] text", Help: "段落", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { - if len(arg) == 0 { - m.Echo(`
`) - return + Index.Merge(&ice.Context{Commands: map[string]*ice.Command{ + ice.CTX_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { + ice.AddRender(ice.RENDER_SCRIPT, func(m *ice.Message, cmd string, args ...interface{}) string { + arg := kit.Simple(args...) + if len(arg) == 1 && arg[0] != BREAK { + arg = []string{SHELL, arg[0]} } + list := []string{kit.Format(`
`, arg[0])} + for _, l := range strings.Split(strings.Join(arg[1:], ice.NL), ice.NL) { + switch list = append(list, "
"); arg[0] { + case SHELL: + list = append(list, "") + default: + list = append(list, "") + } + list = append(list, "", l, "") + list = append(list, "
") + } + list = append(list, "
") + return strings.Join(list, "") + }) + }}, + SPARK: {Name: "spark [name] text", Help: "段落", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { + if len(arg) == 0 { + m.Echo(`
`) + return + } - arg = _name(m, arg) - _spark_show(m, arg[0], strings.TrimSpace(arg[1]), arg[2:]...) - }}, - }, - Configs: map[string]*ice.Config{ - SPARK: {Name: SPARK, Help: "段落", Value: kit.Data( - kit.MDB_TEMPLATE, `

{{.Option "text"}}

`, - ssh.PROMPT, kit.Dict("shell", "$ "), - )}, - }, - }) + arg = _name(m, arg) + _spark_show(m, arg[0], strings.TrimSpace(arg[1]), arg[2:]...) + }}, + }, Configs: map[string]*ice.Config{ + SPARK: {Name: SPARK, Help: "段落", Value: kit.Data( + kit.MDB_TEMPLATE, `

{{.Option "text"}}

`, + ssh.PROMPT, kit.Dict(SHELL, "$ "), + )}, + }}) } diff --git a/core/wiki/table.go b/core/wiki/table.go index 5fb532af..6e99b2ff 100644 --- a/core/wiki/table.go +++ b/core/wiki/table.go @@ -38,9 +38,9 @@ func _table_show(m *ice.Message, text string, arg ...string) { style := []string{} for i := 1; i < len(ls)-1; i += 2 { switch ls[i] { - case "bg": + case BG: ls[i] = "background-color" - case "fg": + case FG: ls[i] = "color" } style = append(style, ls[i]+":"+ls[i+1]) @@ -60,25 +60,22 @@ func _table_show(m *ice.Message, text string, arg ...string) { const TABLE = "table" func init() { - Index.Merge(&ice.Context{ - Commands: map[string]*ice.Command{ - TABLE: {Name: "table `[item item\n]...`", Help: "表格", Action: map[string]*ice.Action{ - ice.RUN: {Name: "run", Help: "执行", Hand: func(m *ice.Message, arg ...string) { - _table_run(m, arg...) - }}, - }, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { - _table_show(m, arg[0], arg[1:]...) + Index.Merge(&ice.Context{Commands: map[string]*ice.Command{ + TABLE: {Name: "table `[item item\n]...`", Help: "表格", Action: map[string]*ice.Action{ + ice.RUN: {Name: "run", Help: "执行", Hand: func(m *ice.Message, arg ...string) { + _table_run(m, arg...) }}, - }, - Configs: map[string]*ice.Config{ - TABLE: {Name: TABLE, Help: "表格", Value: kit.Data( - kit.MDB_TEMPLATE, ` + }, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { + _table_show(m, arg[0], arg[1:]...) + }}, + }, Configs: map[string]*ice.Config{ + TABLE: {Name: TABLE, Help: "表格", Value: kit.Data( + kit.MDB_TEMPLATE, `
{{range $i, $v := .Optionv "head"}}{{end}} {{range $index, $value := .Optionv "list"}} {{range $i, $v := $value}}{{end}} {{end}}
{{$v}}
{{$v}}
`, - )}, - }, - }) + )}, + }}) } diff --git a/core/wiki/title.go b/core/wiki/title.go index b38aaae1..8541a70c 100644 --- a/core/wiki/title.go +++ b/core/wiki/title.go @@ -36,14 +36,11 @@ func _title_parse(m *ice.Message, dir string, root map[string]interface{}, list ls[1] = path.Join(dir, ls[1]) } - meta := kit.Dict( - "name", kit.Select("", ls, 0), - "link", kit.Select("", ls, 1), - ) + meta := kit.Dict(kit.MDB_NAME, kit.Select("", ls, 0), kit.MDB_LINK, kit.Select("", ls, 1)) for i := 2; i < len(ls); i += 2 { meta[ls[i]] = ls[i+1] } - last = kit.Dict("meta", meta, "list", kit.List()) + last = kit.Data(meta) kit.Value(root, "list.-2", last) } return len(list) @@ -53,19 +50,19 @@ func _title_show(m *ice.Message, kind, text string, arg ...string) { switch title, _ := m.Optionv(TITLE).(map[string]int); kind { case NAVMENU: // 导航目录 _option(m, kind, "", text, arg...) - data := kit.Dict("meta", kit.Dict(), "list", kit.List()) + data := kit.Data() _title_parse(m, path.Dir(m.Option(ice.MSG_SCRIPT)), data, strings.Split(text, ice.NL)) m.RenderTemplate(kit.Format("
", kit.Format(data))) return case PREMENU: // 前置目录 _option(m, kind, "", "", arg...) - m.RenderTemplate(m.Conf(TITLE, kit.Keym(kind))) + m.RenderTemplate(m.Config(kind)) return case ENDMENU: // 后置目录 _option(m, kind, "", "", arg...) - m.RenderTemplate(m.Conf(TITLE, kit.Keym(kind))) + m.RenderTemplate(m.Config(kind)) return case SECTION: // 分节标题 @@ -104,7 +101,7 @@ const TITLE = "title" func init() { Index.Merge(&ice.Context{Commands: map[string]*ice.Command{ - TITLE: {Name: "title [premenu|chapter|section|endmenu] text", Help: "标题", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { + TITLE: {Name: "title [navmenu|premenu|chapter|section|endmenu] text", Help: "标题", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { if len(arg) == 0 { ns := kit.Split(ice.Info.NodeName, "-") arg = append(arg, ns[len(ns)-1]) diff --git a/core/wiki/video.go b/core/wiki/video.go index 352e4a3d..54f118f3 100644 --- a/core/wiki/video.go +++ b/core/wiki/video.go @@ -21,21 +21,18 @@ const ( const VIDEO = "video" func init() { - Index.Merge(&ice.Context{ - Commands: map[string]*ice.Command{ - VIDEO: {Name: "video url", Help: "视频", Action: map[string]*ice.Action{ - mdb.RENDER: {Name: "render", Help: "渲染", Hand: func(m *ice.Message, arg ...string) { - _video_show(m, path.Join(arg[2], arg[1])) - }}, - }, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { - _video_show(m, arg[0], arg[1:]...) + Index.Merge(&ice.Context{Commands: map[string]*ice.Command{ + VIDEO: {Name: "video url", Help: "视频", Action: map[string]*ice.Action{ + mdb.RENDER: {Name: "render", Help: "渲染", Hand: func(m *ice.Message, arg ...string) { + _video_show(m, path.Join(arg[2], arg[1])) }}, - }, - Configs: map[string]*ice.Config{ - VIDEO: {Name: "video", Help: "视频", Value: kit.Data( - kit.MDB_TEMPLATE, ``, - kit.MDB_PATH, ice.USR_LOCAL_IMAGE, - )}, - }, - }) + }, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { + _video_show(m, arg[0], arg[1:]...) + }}, + }, Configs: map[string]*ice.Config{ + VIDEO: {Name: "video", Help: "视频", Value: kit.Data( + kit.MDB_TEMPLATE, ``, + kit.MDB_PATH, ice.USR_LOCAL_IMAGE, + )}, + }}) } diff --git a/core/wiki/wiki.go b/core/wiki/wiki.go index f9ce7e9b..39a990ee 100644 --- a/core/wiki/wiki.go +++ b/core/wiki/wiki.go @@ -10,18 +10,36 @@ import ( kit "shylinux.com/x/toolkits" ) +func _name(m *ice.Message, arg []string) []string { + if len(arg) == 1 { + return []string{"", arg[0]} + } + return arg +} +func _option(m *ice.Message, kind, name, text string, arg ...string) { + m.Option(kit.MDB_TYPE, kind) + m.Option(kit.MDB_NAME, name) + m.Option(kit.MDB_TEXT, text) + + extra := kit.Dict() + m.Optionv(kit.MDB_EXTRA, extra) + for i := 0; i < len(arg); i += 2 { + extra[arg[i]] = kit.Format(kit.Parse(nil, "", kit.Split(arg[i+1])...)) + } +} + func _wiki_path(m *ice.Message, cmd string, arg ...string) string { - return path.Join(m.Option(ice.MSG_LOCAL), m.Conf(cmd, kit.META_PATH), path.Join(arg...)) + return path.Join(m.Option(ice.MSG_LOCAL), m.Conf(cmd, kit.Keym(nfs.PATH)), path.Join(arg...)) } func _wiki_link(m *ice.Message, cmd string, text string) string { - if !strings.HasPrefix(text, "http") && !strings.HasPrefix(text, "/") { + if !strings.HasPrefix(text, "http") && !strings.HasPrefix(text, ice.PS) { text = path.Join("/share/local", _wiki_path(m, cmd, text)) } return text } func _wiki_list(m *ice.Message, cmd string, arg ...string) bool { m.Option(nfs.DIR_ROOT, _wiki_path(m, cmd)) - if len(arg) == 0 || strings.HasSuffix(arg[0], "/") { + if len(arg) == 0 || strings.HasSuffix(arg[0], ice.PS) { if m.Option(nfs.DIR_DEEP) != ice.TRUE { // 目录列表 m.Option(nfs.DIR_TYPE, nfs.DIR) m.Cmdy(nfs.DIR, kit.Select("./", arg, 0)) @@ -52,20 +70,13 @@ func _wiki_template(m *ice.Message, cmd string, name, text string, arg ...string const WIKI = "wiki" -var Index = &ice.Context{Name: WIKI, Help: "文档中心", Commands: map[string]*ice.Command{ - ice.CTX_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { - m.Load() - }}, - ice.CTX_EXIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { - m.Save() - }}, -}} +var Index = &ice.Context{Name: WIKI, Help: "文档中心"} func init() { web.Index.Register(Index, &web.Frame{}, - FEEL, WORD, DATA, DRAW, - TITLE, BRIEF, REFER, SPARK, - ORDER, TABLE, CHART, IMAGE, VIDEO, + TITLE, BRIEF, REFER, SPARK, CHART, + ORDER, TABLE, IMAGE, VIDEO, FIELD, SHELL, LOCAL, PARSE, + FEEL, DRAW, WORD, DATA, ) } diff --git a/core/wiki/wiki.shy b/core/wiki/wiki.shy index 2e152165..688713a7 100644 --- a/core/wiki/wiki.shy +++ b/core/wiki/wiki.shy @@ -1,29 +1,26 @@ + title.go brief.go refer.go spark.go +chart.go order.go table.go -chart.go image.go video.go +poems.go field.go shell.go local.go parse.go -data.go -draw.go feel.go +draw.go word.go +data.go +json.go wiki.go wiki.shy - -field "影音" web.wiki.feel -field "数据" web.wiki.data -field "文档" web.wiki.word -field "绘图" web.wiki.draw - diff --git a/core/wiki/word.go b/core/wiki/word.go index a67c4de5..5c651e02 100644 --- a/core/wiki/word.go +++ b/core/wiki/word.go @@ -1,9 +1,6 @@ package wiki import ( - "net/http" - "strings" - ice "shylinux.com/x/icebergs" "shylinux.com/x/icebergs/base/ctx" "shylinux.com/x/icebergs/base/nfs" @@ -12,24 +9,6 @@ import ( kit "shylinux.com/x/toolkits" ) -func _name(m *ice.Message, arg []string) []string { - if len(arg) == 1 { - return []string{"", arg[0]} - } - return arg -} -func _option(m *ice.Message, kind, name, text string, arg ...string) { - m.Option(kit.MDB_TYPE, kind) - m.Option(kit.MDB_NAME, name) - m.Option(kit.MDB_TEXT, text) - - extra := kit.Dict() - m.Optionv(kit.MDB_EXTRA, extra) - for i := 0; i < len(arg); i += 2 { - extra[arg[i]] = kit.Format(kit.Parse(nil, "", kit.Split(arg[i+1])...)) - } -} - func _word_show(m *ice.Message, name string, arg ...string) { m.Set(ice.MSG_RESULT) m.Option(TITLE, map[string]int{}) @@ -40,11 +19,6 @@ func _word_show(m *ice.Message, name string, arg ...string) { m.Cmdy(ssh.SOURCE, name) } -func _word_template(m *ice.Message, cmd string, arg ...string) { - arg = _name(m, arg) - _wiki_template(m, cmd, arg[0], kit.Select(arg[0], arg[1]), arg[2:]...) -} - const WORD = "word" func init() { @@ -62,35 +36,17 @@ func init() { )}, }, Commands: map[string]*ice.Command{ WORD: {Name: "word path=src/main.shy auto play", Help: "语言文字", Meta: kit.Dict( - ice.Display("/plugin/local/wiki/word.js", WORD), + ice.Display("/plugin/local/wiki/word.js"), ), Action: ice.MergeAction(map[string]*ice.Action{ - "play": {Name: "play", Help: "演示"}, web.STORY: {Name: "story", Help: "运行", Hand: func(m *ice.Message, arg ...string) { m.Cmdy(arg[0], ctx.ACTION, ice.RUN, arg[2:]) }}, + "play": {Name: "play", Help: "演示"}, }, ctx.CmdAction()), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { - m.Option(nfs.DIR_REG, m.Conf(WORD, kit.Keym(kit.MDB_REGEXP))) + m.Option(nfs.DIR_REG, m.Config(kit.MDB_REGEXP)) if m.Option(nfs.DIR_DEEP, ice.TRUE); !_wiki_list(m, cmd, arg...) { _word_show(m, arg[0]) } }}, - "/word/": {Name: "word", Help: "文档", Meta: kit.Dict( - ice.Display("/plugin/local/wiki/word.js", WORD), - ), Action: ice.MergeAction(map[string]*ice.Action{ - web.STORY: {Name: "story", Help: "运行", Hand: func(m *ice.Message, arg ...string) { - m.Cmdy(arg[0], ctx.ACTION, ice.RUN, arg[2:]) - }}, - ctx.COMMAND: {Name: "command", Help: "命令", Hand: func(m *ice.Message, arg ...string) { - m.Cmdy(ctx.COMMAND, "web.wiki.word") - if ls := strings.Split(m.Option("_names"), "/word/"); len(ls) > 1 { - m.Push("args", ls[1]) - } - }}, - }, ctx.CmdAction()), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { - if m.R.Method == http.MethodGet { - m.RenderIndex(web.SERVE, ice.VOLCANOS, "page/cmd.html") - return // 目录 - } - }}, }}) } diff --git a/misc/git/spide.go b/misc/git/spide.go index 435786d7..d3105558 100644 --- a/misc/git/spide.go +++ b/misc/git/spide.go @@ -76,7 +76,7 @@ func init() { if arg[0] == path.Base(kit.Pwd()) { m.Option(nfs.DIR_ROOT, path.Join(ice.SRC)) } else { - m.Option(nfs.DIR_ROOT, path.Join(ice.USR, arg[0])) + m.Option(nfs.DIR_ROOT, path.Join(ice.USR, arg[0])+ice.PS) } if len(arg) == 1 { // 目录列表