mirror of
https://shylinux.com/x/icebergs
synced 2025-04-28 18:22:02 +08:00
opt table.go
This commit is contained in:
parent
1a1a53db00
commit
44d2dfbfd5
@ -4,9 +4,29 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
ice "shylinux.com/x/icebergs"
|
ice "shylinux.com/x/icebergs"
|
||||||
|
"shylinux.com/x/icebergs/base/cli"
|
||||||
kit "shylinux.com/x/toolkits"
|
kit "shylinux.com/x/toolkits"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func _table_run(m *ice.Message, arg ...string) {
|
||||||
|
msg := m.Cmd(arg)
|
||||||
|
|
||||||
|
list := [][]string{}
|
||||||
|
msg.Table(func(index int, value map[string]string, head []string) {
|
||||||
|
if index == 0 {
|
||||||
|
m.Optionv("head", head)
|
||||||
|
}
|
||||||
|
|
||||||
|
line := []string{}
|
||||||
|
for _, h := range head {
|
||||||
|
line = append(line, value[h])
|
||||||
|
}
|
||||||
|
list = append(list, line)
|
||||||
|
})
|
||||||
|
m.Optionv("list", list)
|
||||||
|
|
||||||
|
_wiki_template(m, TABLE, "", "")
|
||||||
|
}
|
||||||
func _table_show(m *ice.Message, text string, arg ...string) {
|
func _table_show(m *ice.Message, text string, arg ...string) {
|
||||||
head, list := []string{}, [][]string{}
|
head, list := []string{}, [][]string{}
|
||||||
for i, v := range kit.Split(strings.TrimSpace(text), ice.NL) {
|
for i, v := range kit.Split(strings.TrimSpace(text), ice.NL) {
|
||||||
@ -35,7 +55,7 @@ func _table_show(m *ice.Message, text string, arg ...string) {
|
|||||||
m.Optionv("head", head)
|
m.Optionv("head", head)
|
||||||
m.Optionv("list", list)
|
m.Optionv("list", list)
|
||||||
|
|
||||||
_wiki_template(m, ORDER, "", text, arg...)
|
_wiki_template(m, TABLE, "", text, arg...)
|
||||||
}
|
}
|
||||||
|
|
||||||
const TABLE = "table"
|
const TABLE = "table"
|
||||||
@ -43,7 +63,11 @@ const TABLE = "table"
|
|||||||
func init() {
|
func init() {
|
||||||
Index.Merge(&ice.Context{
|
Index.Merge(&ice.Context{
|
||||||
Commands: map[string]*ice.Command{
|
Commands: map[string]*ice.Command{
|
||||||
TABLE: {Name: "table `[item item\n]...`", Help: "表格", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
TABLE: {Name: "table `[item item\n]...`", Help: "表格", Action: map[string]*ice.Action{
|
||||||
|
cli.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:]...)
|
_table_show(m, arg[0], arg[1:]...)
|
||||||
}},
|
}},
|
||||||
},
|
},
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package wiki
|
package wiki
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"path"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
ice "shylinux.com/x/icebergs"
|
ice "shylinux.com/x/icebergs"
|
||||||
@ -15,14 +16,14 @@ func _title_deep(str string) int {
|
|||||||
}
|
}
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
func _title_parse(m *ice.Message, root map[string]interface{}, list []string) int {
|
func _title_parse(m *ice.Message, dir string, root map[string]interface{}, list []string) int {
|
||||||
var last map[string]interface{}
|
var last map[string]interface{}
|
||||||
deep := _title_deep(list[0])
|
deep := _title_deep(list[0])
|
||||||
for i := 0; i < len(list); i++ {
|
for i := 0; i < len(list); i++ {
|
||||||
if d := _title_deep(list[i]); d < deep {
|
if d := _title_deep(list[i]); d < deep {
|
||||||
return i
|
return i
|
||||||
} else if d > deep {
|
} else if d > deep {
|
||||||
i += _title_parse(m, last, list[i:]) - 1
|
i += _title_parse(m, dir, last, list[i:]) - 1
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -31,9 +32,11 @@ func _title_parse(m *ice.Message, root map[string]interface{}, list []string) in
|
|||||||
case 0:
|
case 0:
|
||||||
continue
|
continue
|
||||||
case 1:
|
case 1:
|
||||||
case 2:
|
|
||||||
default:
|
default:
|
||||||
|
m.Debug("what %v %v", dir, ls)
|
||||||
|
ls[1] = path.Join(dir, ls[1])
|
||||||
}
|
}
|
||||||
|
|
||||||
meta := kit.Dict(
|
meta := kit.Dict(
|
||||||
"name", kit.Select("", ls, 0),
|
"name", kit.Select("", ls, 0),
|
||||||
"link", kit.Select("", ls, 1),
|
"link", kit.Select("", ls, 1),
|
||||||
@ -52,7 +55,7 @@ func _title_show(m *ice.Message, kind, text string, arg ...string) {
|
|||||||
case NAVMENU: // 导航目录
|
case NAVMENU: // 导航目录
|
||||||
_option(m, kind, "", text, arg...)
|
_option(m, kind, "", text, arg...)
|
||||||
data := kit.Dict("meta", kit.Dict(), "list", kit.List())
|
data := kit.Dict("meta", kit.Dict(), "list", kit.List())
|
||||||
_title_parse(m, data, strings.Split(text, ice.NL))
|
_title_parse(m, path.Dir(m.Option(ice.MSG_SCRIPT)), data, strings.Split(text, ice.NL))
|
||||||
m.RenderTemplate(kit.Format("<div {{.OptionTemplate}} data-data='%s'></div>", kit.Format(data)))
|
m.RenderTemplate(kit.Format("<div {{.OptionTemplate}} data-data='%s'></div>", kit.Format(data)))
|
||||||
return
|
return
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user