From 9ae43d9b96122b3ed0fc5b3761e104bd241f1c35 Mon Sep 17 00:00:00 2001 From: shaoying Date: Mon, 26 Jul 2021 01:03:18 +0800 Subject: [PATCH] opt wiki --- base/ctx/command.go | 3 + base/ssh/scripts.go | 2 +- conf.go | 2 + core/chat/meet.go | 2 +- core/team/count.go | 4 +- core/team/plan.go | 2 +- core/wiki/baidu.go | 39 ---- core/wiki/chart.go | 79 ++++++++ core/wiki/data.go | 12 +- core/wiki/draw.go | 12 +- core/wiki/feel.go | 2 +- core/wiki/image.go | 21 +- core/wiki/template.go | 58 ------ core/wiki/video.go | 2 +- core/wiki/wiki.go | 17 +- core/wiki/wiki.shy | 22 +- core/wiki/word.go | 426 ++------------------------------------- misc.go | 22 +- misc/git/spide.go | 2 +- misc/git/trend.go | 2 +- misc/trash/md/md.go | 11 +- misc/trash/web/_favor.go | 3 +- type.go | 6 - 23 files changed, 192 insertions(+), 559 deletions(-) delete mode 100644 core/wiki/baidu.go diff --git a/base/ctx/command.go b/base/ctx/command.go index b48b38fa..fa64a9cd 100644 --- a/base/ctx/command.go +++ b/base/ctx/command.go @@ -47,6 +47,9 @@ func _command_search(m *ice.Message, kind, name, text string) { }) } +const ( + ACTION = "action" +) const COMMAND = "command" func init() { diff --git a/base/ssh/scripts.go b/base/ssh/scripts.go index 9646b545..931d419e 100644 --- a/base/ssh/scripts.go +++ b/base/ssh/scripts.go @@ -225,7 +225,7 @@ func (f *Frame) parse(m *ice.Message, line string) string { msg.Cmdy(ls[0], ls[1:]) } - if strings.HasPrefix(msg.Result(), ice.ErrWarn) && m.Option("render") == "raw" { + if strings.HasPrefix(msg.Result(), ice.ErrWarn) && m.Option(ice.MSG_RENDER) == ice.RENDER_RAW { fmt.Fprintf(msg.O, line) continue } diff --git a/conf.go b/conf.go index 0e974076..b1668063 100644 --- a/conf.go +++ b/conf.go @@ -87,6 +87,7 @@ const ( // MSG MSG_SOURCE = "_source" MSG_TARGET = "_target" MSG_HANDLE = "_handle" + MSG_RENDER = "_render" MSG_OUTPUT = "_output" MSG_ARGS = "_args" @@ -122,6 +123,7 @@ const ( // MSG MSG_TOAST = "sess.toast" ) const ( // RENDER + RENDER_RAW = "_raw" RENDER_VOID = "_void" RENDER_RESULT = "_result" RENDER_ANCHOR = "_anchor" diff --git a/core/chat/meet.go b/core/chat/meet.go index 2d847383..2ec9796f 100644 --- a/core/chat/meet.go +++ b/core/chat/meet.go @@ -27,7 +27,7 @@ func init() { ice.CTX_EXIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { m.Save() }}, MEDIA: {Name: "media name auto open snapshot", Help: "视频会议", Meta: kit.Dict( - "display", "/plugin/local/chat/media.js", + ice.Display("/plugin/local/chat/media.js"), ), Action: map[string]*ice.Action{ tcp.OPEN: {Name: "open", Help: "打开摄相头", Hand: func(m *ice.Message, arg ...string) { m.Cmdy(mdb.IMPORT, m.Prefix(MISS), "", mdb.HASH) diff --git a/core/team/count.go b/core/team/count.go index 1a131c9c..1fa53d77 100644 --- a/core/team/count.go +++ b/core/team/count.go @@ -13,7 +13,9 @@ const COUNT = "count" func init() { Index.Merge(&ice.Context{Commands: map[string]*ice.Command{ - COUNT: {Name: "count begin_time@date end_time@date auto insert", Help: "倒计时", Meta: kit.Dict(kit.MDB_DISPLAY, COUNT), Action: map[string]*ice.Action{ + COUNT: {Name: "count begin_time@date end_time@date auto insert", Help: "倒计时", Meta: kit.Dict( + ice.Display(COUNT), + ), Action: map[string]*ice.Action{ mdb.INSERT: {Name: "insert zone type=once,step,week name text begin_time@date close_time@date", Help: "添加", Hand: func(m *ice.Message, arg ...string) { m.Cmdy(TASK, mdb.INSERT, arg) }}, diff --git a/core/team/plan.go b/core/team/plan.go index bd80538d..1749572a 100644 --- a/core/team/plan.go +++ b/core/team/plan.go @@ -36,7 +36,7 @@ func init() { Index.Merge(&ice.Context{ Commands: map[string]*ice.Command{ PLAN: {Name: "plan scale=day,week,month,year,long begin_time@date auto insert export import", Help: "计划", Meta: kit.Dict( - kit.MDB_DISPLAY, "/plugin/local/team/plan.js", kit.MDB_STYLE, PLAN, + ice.Display("/plugin/local/team/plan.js", PLAN), ), Action: map[string]*ice.Action{ mdb.INSERT: {Name: "insert zone type=once,step,week name text begin_time@date close_time@date", Help: "添加", Hand: func(m *ice.Message, arg ...string) { _task_create(m, arg[1]) diff --git a/core/wiki/baidu.go b/core/wiki/baidu.go deleted file mode 100644 index 3438be0d..00000000 --- a/core/wiki/baidu.go +++ /dev/null @@ -1,39 +0,0 @@ -package wiki - -import ( - ice "github.com/shylinux/icebergs" - "github.com/shylinux/icebergs/base/mdb" - kit "github.com/shylinux/toolkits" -) - -func _baidu_show(m *ice.Message, name, text string, arg ...string) { - _option(m, BAIDU, name, text, arg...) - // m.Cmdy(mdb.RENDER, web.RENDER.Frame, kit.Format("https://baidu.com/s?wd=%s", text)) -} -func _baidu_search(m *ice.Message, kind, name, text string) { - if kit.Contains(kind, "*") || kit.Contains(kind, "baidu") { - m.PushSearchWeb(BAIDU, name) - } -} - -const BAIDU = "baidu" - -func init() { - Index.Merge(&ice.Context{ - Configs: map[string]*ice.Config{ - BAIDU: {Name: "baidu", Help: "百度", Value: kit.Data(kit.MDB_SHORT, kit.MDB_TEXT)}, - }, - Commands: map[string]*ice.Command{ - BAIDU: {Name: "baidu [name] word", Help: "百度", Action: map[string]*ice.Action{ - mdb.SEARCH: {Name: "search type name text", Help: "搜索", Hand: func(m *ice.Message, arg ...string) { - _baidu_search(m, arg[0], arg[1], arg[2]) - }}, - mdb.CREATE: {Name: "create type name text", Help: "创建", Hand: func(m *ice.Message, arg ...string) { - m.Cmd(mdb.INSERT, m.Prefix(BAIDU), "", mdb.HASH, arg) - }}, - }, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { - arg = _name(m, arg) - _baidu_show(m, arg[0], kit.Select(arg[0], arg[1]), arg[2:]...) - }}, - }}) -} diff --git a/core/wiki/chart.go b/core/wiki/chart.go index 6b6e9658..c242b17e 100644 --- a/core/wiki/chart.go +++ b/core/wiki/chart.go @@ -356,3 +356,82 @@ func Stack(m *ice.Message, name string, level int, data interface{}) { }) m.Echo("") } + +func _chart_show(m *ice.Message, kind, name, text string, arg ...string) { + var chart Chart + switch kind { + case LABEL: // 标签 + chart = &Label{} + case CHAIN: // 链接 + chart = &Chain{} + } + + // 基本参数 + m.Option(kit.MDB_TYPE, strings.TrimSpace(kind)) + m.Option(kit.MDB_NAME, strings.TrimSpace(name)) + m.Option(kit.MDB_TEXT, strings.TrimSpace(text)) + + // 扩展参数 + m.Option("font-size", "24") + m.Option("stroke", "blue") + m.Option("fill", "yellow") + // 扩展参数 + m.Option("style", "") + m.Option("stroke-width", "2") + m.Option("font-family", "monospace") + // 扩展参数 + m.Option("compact", "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("fg") != "" { + m.Option("stroke", m.Option("fg")) + } + + // 计算尺寸 + chart.Init(m, m.Option(kit.MDB_TEXT)) + m.Option("height", chart.GetHeight()) + m.Option("width", chart.GetWidth()) + + // 渲染引擎 + m.RenderTemplate(m.Conf(CHART, kit.Keym(kit.MDB_TEMPLATE))) + defer m.RenderTemplate(m.Conf(CHART, kit.Keym("suffix"))) + chart.Draw(m, 0, 0) +} + +const ( + LABEL = "label" + CHAIN = "chain" +) +const CHART = "chart" + +func init() { + Index.Merge(&ice.Context{ + Commands: map[string]*ice.Command{ + CHART: {Name: "chart label|chain [name] text", Help: "图表", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { + if len(arg) == 2 { + arg = []string{arg[0], "", arg[1]} + } + _chart_show(m, arg[0], arg[1], arg[2], arg[3:]...) + }}, + }, + Configs: map[string]*ice.Config{ + CHART: {Name: CHART, Help: "图表", Value: kit.Data( + kit.MDB_TEMPLATE, ``, "suffix", ``, + )}, + }, + }) +} diff --git a/core/wiki/data.go b/core/wiki/data.go index cb736da5..764c3ede 100644 --- a/core/wiki/data.go +++ b/core/wiki/data.go @@ -6,27 +6,25 @@ import ( kit "github.com/shylinux/toolkits" ) -func _data_show(m *ice.Message, name string, arg ...string) { - m.CSV(m.Cmd(nfs.CAT, name).Result()) -} - const DATA = "data" func init() { Index.Merge(&ice.Context{ Configs: map[string]*ice.Config{ - DATA: {Name: DATA, Help: "数据表格", Value: kit.Data(kit.MDB_PATH, "usr/local/export", kit.MDB_REGEXP, ".*\\.csv")}, + DATA: {Name: DATA, Help: "数据表格", Value: kit.Data( + kit.MDB_PATH, "usr/local/export", kit.MDB_REGEXP, ".*\\.csv", + )}, }, Commands: map[string]*ice.Command{ DATA: {Name: "data path auto", Help: "数据表格", Meta: kit.Dict( - "display", "/plugin/local/wiki/data.js", + 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)) { - _data_show(m, arg[0]) + m.CSV(m.Cmd(nfs.CAT, arg[0]).Result()) } }}, }, diff --git a/core/wiki/draw.go b/core/wiki/draw.go index 93c7a5bb..790949a1 100644 --- a/core/wiki/draw.go +++ b/core/wiki/draw.go @@ -1,11 +1,11 @@ package wiki import ( + "path" + ice "github.com/shylinux/icebergs" "github.com/shylinux/icebergs/base/nfs" kit "github.com/shylinux/toolkits" - - "path" ) const DRAW = "draw" @@ -13,13 +13,15 @@ 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")}, + DRAW: {Name: DRAW, Help: "思维导图", Value: kit.Data( + kit.MDB_PATH, "", kit.MDB_REGEXP, ".*\\.svg", + )}, }, Commands: map[string]*ice.Command{ DRAW: {Name: "draw path=src/ file=main.svg 刷新:button=auto 编辑 save 项目 参数", Help: "思维导图", Meta: kit.Dict( - "display", "/plugin/local/wiki/draw.js", + ice.Display("/plugin/local/wiki/draw.js"), ), Action: map[string]*ice.Action{ - nfs.SAVE: {Name: "save", Help: "保存", Hand: func(m *ice.Message, arg ...string) { + nfs.SAVE: {Name: "save path", Help: "保存", Hand: func(m *ice.Message, arg ...string) { _wiki_save(m, DRAW, path.Join(arg...), m.Option("content")) }}, }, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { diff --git a/core/wiki/feel.go b/core/wiki/feel.go index 8c37d69a..8efcdd17 100644 --- a/core/wiki/feel.go +++ b/core/wiki/feel.go @@ -17,7 +17,7 @@ func init() { }, Commands: map[string]*ice.Command{ FEEL: {Name: "feel path auto upload 上一页 下一页 参数", Help: "影音媒体", Meta: kit.Dict( - kit.MDB_DISPLAY, "/plugin/local/wiki/feel.js", + 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)) diff --git a/core/wiki/image.go b/core/wiki/image.go index eb9ca2c7..7aec5930 100644 --- a/core/wiki/image.go +++ b/core/wiki/image.go @@ -9,18 +9,13 @@ import ( kit "github.com/shylinux/toolkits" ) -var image = `` - func _image_show(m *ice.Message, name, text string, arg ...string) { if !strings.HasPrefix(text, "http") && !strings.HasPrefix(text, "/") { text = path.Join("/share/local", _wiki_path(m, FEEL, text)) } _option(m, IMAGE, name, text, arg...) - m.Render(ice.RENDER_TEMPLATE, m.Conf(IMAGE, kit.Keym(kit.MDB_TEMPLATE))) + m.RenderTemplate(m.Conf(IMAGE, kit.Keym(kit.MDB_TEMPLATE))) } const ( @@ -32,10 +27,10 @@ const IMAGE = "image" func init() { Index.Merge(&ice.Context{ - Configs: map[string]*ice.Config{ - IMAGE: {Name: IMAGE, Help: "图片", Value: kit.Data(kit.MDB_TEMPLATE, image)}, - }, 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 [name] url", Help: "图片", Action: map[string]*ice.Action{ mdb.RENDER: {Name: "render", Help: "渲染", Hand: func(m *ice.Message, arg ...string) { _image_show(m, arg[1], path.Join(arg[2], arg[1])) @@ -45,5 +40,13 @@ func init() { _image_show(m, arg[0], arg[1], arg[2:]...) }}, }, + Configs: map[string]*ice.Config{ + IMAGE: {Name: IMAGE, Help: "图片", Value: kit.Data( + kit.MDB_TEMPLATE, ``, + )}, + }, }) } diff --git a/core/wiki/template.go b/core/wiki/template.go index d0517a70..3e1ef4c3 100644 --- a/core/wiki/template.go +++ b/core/wiki/template.go @@ -1,59 +1 @@ package wiki - -var premenu = `` -var endmenu = `` - -var title = `<{{.Option "level"}} class="story" -{{range $k, $v := .Optionv "extra"}}data-{{$k}}='{{$v}}'{{end}} -data-type="{{.Option "type"}}" ->{{.Option "prefix"}} {{.Option "content"}}` -var brief = `

{{.Option "text"}}

` -var refer = `` -var spark = `

{{.Option "text"}}

` - -var order = `` -var table = ` -{{range $i, $v := .Optionv "head"}}{{end}} -{{range $index, $value := .Optionv "list"}} -{{range $i, $v := $value}}{{end}} -{{end}} -
{{$v}}
{{$v}}
` -var shell = `$ {{.Option "input"}} # {{.Option "name"}} -{{.Option "output"}}` -var local = `{{range $index, $value := .Optionv "input"}}{{$value}}{{end}}` - -var chart = `` -var field = `
-{{.Option "name"}} -
-
-
-
- -` -var other = `` diff --git a/core/wiki/video.go b/core/wiki/video.go index 12b5c4b1..ab4af5bd 100644 --- a/core/wiki/video.go +++ b/core/wiki/video.go @@ -20,7 +20,7 @@ func _video_show(m *ice.Message, name, text string, arg ...string) { } _option(m, VIDEO, name, text, arg...) - m.Render(ice.RENDER_TEMPLATE, m.Conf(VIDEO, kit.Keym(kit.MDB_TEMPLATE))) + m.RenderTemplate(m.Conf(VIDEO, kit.Keym(kit.MDB_TEMPLATE))) } const ( diff --git a/core/wiki/wiki.go b/core/wiki/wiki.go index 7fcdff76..b6d7a6df 100644 --- a/core/wiki/wiki.go +++ b/core/wiki/wiki.go @@ -5,7 +5,6 @@ import ( "strings" ice "github.com/shylinux/icebergs" - "github.com/shylinux/icebergs/base/mdb" "github.com/shylinux/icebergs/base/nfs" "github.com/shylinux/icebergs/base/web" kit "github.com/shylinux/toolkits" @@ -14,19 +13,17 @@ import ( 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...)) } - 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 m.Option(nfs.DIR_DEEP) != "true" { - // 目录列表 + if m.Option(nfs.DIR_DEEP) != ice.TRUE { // 目录列表 m.Option(nfs.DIR_TYPE, nfs.DIR) - m.Cmdy(nfs.DIR, kit.Select("./", arg, 0), "time,size,path") + m.Cmdy(nfs.DIR, kit.Select("./", arg, 0)) } // 文件列表 m.Option(nfs.DIR_TYPE, nfs.CAT) - m.Cmdy(nfs.DIR, kit.Select("./", arg, 0), "time,size,path") + m.Cmdy(nfs.DIR, kit.Select("./", arg, 0)) return true } return false @@ -42,13 +39,16 @@ func _wiki_save(m *ice.Message, cmd, name, text string, arg ...string) { func _wiki_upload(m *ice.Message, cmd string, dir string) { m.Upload(_wiki_path(m, cmd, dir)) } +func _wiki_template(m *ice.Message, cmd string, name, text string, arg ...string) { + _option(m, cmd, name, strings.TrimSpace(text), arg...) + m.RenderTemplate(m.Conf(cmd, kit.Keym(kit.MDB_TEMPLATE))) +} 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.Cmd(mdb.RENDER, mdb.CREATE, PNG, m.Prefix(IMAGE)) m.Load() }}, ice.CTX_EXIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { @@ -59,7 +59,6 @@ var Index = &ice.Context{Name: WIKI, Help: "文档中心", func init() { web.Index.Register(Index, &web.Frame{}, - FEEL, DRAW, DATA, WORD, - SPARK, IMAGE, + FEEL, WORD, DATA, DRAW, IMAGE, SPARK, ) } diff --git a/core/wiki/wiki.shy b/core/wiki/wiki.shy index 9b368747..04608df6 100644 --- a/core/wiki/wiki.shy +++ b/core/wiki/wiki.shy @@ -1,17 +1,27 @@ chapter "文档" +field "影音" web.wiki.feel +field "数据" web.wiki.data +field "绘图" web.wiki.draw +return +field "文档" web.wiki.word + +field "绘图" web.wiki.draw +field "绘图" web.wiki.draw +field "绘图" web.wiki.draw + wiki.go wiki.shy feel.go -draw.go -data.go word.go +data.go +draw.go chart.go +image.go +video.go +music.go +baidu.go template.go -baidu.go -music.go -video.go - diff --git a/core/wiki/word.go b/core/wiki/word.go index 7f83bfa8..b50dba4d 100644 --- a/core/wiki/word.go +++ b/core/wiki/word.go @@ -1,14 +1,9 @@ package wiki import ( - "fmt" - "net/url" - "path" - "strings" - ice "github.com/shylinux/icebergs" "github.com/shylinux/icebergs/base/cli" - "github.com/shylinux/icebergs/base/mdb" + "github.com/shylinux/icebergs/base/ctx" "github.com/shylinux/icebergs/base/nfs" "github.com/shylinux/icebergs/base/ssh" "github.com/shylinux/icebergs/base/web" @@ -33,431 +28,50 @@ func _option(m *ice.Message, kind, name, text string, arg ...string) { } } -func _title_show(m *ice.Message, kind, text string, arg ...string) { - title, _ := m.Optionv(TITLE).(map[string]int) - switch kind { - case PREMENU: - // 前置目录 - m.Render(ice.RENDER_TEMPLATE, premenu) - return - case ENDMENU: - // 后置目录 - m.Render(ice.RENDER_TEMPLATE, endmenu) - return - case SECTION: - // 分节标题 - title[SECTION]++ - m.Option("level", "h3") - m.Option("prefix", fmt.Sprintf("%d.%d ", title[CHAPTER], title[SECTION])) - case CHAPTER: - // 章节标题 - title[CHAPTER]++ - title[SECTION] = 0 - m.Option("level", "h2") - m.Option("prefix", fmt.Sprintf("%d ", title[CHAPTER])) - default: - // 文章标题 - m.Option("level", "h1") - m.Option("prefix", "") - } - - // 添加目录 - menu, _ := m.Optionv("menu").(map[string]interface{}) - menu["list"] = append(menu["list"].([]interface{}), map[string]interface{}{ - "content": m.Option("content", text), - "prefix": m.Option("prefix"), - "level": m.Option("level"), - }) - - // 渲染引擎 - _option(m, TITLE, text, text, arg...) - m.Render(ice.RENDER_TEMPLATE, m.Conf(TITLE, kit.Keym(kit.MDB_TEMPLATE))) -} -func _brief_show(m *ice.Message, name, text string, arg ...string) { - _option(m, BRIEF, name, text, arg...) - m.Render(ice.RENDER_TEMPLATE, m.Conf(BRIEF, kit.Keym(kit.MDB_TEMPLATE))) -} -func _refer_show(m *ice.Message, name, text string, arg ...string) { - list := [][]string{} - for _, v := range kit.Split(strings.TrimSpace(text), "\n", "\n") { - if ls := kit.Split(v); len(ls) == 1 { - list = append(list, []string{path.Base(ls[0]), ls[0]}) - } else { - list = append(list, ls) - } - } - m.Optionv("list", list) - - _option(m, REFER, name, text, arg...) - m.Render(ice.RENDER_TEMPLATE, m.Conf(REFER, kit.Keym(kit.MDB_TEMPLATE))) -} -func _spark_show(m *ice.Message, name, text string, arg ...string) { - switch text = strings.TrimSpace(text); name { - case "shell", "redis", "mysql": - m.Echo(`
`, name) - for _, l := range strings.Split(text, "\n") { - m.Echo("
") - m.Echo("").Echo("").Echo(l).Echo("") - m.Echo("
") - } - m.Echo("
") - return - } - m.Optionv("list", kit.Split(text, "\n", "\n")) - - _option(m, SPARK, name, text, arg...) - m.Render(ice.RENDER_TEMPLATE, m.Conf(SPARK, kit.Keym(kit.MDB_TEMPLATE))) -} - -func _order_show(m *ice.Message, name, text string, arg ...string) { - m.Optionv("list", kit.Split(strings.TrimSpace(text), "\n")) - _option(m, ORDER, name, text, arg...) - m.Render(ice.RENDER_TEMPLATE, m.Conf(ORDER, kit.Keym(kit.MDB_TEMPLATE))) -} -func _table_show(m *ice.Message, name, text string, arg ...string) { - head, list := []string{}, [][]string{} - for i, v := range kit.Split(strings.TrimSpace(text), "\n") { - if v = strings.ReplaceAll(v, "%", "%%"); i == 0 { - head = kit.Split(v) - } else { - line := kit.Split(v) - for i, v := range line { - if ls := kit.Split(v); len(ls) > 1 { - style := []string{} - for i := 1; i < len(ls)-1; i += 2 { - switch ls[i] { - case "bg": - ls[i] = "background-color" - case "fg": - ls[i] = "color" - } - style = append(style, ls[i]+":"+ls[i+1]) - } - line[i] = kit.Format(`%s`, strings.Join(style, ";"), ls[0]) - } - } - list = append(list, line) - } - } - m.Optionv("head", head) - m.Optionv("list", list) - - _option(m, TABLE, name, text, arg...) - m.Render(ice.RENDER_TEMPLATE, m.Conf(TABLE, kit.Keym(kit.MDB_TEMPLATE))) -} -func _shell_show(m *ice.Message, name, text string, arg ...string) { - m.Option("output", m.Cmdx(cli.SYSTEM, "sh", "-c", m.Option("input", text))) - _option(m, SHELL, name, text, arg...) - m.Render(ice.RENDER_TEMPLATE, m.Conf(SHELL, kit.Keym(kit.MDB_TEMPLATE))) -} -func _local_show(m *ice.Message, name, text string, arg ...string) { - m.Option("input", m.Cmdx(nfs.CAT, text)) - _option(m, LOCAL, name, text, arg...) - m.Render(ice.RENDER_TEMPLATE, m.Conf(LOCAL, kit.Keym(kit.MDB_TEMPLATE))) -} - -func _chart_show(m *ice.Message, kind, name, text string, arg ...string) { - var chart Chart - switch kind { - case LABEL: - // 标签 - chart = &Label{} - case CHAIN: - // 链接 - chart = &Chain{} - } - name = strings.TrimSpace(name) - text = strings.TrimSpace(text) - - // 基本参数 - m.Option(kit.MDB_TYPE, kind) - m.Option(kit.MDB_NAME, name) - m.Option(kit.MDB_TEXT, text) - - // 扩展参数 - m.Option("font-size", "24") - m.Option("stroke", "blue") - m.Option("fill", "yellow") - // 扩展参数 - m.Option("style", "") - m.Option("compact", "false") - m.Option("stroke-width", "2") - m.Option("padding", "10") - m.Option("marginx", "10") - m.Option("marginy", "10") - // m.Option("font-family", kit.Select("", "monospace", len(text) == len([]rune(text)))) - m.Option("font-family", "monospace") - for i := 0; i < len(arg)-1; i++ { - m.Option(arg[i], arg[i+1]) - } - if m.Option("fg") != "" { - m.Option("stroke", m.Option("fg")) - } - if m.Option("bg") != "" { - m.Option("fill", m.Option("bg")) - } - - // 计算尺寸 - chart.Init(m, text) - m.Option("width", chart.GetWidth()) - m.Option("height", chart.GetHeight()) - - // 渲染引擎 - m.Render(ice.RENDER_TEMPLATE, m.Conf(CHART, kit.Keym(kit.MDB_TEMPLATE))) - chart.Draw(m, 0, 0) - m.Render(ice.RENDER_TEMPLATE, m.Conf(CHART, "meta.suffix")) -} -func _field_show(m *ice.Message, name, text string, arg ...string) { - // 基本参数 - m.Option(kit.MDB_TYPE, FIELD) - m.Option(kit.MDB_NAME, name) - m.Option(kit.MDB_TEXT, text) - - // 命令参数 - data := kit.Dict(kit.MDB_NAME, name) - cmds := kit.Split(text) - m.Search(cmds[0], func(p *ice.Context, s *ice.Context, key string, cmd *ice.Command) { - data["feature"], data["inputs"] = cmd.Meta, cmd.List - }) - - // 扩展参数 - for i := 0; i < len(arg)-1; i += 2 { - if strings.HasPrefix(arg[i], "args.") { - m.Option(arg[i], strings.TrimSpace(arg[i+1])) - kit.Value(data, arg[i], m.Option(arg[i])) - } else if strings.HasPrefix(arg[i], "args") { - m.Option(arg[i], kit.Split(strings.TrimSuffix(strings.TrimPrefix(arg[i+1], "["), "]"))) - kit.Value(data, arg[i], m.Optionv(arg[i])) - } else { - m.Parse("option", arg[i], arg[i+1]) - kit.Value(data, arg[i], m.Optionv(arg[i])) - } - - switch arg[i] { - case "content": - data[arg[i]] = arg[i+1] - - case "args": - args := kit.Simple(m.Optionv(arg[i])) - - count := 0 - kit.Fetch(data["inputs"], func(index int, value map[string]interface{}) { - if value["_input"] != "button" && value["type"] != "button" { - count++ - } - }) - - if len(args) > count { - list := data["inputs"].([]interface{}) - for i := count; i < len(args); i++ { - list = append(list, kit.Dict( - "_input", "text", "name", "args", "value", args[i], - )) - } - data["inputs"] = list - } - } - } - - // 渲染引擎 - m.Option(kit.MDB_META, data) - m.Render(ice.RENDER_TEMPLATE, m.Conf(FIELD, kit.Keym(kit.MDB_TEMPLATE))) -} -func _other_show(m *ice.Message, name, text string, arg ...string) { - _option(m, OTHER, name, text, arg...) - m.Render(ice.RENDER_TEMPLATE, m.Conf(OTHER, kit.Keym(kit.MDB_TEMPLATE))) -} - func _word_show(m *ice.Message, name string, arg ...string) { m.Set(ice.MSG_RESULT) - m.Option("render", "raw") m.Option(TITLE, map[string]int{}) - m.Option("menu", map[string]interface{}{"list": []interface{}{}}) + m.Option("menu", kit.Dict("list", []interface{}{})) - m.Option(ice.MSG_ALIAS, m.Confv(WORD, "meta.alias")) + m.Option(ice.MSG_ALIAS, m.Confv(WORD, kit.Keym("alias"))) m.Option(nfs.DIR_ROOT, _wiki_path(m, WORD)) + m.Option(ice.MSG_RENDER, ice.RENDER_RAW) m.Cmdy(ssh.SOURCE, name) } -const ( - TITLE = "title" - BRIEF = "brief" - REFER = "refer" - SPARK = "spark" - - ORDER = "order" - TABLE = "table" - SHELL = "shell" - LOCAL = "local" - - CHART = "chart" - FIELD = "field" - OTHER = "other" - - PARSE = "parse" - - PREMENU = "premenu" - CHAPTER = "chapter" - SECTION = "section" - ENDMENU = "endmenu" - - LABEL = "label" - CHAIN = "chain" -) +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() { Index.Merge(&ice.Context{ Configs: map[string]*ice.Config{ - TITLE: {Name: TITLE, Help: "标题", Value: kit.Data(kit.MDB_TEMPLATE, title)}, - BRIEF: {Name: BRIEF, Help: "摘要", Value: kit.Data(kit.MDB_TEMPLATE, brief)}, - REFER: {Name: REFER, Help: "参考", Value: kit.Data(kit.MDB_TEMPLATE, refer)}, - SPARK: {Name: SPARK, Help: "段落", Value: kit.Data(kit.MDB_TEMPLATE, spark, "prompt", kit.Dict("shell", "$ "))}, - - ORDER: {Name: ORDER, Help: "列表", Value: kit.Data(kit.MDB_TEMPLATE, order)}, - TABLE: {Name: TABLE, Help: "表格", Value: kit.Data(kit.MDB_TEMPLATE, table)}, - SHELL: {Name: SHELL, Help: "命令", Value: kit.Data(kit.MDB_TEMPLATE, shell)}, - LOCAL: {Name: LOCAL, Help: "文件", Value: kit.Data(kit.MDB_TEMPLATE, local)}, - - CHART: {Name: CHART, Help: "图表", Value: kit.Data(kit.MDB_TEMPLATE, chart, "suffix", ``)}, - FIELD: {Name: FIELD, Help: "插件", Value: kit.Data(kit.MDB_TEMPLATE, field)}, - OTHER: {Name: FIELD, Help: "网页", Value: kit.Data(kit.MDB_TEMPLATE, other)}, - WORD: {Name: WORD, Help: "语言文字", Value: kit.Data( - kit.MDB_PATH, "", kit.MDB_REGEXP, ".*\\.shy", "alias", map[string]interface{}{ - PREMENU: []interface{}{TITLE, PREMENU}, - CHAPTER: []interface{}{TITLE, CHAPTER}, - SECTION: []interface{}{TITLE, SECTION}, - ENDMENU: []interface{}{TITLE, ENDMENU}, - LABEL: []interface{}{CHART, LABEL}, - CHAIN: []interface{}{CHART, CHAIN}, - }, + kit.MDB_PATH, "", kit.MDB_REGEXP, ".*\\.shy", "alias", kit.Dict( + PREMENU, []interface{}{TITLE, PREMENU}, + CHAPTER, []interface{}{TITLE, CHAPTER}, + SECTION, []interface{}{TITLE, SECTION}, + ENDMENU, []interface{}{TITLE, ENDMENU}, + LABEL, []interface{}{CHART, LABEL}, + CHAIN, []interface{}{CHART, CHAIN}, + ), )}, }, 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) { - if len(arg) == 0 { - ns := strings.Split(ice.Info.NodeName, "-") - arg = append(arg, kit.Select(ns[len(ns)-1], "")) - } - - if len(arg) == 1 { - arg = append(arg, "") - } - _title_show(m, arg[0], kit.Select(arg[0], arg[1]), arg[2:]...) - }}, - BRIEF: {Name: "brief [name] text", Help: "摘要", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { - arg = _name(m, arg) - _brief_show(m, arg[0], kit.Select(arg[0], arg[1]), arg[2:]...) - }}, - REFER: {Name: "refer [name] `[name url]...`", Help: "参考", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { - arg = _name(m, arg) - _refer_show(m, arg[0], arg[1], arg[2:]...) - }}, - 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], kit.Select(arg[0], arg[1]), arg[2:]...) - }}, - - ORDER: {Name: "order [name] `[item \n]...`", Help: "列表", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { - arg = _name(m, arg) - _order_show(m, arg[0], kit.Select(arg[0], arg[1]), arg[2:]...) - }}, - TABLE: {Name: "table [name] `[item item\n]...`", Help: "表格", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { - arg = _name(m, arg) - _table_show(m, arg[0], kit.Select(arg[0], arg[1]), arg[2:]...) - }}, - 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:]...) - }}, - 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:]...) - }}, - - CHART: {Name: "chart label|chain [name] text", Help: "图表", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { - if len(arg) == 2 { - arg = []string{arg[0], "", arg[1]} - } - _chart_show(m, arg[0], arg[1], arg[2], arg[3:]...) - }}, - FIELD: {Name: "field [name] cmd", Help: "插件", Action: map[string]*ice.Action{ - "run": {Name: "run", Help: "运行", Hand: func(m *ice.Message, arg ...string) { - if !m.Warn(!m.Right(arg[1:]), ice.ErrNotRight, arg[1:]) { - m.Cmdy(arg[1:]) - } - }}, - }, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { - arg = _name(m, arg) - _field_show(m, strings.ReplaceAll(kit.Select(path.Base(arg[1]), arg[0]), " ", "_"), arg[1], arg[2:]...) - }}, - OTHER: {Name: "other [name] url", Help: "网页", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { - arg = _name(m, arg) - _other_show(m, arg[0], kit.Select(arg[0], arg[1]), arg[2:]...) - }}, - - PARSE: {Name: "parse type=auto,json,http,form,list auto text:textarea", Help: "解析", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { - if len(arg) < 2 { - return - } - if arg[0] == "auto" && (strings.HasPrefix(arg[1], "{") || strings.HasPrefix(arg[1], "[")) { - arg[0] = "json" - } else if strings.HasPrefix(arg[1], "http") { - arg[0] = "http" - } else if strings.Contains(arg[1], "=") { - arg[0] = "form" - } else { - arg[0] = "list" - } - - m.Option(mdb.FIELDS, mdb.DETAIL) - switch arg[0] { - case "json": - m.Echo(kit.Formats(kit.UnMarshal(arg[1]))) - case "http": - u, _ := url.Parse(arg[1]) - for k, v := range u.Query() { - for _, v := range v { - m.Push(k, v) - } - } - m.EchoQRCode(arg[1]) - - case "form": - for _, v := range kit.Split(arg[1], "&", "&", "&") { - ls := kit.Split(v, "=", "=", "=") - key, _ := url.QueryUnescape(ls[0]) - value, _ := url.QueryUnescape(kit.Select("", ls, 1)) - m.Push(key, value) - } - case "list": - for i, v := range kit.Split(arg[1]) { - m.Push(kit.Format(i), v) - } - } - }}, - WORD: {Name: "word path=src/main.shy auto 演示", Help: "语言文字", Meta: kit.Dict( - kit.MDB_DISPLAY, "/plugin/local/wiki/word.js", kit.MDB_STYLE, WORD, + ice.Display("/plugin/local/wiki/word.js", WORD), ), Action: map[string]*ice.Action{ web.STORY: {Name: "story", Help: "运行", Hand: func(m *ice.Message, arg ...string) { - m.Cmdy(arg[0], kit.MDB_ACTION, "run", arg[1:]) + m.Cmdy(arg[0], ctx.ACTION, cli.RUN, arg[1:]) }}, }, 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))) - if m.Option(nfs.DIR_DEEP, "true"); _wiki_list(m, cmd, arg...) { - return + if m.Option(nfs.DIR_DEEP, ice.TRUE); !_wiki_list(m, cmd, arg...) { + _word_show(m, arg[0]) } - _word_show(m, arg[0]) }}, }, }) diff --git a/misc.go b/misc.go index 1e6381e7..6482fe1c 100644 --- a/misc.go +++ b/misc.go @@ -544,7 +544,8 @@ func Display(file string, arg ...string) map[string]string { file = kit.Select(file+".js", file, strings.HasSuffix(file, ".js")) file = path.Join("/require/github.com/shylinux", path.Dir(ls[len(ls)-1]), file) } - return map[string]string{kit.MDB_DISPLAY: file, kit.MDB_STYLE: kit.Select("", arg, 0)} + // return map[string]string{kit.MDB_DISPLAY: file, kit.MDB_STYLE: kit.Select("", arg, 0)} + return map[string]string{"display": file, kit.MDB_STYLE: kit.Select("", arg, 0)} } func (m *Message) OptionSplit(fields ...string) (res []string) { for _, k := range strings.Split(strings.Join(fields, ","), ",") { @@ -552,3 +553,22 @@ func (m *Message) OptionSplit(fields ...string) (res []string) { } return res } +func (m *Message) OptionTemplate() string { + res := []string{`class="story"`} + for _, key := range kit.Split("style") { + if m.Option(key) != "" { + res = append(res, kit.Format(`s="%s"`, key, m.Option(key))) + } + } + for _, key := range kit.Split("type,name,text") { + if m.Option(key) != "" { + res = append(res, kit.Format(`data-%s="%s"`, key, m.Option(key))) + } + } + kit.Fetch(m.Optionv("extra"), func(key string, value string) { + if value != "" { + res = append(res, kit.Format(`data-%s="%s"`, key, value)) + } + }) + return strings.Join(res, " ") +} diff --git a/misc/git/spide.go b/misc/git/spide.go index b47439f4..040efff7 100644 --- a/misc/git/spide.go +++ b/misc/git/spide.go @@ -62,7 +62,7 @@ const SPIDE = "spide" func init() { Index.Merge(&ice.Context{Commands: map[string]*ice.Command{ SPIDE: {Name: "spide name@key auto", Help: "构架图", Meta: kit.Dict( - kit.MDB_DISPLAY, "/plugin/story/spide.js", + ice.Display("/plugin/story/spide.js"), ), Action: map[string]*ice.Action{ mdb.INPUTS: {Name: "inputs", Help: "补全", Hand: func(m *ice.Message, arg ...string) { m.Cmdy(REPOS) diff --git a/misc/git/trend.go b/misc/git/trend.go index 052e8241..6409a169 100644 --- a/misc/git/trend.go +++ b/misc/git/trend.go @@ -13,7 +13,7 @@ const TREND = "trend" func init() { Index.Merge(&ice.Context{Commands: map[string]*ice.Command{ TREND: {Name: "trend name@key begin_time@date auto", Help: "趋势图", Meta: kit.Dict( - kit.MDB_DISPLAY, "/plugin/story/trend.js", + ice.Display("/plugin/story/trend.js"), ), Action: map[string]*ice.Action{ mdb.INPUTS: {Name: "inputs", Help: "补全", Hand: func(m *ice.Message, arg ...string) { m.Cmdy(REPOS, ice.OptionFields("name,time")) diff --git a/misc/trash/md/md.go b/misc/trash/md/md.go index b1f505f0..6ee6b2a1 100644 --- a/misc/trash/md/md.go +++ b/misc/trash/md/md.go @@ -1,14 +1,15 @@ package md import ( - "github.com/shylinux/icebergs" + ice "github.com/shylinux/icebergs" "github.com/shylinux/icebergs/core/wiki" - "github.com/shylinux/toolkits" + kit "github.com/shylinux/toolkits" - "github.com/gomarkdown/markdown" "io/ioutil" "path" "strings" + + "github.com/gomarkdown/markdown" ) /* @@ -42,7 +43,9 @@ var Index = &ice.Context{Name: "md", Help: "md", m.Echo("hello world") }}, - "note": {Name: "note file", Help: "文档", Meta: kit.Dict("display", "inner"), List: kit.List( + "note": {Name: "note file", Help: "文档", Meta: kit.Dict( + ice.Display("inner"), + ), List: kit.List( kit.MDB_INPUT, "text", "name", "path", "value", "README.md", "action", "auto", kit.MDB_INPUT, "button", "name", "执行", "action", "auto", kit.MDB_INPUT, "button", "name", "返回", "cb", "Last", diff --git a/misc/trash/web/_favor.go b/misc/trash/web/_favor.go index 76fecf68..460cf61d 100644 --- a/misc/trash/web/_favor.go +++ b/misc/trash/web/_favor.go @@ -2,6 +2,7 @@ package web import ( ice "github.com/shylinux/icebergs" + "github.com/shylinux/icebergs/base/aaa" "github.com/shylinux/icebergs/base/mdb" kit "github.com/shylinux/toolkits" @@ -394,7 +395,7 @@ func init() { m.Option(kit.MDB_TYPE, value[kit.MDB_TYPE]) m.Option(kit.MDB_NAME, value[kit.MDB_NAME]) m.Option(kit.MDB_TEXT, value[kit.MDB_TEXT]) - m.Render(ice.RENDER_TEMPLATE, m.Conf(SHARE, "meta.template.simple")) + m.RenderTemplate(m.Conf(SHARE, "meta.template.simple")) m.Option(ice.MSG_OUTPUT, ice.RENDER_RESULT) } }) diff --git a/type.go b/type.go index 8b52396d..ae777512 100644 --- a/type.go +++ b/type.go @@ -5,7 +5,6 @@ import ( "fmt" "io" "net/http" - "path" "reflect" "runtime" "sort" @@ -188,11 +187,6 @@ func (c *Context) Merge(s *Context) *Context { v.Meta = kit.Dict() } - if p := kit.Format(v.Meta[kit.MDB_DISPLAY]); p != "" && !strings.HasPrefix(p, "/") { - ls := strings.Split(kit.FileLine(2, 100), "usr") - p = kit.Select(p+".js", p, strings.HasSuffix(p, ".js")) - v.Meta[kit.MDB_DISPLAY] = path.Join("/require/github.com/shylinux", path.Dir(ls[len(ls)-1]), p) - } if p := kit.Format(v.Meta[kit.MDB_STYLE]); p == "" { v.Meta[kit.MDB_STYLE] = k }