forked from x/icebergs
opt wiki
This commit is contained in:
parent
d582280b0a
commit
40d48142b6
@ -11,7 +11,10 @@ func init() { Index.MergeCommands(ice.Commands{RENDER: {Help: "渲染", Actions:
|
||||
|
||||
func RenderAction(arg ...ice.Any) ice.Actions {
|
||||
return ice.MergeActions(ice.Actions{ice.CTX_INIT: AutoConfig(SHORT, TYPE, FIELD, "time,type,name,text", arg),
|
||||
CREATE: {Name: "create type name text", Hand: func(m *ice.Message, arg ...string) { HashCreate(m) }},
|
||||
CREATE: {Name: "create type name text", Hand: func(m *ice.Message, arg ...string) {
|
||||
Config(m, SHORT, TYPE)
|
||||
HashCreate(m)
|
||||
}},
|
||||
SELECT: {Name: "select type name text auto create", Hand: func(m *ice.Message, arg ...string) {
|
||||
if len(arg) < 2 || arg[0] == "" {
|
||||
HashSelect(m, arg...)
|
||||
|
@ -131,7 +131,7 @@ func Template(m templateMessage, p string, arg ...ice.Any) string {
|
||||
return kit.Renders(kit.Format(TemplateText(m, p), arg...), m)
|
||||
}
|
||||
func TemplateText(m templateMessage, p string) string {
|
||||
return m.Cmdx(CAT, path.Join(m.PrefixKey(), path.Base(p)), kit.Dict(DIR_ROOT, ice.SRC_TEMPLATE))
|
||||
return strings.TrimSpace(m.Cmdx(CAT, path.Join(m.PrefixKey(), path.Base(p)), kit.Dict(DIR_ROOT, ice.SRC_TEMPLATE)))
|
||||
}
|
||||
func IsSourceFile(m *ice.Message, ext string) bool {
|
||||
return mdb.Conf(m, Prefix(CAT), kit.Keym(SOURCE, ext)) == ice.TRUE
|
||||
|
@ -96,11 +96,11 @@ func _space_handle(m *ice.Message, safe bool, name string, c *websocket.Conn) {
|
||||
}
|
||||
}
|
||||
func _space_domain(m *ice.Message) (link string) {
|
||||
// m.Options(ice.MSG_OPTION, ice.MSG_USERNAME, ice.MSG_OPTS, ice.MSG_USERNAME)
|
||||
return kit.GetValid(
|
||||
func() string { return ice.Info.Domain },
|
||||
func() string {
|
||||
if dev := kit.Select(ice.DEV, ice.OPS, ice.Info.NodeType == WORKER); mdb.HashSelectDetail(m, dev, nil) {
|
||||
m.Options(ice.MSG_OPTION, ice.MSG_USERNAME, ice.MSG_OPTS, ice.MSG_USERNAME)
|
||||
return m.Cmdv(SPACE, dev, cli.PWD, mdb.LINK)
|
||||
}
|
||||
return ""
|
||||
@ -111,7 +111,7 @@ func _space_domain(m *ice.Message) (link string) {
|
||||
func _space_exec(m *ice.Message, source, target []string, c *websocket.Conn) {
|
||||
switch kit.Select(cli.PWD, m.Detailv(), 0) {
|
||||
case cli.PWD:
|
||||
m.Push(mdb.LINK, m.MergePod(_space_domain(m), kit.Select("", source, -1)))
|
||||
m.Push(mdb.LINK, m.MergePod(kit.Select("", source, -1)))
|
||||
default:
|
||||
kit.If(aaa.Right(m, m.Detailv()), func() { m = m.Cmd() })
|
||||
}
|
||||
|
@ -66,7 +66,7 @@ func _autogen_version(m *ice.Message) string {
|
||||
func _autogen_gits(m *ice.Message, arg ...string) string {
|
||||
res := []string{}
|
||||
kit.For(_autogen_git(m, arg...), func(k, v string) {
|
||||
res = append(res, kit.Format(` %s: "%s",`, kit.LowerCapital(k), strings.TrimSpace(v)))
|
||||
res = append(res, kit.Format(` %s: "%s",`, kit.Capital(k), strings.TrimSpace(v)))
|
||||
})
|
||||
return kit.Join(res, ice.NL)
|
||||
}
|
||||
|
@ -133,7 +133,7 @@ func init() {
|
||||
func PlugAction() ice.Actions {
|
||||
return ice.Actions{
|
||||
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) {
|
||||
kit.For([]string{mdb.PLUGIN, mdb.RENDER, mdb.ENGINE}, func(cmd string) { m.Cmd(cmd, mdb.CREATE, m.CommandKey(), m.PrefixKey()) })
|
||||
kit.For([]string{mdb.PLUGIN, mdb.RENDER, mdb.ENGINE, TEMPLATE, COMPLETE}, func(cmd string) { m.Cmd(cmd, mdb.CREATE, m.CommandKey(), m.PrefixKey()) })
|
||||
LoadPlug(m, m.CommandKey())
|
||||
}},
|
||||
mdb.PLUGIN: {Hand: func(m *ice.Message, arg ...string) { m.Echo(mdb.Config(m, PLUG)) }},
|
||||
|
@ -19,17 +19,13 @@ func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
SHY: {Name: "shy path auto", Help: "笔记", Actions: ice.MergeActions(ice.Actions{
|
||||
mdb.RENDER: {Hand: func(m *ice.Message, arg ...string) {
|
||||
// ctx.ProcessCommand(m, web.WIKI_WORD, kit.Simple(path.Join(arg[2], arg[1])))
|
||||
// ctx.ProcessCommand(m, yac.STACK, kit.Simple(arg[1]))
|
||||
// if ls := kit.Split(arg[1], ice.PS); ls[0] == nfs.SCRIPT {
|
||||
// m.Search(ls[1], func(key string, cmd *ice.Command) { yac.StackHandler(m) })
|
||||
// ctx.ProcessCommand(m, ls[1], kit.Simple())
|
||||
// } else {
|
||||
// ctx.ProcessCommand(m, kit.TrimExt(arg[1], SHY), kit.Simple())
|
||||
// }
|
||||
ctx.ProcessCommand(m, web.WIKI_WORD, kit.Simple(path.Join(arg[2], arg[1])))
|
||||
return
|
||||
ctx.ProcessCommand(m, yac.STACK, kit.Simple(path.Join(arg[2], arg[1])))
|
||||
}},
|
||||
mdb.ENGINE: {Hand: func(m *ice.Message, arg ...string) {
|
||||
ctx.ProcessCommand(m, web.WIKI_WORD, kit.Simple(path.Join(arg[2], arg[1])))
|
||||
return
|
||||
if msg := m.Cmd(yac.STACK, path.Join(arg[2], arg[1])); msg.Option("__index") != "" {
|
||||
ctx.ProcessCommand(m, msg.Option("__index"), kit.Simple())
|
||||
} else {
|
||||
@ -39,6 +35,7 @@ func init() {
|
||||
TEMPLATE: {Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Echo(nfs.Template(m, "demo.shy"), path.Base(path.Dir(path.Join(arg[2], arg[1]))))
|
||||
}},
|
||||
COMPLETE: {Hand: func(m *ice.Message, arg ...string) { m.Cmdy("web.wiki.word", COMPLETE, arg) }},
|
||||
}, PlugAction()), Hand: func(m *ice.Message, arg ...string) {
|
||||
if len(arg) > 0 && kit.Ext(arg[0]) == m.CommandKey() {
|
||||
m.Cmdy(web.WIKI_WORD, path.Join(ice.SRC, strings.TrimPrefix(arg[0], nfs.SRC)))
|
||||
|
@ -2,6 +2,7 @@ package wiki
|
||||
|
||||
import (
|
||||
ice "shylinux.com/x/icebergs"
|
||||
"shylinux.com/x/icebergs/base/ctx"
|
||||
"shylinux.com/x/icebergs/base/nfs"
|
||||
)
|
||||
|
||||
@ -12,8 +13,8 @@ const AUDIO = "audio"
|
||||
|
||||
func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
AUDIO: {Name: "audio url", Help: "音频", Actions: WordAction(
|
||||
`<audio {{.OptionTemplate}} src="{{.Option "text"}}" controls></audio>`, nfs.PATH, ice.USR_LOCAL_IMAGE,
|
||||
), Hand: func(m *ice.Message, arg ...string) { _image_show(m, arg[0], arg[1:]...) }},
|
||||
AUDIO: {Name: "audio url", Help: "音频", Actions: ctx.ConfAction(nfs.PATH, ice.USR_LOCAL_IMAGE), Hand: func(m *ice.Message, arg ...string) {
|
||||
_image_show(m, arg[0], arg[1:]...)
|
||||
}},
|
||||
})
|
||||
}
|
||||
|
@ -8,8 +8,8 @@ const BRIEF = "brief"
|
||||
|
||||
func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
BRIEF: {Name: "brief text", Help: "摘要", Actions: WordAction(
|
||||
`<p {{.OptionTemplate}}>{{.Option "text"}}</p>`,
|
||||
), Hand: func(m *ice.Message, arg ...string) { _wiki_template(m, "", arg[0], arg[1:]...) }},
|
||||
BRIEF: {Name: "brief text", Help: "摘要", Hand: func(m *ice.Message, arg ...string) {
|
||||
_wiki_template(m, "", "", arg[0], arg[1:]...)
|
||||
}},
|
||||
})
|
||||
}
|
||||
|
@ -124,7 +124,7 @@ func _chart_show(m *ice.Message, kind, text string, arg ...string) {
|
||||
m.Option(WIDTH, chart.GetWidth())
|
||||
m.Option(HEIGHT, chart.GetHeight())
|
||||
|
||||
_wiki_template(m, "", text, arg...)
|
||||
_wiki_template(m, "", "", text, arg...)
|
||||
defer m.Echo("</svg>")
|
||||
defer m.RenderResult()
|
||||
chart.Draw(m, 0, 0)
|
||||
@ -156,10 +156,8 @@ const CHART = "chart"
|
||||
|
||||
func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
CHART: {Name: "chart type=label,chain,sequence run text", Help: "图表", Actions: WordAction(
|
||||
`<svg xmlns="http://www.w3.org/2000/svg" vertion="1.1"
|
||||
{{.OptionTemplate}} {{.OptionKV "height,width,font-size,font-family,stroke-width,stroke,fill"}}
|
||||
text-anchor="middle" dominant-baseline="middle">`,
|
||||
), Hand: func(m *ice.Message, arg ...string) { _chart_show(m, arg[0], strings.TrimSpace(arg[1]), arg[2:]...) }},
|
||||
CHART: {Name: "chart type=label,chain,sequence auto text", Help: "图表", Hand: func(m *ice.Message, arg ...string) {
|
||||
_chart_show(m, arg[0], strings.TrimSpace(arg[1]), arg[2:]...)
|
||||
}},
|
||||
})
|
||||
}
|
||||
|
@ -29,25 +29,19 @@ func init() {
|
||||
m.Cmd(nfs.PUSH, path.Join(mdb.Config(m, nfs.PATH), arg[0]), kit.Join(arg[1:], ice.FS)+ice.NL)
|
||||
}}, "draw": {Help: "绘图"},
|
||||
}, WikiAction(ice.USR_LOCAL_EXPORT, nfs.CSV)), Hand: func(m *ice.Message, arg ...string) {
|
||||
if !_wiki_list(m, arg...) {
|
||||
CSV(m, m.Cmdx(nfs.CAT, arg[0])).StatusTimeCount()
|
||||
}
|
||||
kit.If(!_wiki_list(m, arg...), func() { CSV(m, m.Cmdx(nfs.CAT, arg[0])).StatusTimeCount() })
|
||||
}},
|
||||
})
|
||||
}
|
||||
func CSV(m *ice.Message, text string, head ...string) *ice.Message {
|
||||
r := csv.NewReader(bytes.NewBufferString(text))
|
||||
if len(head) == 0 {
|
||||
head, _ = r.Read()
|
||||
}
|
||||
kit.If(len(head) == 0, func() { head, _ = r.Read() })
|
||||
for {
|
||||
line, e := r.Read()
|
||||
if e != nil {
|
||||
break
|
||||
}
|
||||
for i, k := range head {
|
||||
m.Push(k, kit.Select("", line, i))
|
||||
}
|
||||
kit.For(head, func(i int, k string) { m.Push(k, kit.Select("", line, i)) })
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ import (
|
||||
"shylinux.com/x/icebergs/base/ctx"
|
||||
"shylinux.com/x/icebergs/base/mdb"
|
||||
"shylinux.com/x/icebergs/base/nfs"
|
||||
kit "shylinux.com/x/toolkits"
|
||||
)
|
||||
|
||||
const DRAW = "draw"
|
||||
@ -22,9 +23,7 @@ func init() {
|
||||
m.Cmdy(nfs.CAT, path.Join(arg[2], arg[1]))
|
||||
}},
|
||||
}, WikiAction("", nfs.SVG), ctx.CmdAction()), Hand: func(m *ice.Message, arg ...string) {
|
||||
if !_wiki_list(m, arg...) {
|
||||
_wiki_show(m, arg[0])
|
||||
}
|
||||
kit.If(!_wiki_list(m, arg...), func() { _wiki_show(m, arg[0]) })
|
||||
}},
|
||||
})
|
||||
}
|
||||
|
@ -10,10 +10,9 @@ const FEEL = "feel"
|
||||
|
||||
func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
FEEL: {Name: "feel path auto record1 record2 upload prev next actions", Help: "影音媒体", Actions: ice.MergeActions(ice.Actions{
|
||||
"record1": {Name: "record1", Help: "截图"},
|
||||
"record2": {Name: "record2", Help: "录屏"},
|
||||
}, WikiAction(ice.USR_LOCAL_IMAGE, "png|PNG|jpg|JPG|jpeg|mp4|m4v|MOV|webm")), Hand: func(m *ice.Message, arg ...string) {
|
||||
FEEL: {Name: "feel path auto prev next record1 record2 upload actions", Help: "影音媒体", Actions: ice.MergeActions(ice.Actions{
|
||||
"record1": {Help: "截图"}, "record2": {Help: "录屏"},
|
||||
}, WikiAction(ice.USR_LOCAL_IMAGE, "png|PNG|jpg|JPG|jpeg|mp4|m4v|mov|MOV|webm")), Hand: func(m *ice.Message, arg ...string) {
|
||||
_wiki_list(m, kit.Slice(arg, 0, 1)...)
|
||||
ctx.DisplayLocal(m, "")
|
||||
}},
|
||||
|
@ -1,121 +1,41 @@
|
||||
package wiki
|
||||
|
||||
import (
|
||||
"path"
|
||||
"strings"
|
||||
|
||||
ice "shylinux.com/x/icebergs"
|
||||
"shylinux.com/x/icebergs/base/aaa"
|
||||
"shylinux.com/x/icebergs/base/ctx"
|
||||
"shylinux.com/x/icebergs/base/mdb"
|
||||
"shylinux.com/x/icebergs/base/nfs"
|
||||
kit "shylinux.com/x/toolkits"
|
||||
)
|
||||
|
||||
func Parse(m *ice.Message, meta string, key string, arg ...string) (data ice.Any) {
|
||||
list := []string{}
|
||||
for _, line := range kit.SplitLine(strings.Join(arg, ice.SP)) {
|
||||
if strings.HasPrefix(strings.TrimSpace(line), "# ") {
|
||||
continue
|
||||
}
|
||||
list = append(list, kit.SplitWord(line)...)
|
||||
}
|
||||
switch data = kit.Parse(nil, "", list...); meta {
|
||||
case ice.MSG_OPTION:
|
||||
m.Option(key, data)
|
||||
case ice.MSG_APPEND:
|
||||
m.Append(key, data)
|
||||
}
|
||||
return data
|
||||
}
|
||||
func _field_show(m *ice.Message, name, text string, arg ...string) {
|
||||
meta, cmds := kit.Dict(), kit.Split(text)
|
||||
m.Search(cmds[0], func(p *ice.Context, s *ice.Context, key string, cmd *ice.Command) {
|
||||
if meta[FEATURE], meta[INPUTS] = kit.Dict(cmd.Meta), cmd.List; name == "" {
|
||||
name = cmd.Help
|
||||
}
|
||||
meta := kit.Dict()
|
||||
m.Search(text, func(key string, cmd *ice.Command) {
|
||||
meta[mdb.META], meta[mdb.LIST], name = kit.Dict(cmd.Meta), cmd.List, kit.Select(cmd.Help, name)
|
||||
})
|
||||
if len(meta) == 0 || !aaa.Right(m.Spawn(), cmds[0]) {
|
||||
if m.Warn(len(meta) == 0, ice.ErrNotFound, text) || !aaa.Right(m.Spawn(), text) {
|
||||
return
|
||||
}
|
||||
name = strings.Replace(name, ice.SP, "_", -1)
|
||||
meta[mdb.NAME], meta[mdb.INDEX] = name, text
|
||||
msg := m.Spawn()
|
||||
for i := 0; i < len(arg)-1; i += 2 {
|
||||
if strings.HasPrefix(arg[i], "args.") {
|
||||
kit.Value(meta, arg[i], m.Option(arg[i], strings.TrimSpace(arg[i+1])))
|
||||
} else if strings.HasPrefix(arg[i], ARGS) {
|
||||
kit.Value(meta, arg[i], m.Optionv(arg[i], kit.Split(strings.TrimSuffix(strings.TrimPrefix(arg[i+1], "["), "]"))))
|
||||
kit.For(arg, func(k, v string) {
|
||||
if k == ctx.ARGS {
|
||||
kit.Value(meta, k, kit.Split(strings.TrimSuffix(strings.TrimPrefix(v, "["), "]")))
|
||||
} else {
|
||||
kit.Value(meta, arg[i], Parse(m, ice.MSG_OPTION, arg[i], arg[i+1]))
|
||||
kit.Value(meta, k, v)
|
||||
}
|
||||
|
||||
switch arg[i] {
|
||||
case ARGS:
|
||||
count := 0
|
||||
kit.For(meta[INPUTS], func(index int, value ice.Map) {
|
||||
if value[mdb.TYPE] != "button" {
|
||||
count++
|
||||
}
|
||||
})
|
||||
if args := kit.Simple(m.Optionv(arg[i])); len(args) > count {
|
||||
list := meta[INPUTS].([]ice.Any)
|
||||
for i := count; i < len(args); i++ {
|
||||
list = append(list, kit.Dict(mdb.TYPE, "text", mdb.NAME, ARGS, mdb.VALUE, args[i]))
|
||||
}
|
||||
meta[INPUTS] = list
|
||||
}
|
||||
case TABLE:
|
||||
ls := kit.SplitLine(arg[i+1])
|
||||
head := kit.SplitWord(ls[0])
|
||||
for _, l := range ls[1:] {
|
||||
for i, v := range kit.SplitWord(l) {
|
||||
msg.Push(head[i], v)
|
||||
}
|
||||
}
|
||||
kit.Value(meta, "msg", msg.FormatMeta(), kit.Keys(FEATURE, "mode"), "simple")
|
||||
case SPARK:
|
||||
if arg[i+1][0] == '@' && nfs.Exists(m, arg[i+1][1:]) {
|
||||
msg.Cmdy(nfs.CAT, arg[i+1][1:])
|
||||
} else {
|
||||
msg.Echo(strings.TrimSpace(arg[i+1]))
|
||||
}
|
||||
kit.Value(meta, "msg", msg.FormatMeta(), kit.Keys(FEATURE, "mode"), "simple")
|
||||
if text == "web.code.inner" {
|
||||
kit.Value(meta, kit.Keys(FEATURE, ctx.DISPLAY), "/plugin/local/code/inner.js")
|
||||
kit.Value(meta, "plug", kit.UnMarshal(m.Cmdx(mdb.PLUGIN, kit.Ext(name))))
|
||||
kit.Value(meta, ARGS, kit.List(path.Dir(name)+ice.PS, path.Base(name)))
|
||||
}
|
||||
default:
|
||||
kit.Value(meta, kit.Keys(FEATURE, arg[i]), msg.Optionv(arg[i], arg[i+1]))
|
||||
}
|
||||
}
|
||||
m.Option(mdb.META, meta)
|
||||
_wiki_template(m, name, text)
|
||||
})
|
||||
meta[mdb.NAME], meta[mdb.INDEX] = name, text
|
||||
_wiki_template(m.Options(mdb.META, kit.Format(meta)), "", name, text)
|
||||
}
|
||||
|
||||
const (
|
||||
FEATURE = "feature"
|
||||
INPUTS = "inputs"
|
||||
ARGS = "args"
|
||||
)
|
||||
const FIELD = "field"
|
||||
|
||||
func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
FIELD: {Name: "field [name] cmd", Help: "插件", Actions: ice.MergeActions(WordAction(`<fieldset {{.OptionTemplate}}" data-meta='{{.Optionv "meta"|Format}}'>
|
||||
<legend>{{.Option "name"}}</legend>
|
||||
<form class="option"></form>
|
||||
<div class="action"></div>
|
||||
<div class="output"></div>
|
||||
<div class="status"></div>
|
||||
</fieldset>`), ctx.CmdAction()), Hand: func(m *ice.Message, arg ...string) {
|
||||
if kit.Select("", arg, 1) == ctx.ARGS {
|
||||
arg = kit.Simple("", arg)
|
||||
}
|
||||
if arg = _name(m, arg); strings.Contains(arg[1], ice.NL) {
|
||||
arg = kit.Simple(arg[0], "web.chat.div", "auto.cmd", "split", "opts.text", arg[1], arg[2:])
|
||||
}
|
||||
FIELD: {Name: "field name cmd", Help: "插件", Actions: ctx.CmdAction(), Hand: func(m *ice.Message, arg ...string) {
|
||||
kit.If(kit.Select("", arg, 1) == ctx.ARGS, func() { arg = kit.Simple("", arg) })
|
||||
arg = _name(m, arg)
|
||||
_field_show(m, arg[0], arg[1], arg[2:]...)
|
||||
}},
|
||||
})
|
||||
|
@ -2,11 +2,12 @@ package wiki
|
||||
|
||||
import (
|
||||
ice "shylinux.com/x/icebergs"
|
||||
"shylinux.com/x/icebergs/base/ctx"
|
||||
"shylinux.com/x/icebergs/base/nfs"
|
||||
)
|
||||
|
||||
func _image_show(m *ice.Message, text string, arg ...string) {
|
||||
_wiki_template(m, "", _wiki_link(m, text), arg...)
|
||||
_wiki_template(m, "", "", _wiki_link(m, text), arg...)
|
||||
}
|
||||
|
||||
const (
|
||||
@ -19,8 +20,8 @@ const IMAGE = "image"
|
||||
|
||||
func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
IMAGE: {Name: "image url run", Help: "图片", Actions: WordAction(
|
||||
`<img {{.OptionTemplate}} title="{{.Option "text"}}" src="{{.Option "text"}}">`, nfs.PATH, ice.USR_LOCAL_IMAGE,
|
||||
), Hand: func(m *ice.Message, arg ...string) { _image_show(m, arg[0], arg[1:]...) }},
|
||||
IMAGE: {Name: "image path auto", Help: "图片", Actions: ice.MergeActions(ctx.ConfAction(nfs.PATH, ice.USR_LOCAL_IMAGE)), Hand: func(m *ice.Message, arg ...string) {
|
||||
_image_show(m, arg[0], arg[1:]...)
|
||||
}},
|
||||
})
|
||||
}
|
||||
|
@ -7,16 +7,15 @@ import (
|
||||
)
|
||||
|
||||
func _order_show(m *ice.Message, text string, arg ...string) {
|
||||
m.Optionv(mdb.LIST, kit.SplitLine(text))
|
||||
_wiki_template(m, "", text, arg...)
|
||||
_wiki_template(m.Options(mdb.LIST, kit.SplitLine(text)), "", "", text, arg...)
|
||||
}
|
||||
|
||||
const ORDER = "order"
|
||||
|
||||
func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
ORDER: {Name: "order text", Help: "列表", Actions: WordAction(
|
||||
`<ul {{.OptionTemplate}}>{{range $index, $value := .Optionv "list"}}<li>{{$value}}</li>{{end}}</ul>`,
|
||||
), Hand: func(m *ice.Message, arg ...string) { _order_show(m, arg[0], arg[1:]...) }},
|
||||
ORDER: {Name: "order text", Help: "列表", Hand: func(m *ice.Message, arg ...string) {
|
||||
_order_show(m, arg[0], arg[1:]...)
|
||||
}},
|
||||
})
|
||||
}
|
||||
|
@ -3,7 +3,6 @@ package wiki
|
||||
import (
|
||||
"encoding/base64"
|
||||
"encoding/hex"
|
||||
"net/url"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
@ -39,36 +38,27 @@ func init() {
|
||||
}
|
||||
}
|
||||
switch m.OptionFields(mdb.DETAIL); arg[0] {
|
||||
case "base64":
|
||||
if buf, err := base64.StdEncoding.DecodeString(arg[1]); err == nil {
|
||||
m.Echo(hex.EncodeToString(buf))
|
||||
}
|
||||
case nfs.JSON:
|
||||
m.Echo(kit.Formats(kit.UnMarshal(arg[1])))
|
||||
ctx.DisplayStoryJSON(m)
|
||||
case web.HTTP:
|
||||
u, _ := url.Parse(arg[1])
|
||||
m.Push(tcp.PROTO, u.Scheme)
|
||||
m.Push(tcp.HOST, u.Host)
|
||||
m.Push(nfs.PATH, u.Path)
|
||||
for k, v := range u.Query() {
|
||||
for _, v := range v {
|
||||
m.Push(k, v)
|
||||
}
|
||||
}
|
||||
u := kit.ParseURL(arg[1])
|
||||
m.Push(tcp.PROTO, u.Scheme).Push(tcp.HOST, u.Host).Push(nfs.PATH, u.Path)
|
||||
kit.For(u, func(k string, v []string) { m.Push(k, v) })
|
||||
m.EchoQRCode(arg[1])
|
||||
case web.FORM:
|
||||
for _, v := range strings.Split(arg[1], "&") {
|
||||
ls := strings.Split(v, ice.EQ)
|
||||
m.Push(kit.QueryUnescape(ls[0]), kit.QueryUnescape(kit.Select("", ls, 1)))
|
||||
}
|
||||
kit.SplitKV("=", "&", arg[1], func(k string, v []string) {
|
||||
kit.For(v, func(v string) { m.Push(kit.QueryUnescape(k), kit.QueryUnescape(v)) })
|
||||
})
|
||||
case mdb.TIME:
|
||||
if i, e := strconv.ParseInt(arg[1], 10, 64); e == nil {
|
||||
m.Echo(time.Unix(i, 0).Format(ice.MOD_TIME))
|
||||
}
|
||||
case mdb.LIST:
|
||||
for i, v := range kit.Split(arg[1]) {
|
||||
m.Push(kit.Format(i), v)
|
||||
kit.For(kit.Split(arg[1]), func(i int, v string) { m.Push(kit.Format(i), v) })
|
||||
case "base64":
|
||||
if buf, err := base64.StdEncoding.DecodeString(arg[1]); err == nil {
|
||||
m.Echo(hex.EncodeToString(buf))
|
||||
}
|
||||
}
|
||||
}},
|
||||
|
@ -2,6 +2,7 @@ package wiki
|
||||
|
||||
import (
|
||||
"path"
|
||||
"strings"
|
||||
|
||||
ice "shylinux.com/x/icebergs"
|
||||
"shylinux.com/x/icebergs/base/mdb"
|
||||
@ -13,25 +14,20 @@ func _refer_show(m *ice.Message, text string, arg ...string) {
|
||||
for _, v := range kit.SplitLine(text) {
|
||||
if ls := kit.SplitWord(v); len(ls) == 1 {
|
||||
p := kit.QueryUnescape(ls[0])
|
||||
list = append(list, []string{kit.Select(ls[0], path.Base(p)), ls[0], p})
|
||||
list = append(list, []string{kit.Select(ls[0], path.Base(strings.Split(p, ice.QS)[0])), ls[0], p})
|
||||
} else {
|
||||
list = append(list, append(ls, kit.QueryUnescape(ls[1])))
|
||||
}
|
||||
}
|
||||
m.Optionv(mdb.LIST, list)
|
||||
_wiki_template(m, "", text, arg...)
|
||||
_wiki_template(m.Options(mdb.LIST, list), "", "", text, arg...)
|
||||
}
|
||||
|
||||
const REFER = "refer"
|
||||
|
||||
func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
REFER: {Name: "refer text", Help: "参考", Actions: WordAction(
|
||||
`<ul {{.OptionTemplate}}>{{range $index, $value := .Optionv "list"}}<li>{{index $value 0}}: <a href="{{index $value 1}}" data-name="{{index $value 0}}" target="_blank">{{index $value 2}}</a></li>{{end}}</ul>`,
|
||||
), Hand: func(m *ice.Message, arg ...string) {
|
||||
if len(arg) > 1 {
|
||||
_refer_show(m, arg[0], arg[1:]...)
|
||||
}
|
||||
REFER: {Name: "refer text", Help: "参考", Hand: func(m *ice.Message, arg ...string) {
|
||||
_refer_show(m, arg[0], arg[1:]...)
|
||||
}},
|
||||
})
|
||||
}
|
||||
|
@ -6,104 +6,63 @@ import (
|
||||
ice "shylinux.com/x/icebergs"
|
||||
"shylinux.com/x/icebergs/base/mdb"
|
||||
"shylinux.com/x/icebergs/base/nfs"
|
||||
"shylinux.com/x/icebergs/base/ssh"
|
||||
kit "shylinux.com/x/toolkits"
|
||||
)
|
||||
|
||||
func _spark_show(m *ice.Message, name, text string, arg ...string) *ice.Message {
|
||||
if _option(m, m.CommandKey(), name, text, arg...); name == "" {
|
||||
return _wiki_template(m, name, text, arg...)
|
||||
}
|
||||
m.Echo(`<div class="story" data-type="spark" data-name="%s" style="%s">`, name, m.Option("style"))
|
||||
defer m.Echo("</div>")
|
||||
switch name {
|
||||
case "inner", FIELD:
|
||||
return m.Echo(text)
|
||||
}
|
||||
prompt := kit.Select(name+"> ", mdb.Config(m, kit.Keys(ssh.PROMPT, name)))
|
||||
for _, l := range kit.SplitLine(text) {
|
||||
m.Echo(Format("div", Format("label", prompt), Format("span", l)))
|
||||
func _spark_md(m *ice.Message, arg ...string) *ice.Message {
|
||||
block, code := "", []string{}
|
||||
text := func() {
|
||||
if len(code) > 0 {
|
||||
m.Cmdy(SPARK, kit.Join(code, ice.NL))
|
||||
code = []string{}
|
||||
}
|
||||
}
|
||||
m.Cmd(nfs.CAT, arg[0], func(line string) {
|
||||
for _, ls := range [][]string{[]string{"# ", TITLE}, []string{"## ", TITLE, CHAPTER}, []string{"### ", TITLE, SECTION}} {
|
||||
if strings.HasPrefix(line, ls[0]) {
|
||||
text()
|
||||
m.Cmdy(ls[1:], strings.TrimPrefix(line, ls[0]))
|
||||
return
|
||||
}
|
||||
}
|
||||
if strings.HasPrefix(line, "```") {
|
||||
if block == "" {
|
||||
text()
|
||||
block = "```"
|
||||
} else {
|
||||
m.Cmdy(SPARK, SHELL, kit.Join(code, ice.NL))
|
||||
block, code = "", []string{}
|
||||
}
|
||||
return
|
||||
}
|
||||
code = append(code, line)
|
||||
})
|
||||
text()
|
||||
return m
|
||||
}
|
||||
func _spark_show(m *ice.Message, name, text string, arg ...string) *ice.Message {
|
||||
return _wiki_template(m.Options(mdb.LIST, kit.SplitLine(text)), name, name, text, arg...)
|
||||
}
|
||||
|
||||
const (
|
||||
PROMPT = "prompt"
|
||||
BREAK = "break"
|
||||
SHELL = "shell"
|
||||
SHELL = "shell"
|
||||
)
|
||||
|
||||
const SPARK = "spark"
|
||||
|
||||
func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
SPARK: {Name: "spark [name] text auto field:text value:text", Help: "段落", Actions: ice.MergeActions(ice.Actions{
|
||||
SPARK: {Name: "spark type=inner,shell,redis,mysql text", Help: "段落", Actions: ice.MergeActions(ice.Actions{
|
||||
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) {
|
||||
ice.AddRender(ice.RENDER_SCRIPT, func(m *ice.Message, args ...ice.Any) string {
|
||||
arg := kit.Simple(args...)
|
||||
if m.IsCliUA() {
|
||||
if len(arg) > 1 {
|
||||
arg = arg[1:]
|
||||
}
|
||||
return strings.Join(arg, ice.NL)
|
||||
}
|
||||
if len(arg) == 1 && arg[0] != BREAK {
|
||||
arg = []string{SHELL, arg[0]}
|
||||
}
|
||||
list := []string{kit.Format(`<div class="story" data-type="spark" data-name="%s">`, arg[0])}
|
||||
for _, l := range kit.SplitLine(strings.Join(arg[1:], ice.NL)) {
|
||||
list = append(list, Format("div", Format("label", kit.Select("> ", "$ ", arg[0] == SHELL)), Format("span", l)))
|
||||
}
|
||||
return strings.Join(append(list, "</div>"), "")
|
||||
})
|
||||
ice.AddRender(ice.RENDER_SCRIPT, func(msg *ice.Message, args ...ice.Any) string { return m.Cmdx(SPARK, SHELL, args) })
|
||||
}},
|
||||
"md": {Name: "md file", Help: "md", Hand: func(m *ice.Message, arg ...string) {
|
||||
block, code := "", []string{}
|
||||
text := func() {
|
||||
if len(code) > 0 {
|
||||
m.Cmdy(SPARK, kit.Join(code, ice.NL))
|
||||
code = []string{}
|
||||
}
|
||||
}
|
||||
m.Cmd(nfs.CAT, m.Option(nfs.FILE), func(line string) {
|
||||
for _, ls := range [][]string{
|
||||
[]string{"# ", TITLE}, []string{"## ", TITLE, CHAPTER}, []string{"### ", TITLE, SECTION},
|
||||
} {
|
||||
if strings.HasPrefix(line, ls[0]) {
|
||||
text()
|
||||
m.Cmdy(ls[1:], strings.TrimPrefix(line, ls[0]))
|
||||
return
|
||||
}
|
||||
}
|
||||
if strings.HasPrefix(line, "```") {
|
||||
if block == "" {
|
||||
text()
|
||||
block = "```"
|
||||
} else {
|
||||
m.Cmdy(SPARK, SHELL, kit.Join(code, ice.NL))
|
||||
block, code = "", []string{}
|
||||
}
|
||||
return
|
||||
}
|
||||
code = append(code, line)
|
||||
})
|
||||
text()
|
||||
}},
|
||||
}, WordAction(`<p {{.OptionTemplate}}>{{.Option "text"}}</p>`, ssh.PROMPT, kit.Dict(SHELL, "$ "))), Hand: func(m *ice.Message, arg ...string) {
|
||||
if len(arg) == 0 {
|
||||
m.Echo(`<br class="story" data-type="spark">`)
|
||||
} else if kit.Ext(arg[0]) == "md" {
|
||||
m.Cmdy(SPARK, "md", arg)
|
||||
}), Hand: func(m *ice.Message, arg ...string) {
|
||||
if kit.Ext(arg[0]) == "md" {
|
||||
_spark_md(m, arg...)
|
||||
} else {
|
||||
if arg[0] == "shell" && arg[1] == "inner" {
|
||||
arg = arg[1:]
|
||||
}
|
||||
arg = _name(m, arg)
|
||||
_spark_show(m, arg[0], strings.TrimSpace(arg[1]), arg[2:]...)
|
||||
}
|
||||
}},
|
||||
})
|
||||
}
|
||||
func Format(tag string, arg ...ice.Any) string {
|
||||
return kit.Format("<%s>%s</%s>", tag, strings.Join(kit.Simple(arg), ""), tag)
|
||||
}
|
||||
|
@ -8,20 +8,14 @@ import (
|
||||
)
|
||||
|
||||
func _table_run(m *ice.Message, arg ...string) {
|
||||
msg := m.Cmd(arg)
|
||||
list := [][]string{}
|
||||
msg.Table(func(index int, value ice.Maps, head []string) {
|
||||
if index == 0 {
|
||||
m.Optionv("head", head)
|
||||
}
|
||||
m.Cmd(arg).Table(func(index int, value ice.Maps, head []string) {
|
||||
kit.If(index == 0, func() { m.Optionv("head", head) })
|
||||
line := []string{}
|
||||
for _, h := range head {
|
||||
line = append(line, value[h])
|
||||
}
|
||||
kit.For(head, func(h string) { line = append(line, value[h]) })
|
||||
list = append(list, line)
|
||||
})
|
||||
m.Optionv("list", list)
|
||||
_wiki_template(m, "", "")
|
||||
_wiki_template(m.Options("list", list), "", "", "")
|
||||
}
|
||||
func _table_show(m *ice.Message, text string, arg ...string) {
|
||||
head, list := []string{}, [][]string{}
|
||||
@ -30,22 +24,14 @@ func _table_show(m *ice.Message, text string, arg ...string) {
|
||||
head = kit.SplitWord(line)
|
||||
continue
|
||||
}
|
||||
list = append(list, transList(kit.SplitWord(line), func(value string) string {
|
||||
list = append(list, kit.Simple(kit.SplitWord(line), func(value string) string {
|
||||
if ls := kit.SplitWord(value); len(ls) > 1 {
|
||||
return kit.Format(`<span style="%s">%s</span>`, kit.JoinKV(":", ";", transArgKey(ls[1:])...), ls[0])
|
||||
}
|
||||
return value
|
||||
}))
|
||||
}
|
||||
m.Optionv("head", head)
|
||||
m.Optionv("list", list)
|
||||
_wiki_template(m, "", text, arg...)
|
||||
}
|
||||
func transList(arg []string, cb func(string) string) []string {
|
||||
for i, v := range arg {
|
||||
arg[i] = cb(v)
|
||||
}
|
||||
return arg
|
||||
_wiki_template(m.Options("head", head, "list", list), "", "", text, arg...)
|
||||
}
|
||||
func transArgKey(arg []string) []string {
|
||||
for i := 0; i < len(arg)-1; i += 2 {
|
||||
@ -65,9 +51,6 @@ func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
TABLE: {Name: "table text", Help: "表格", Actions: ice.MergeActions(ice.Actions{
|
||||
ice.RUN: {Hand: func(m *ice.Message, arg ...string) { _table_run(m, arg...) }},
|
||||
}, WordAction(`<table {{.OptionTemplate}}>
|
||||
<tr>{{range $i, $v := .Optionv "head"}}<th>{{$v}}</th>{{end}}</tr>
|
||||
{{range $index, $value := .Optionv "list"}}<tr>{{range $i, $v := $value}}<td>{{$v}}</td>{{end}}</tr>{{end}}
|
||||
</table>`)), Hand: func(m *ice.Message, arg ...string) { _table_show(m, arg[0], arg[1:]...) }},
|
||||
}), Hand: func(m *ice.Message, arg ...string) { _table_show(m, arg[0], arg[1:]...) }},
|
||||
})
|
||||
}
|
||||
|
@ -7,48 +7,38 @@ import (
|
||||
"shylinux.com/x/icebergs/base/lex"
|
||||
"shylinux.com/x/icebergs/base/mdb"
|
||||
"shylinux.com/x/icebergs/base/nfs"
|
||||
"shylinux.com/x/icebergs/base/web"
|
||||
kit "shylinux.com/x/toolkits"
|
||||
)
|
||||
|
||||
func _title_parse(m *ice.Message, dir string, text string) string {
|
||||
func _title_parse(m *ice.Message, text string) string {
|
||||
return m.Cmdx(lex.SPLIT, "", "name,link", kit.Dict(nfs.CAT_CONTENT, text), func(ls []string) []string {
|
||||
if len(ls) > 1 {
|
||||
ls[1] = path.Join(dir, ls[1])
|
||||
}
|
||||
kit.If(!kit.HasPrefix(ls[1], nfs.PS, web.HTTP), func() { ls[1] = path.Join(path.Dir(m.Option(ice.MSG_SCRIPT)), ls[1]) })
|
||||
return ls
|
||||
})
|
||||
}
|
||||
func _title_menu(m *ice.Message, kind, text string, arg ...string) *ice.Message {
|
||||
if kind == NAVMENU {
|
||||
m.Option(mdb.DATA, _title_parse(m, path.Dir(m.Option(ice.MSG_SCRIPT)), text))
|
||||
}
|
||||
return _option(m, kind, "", text, arg...).RenderTemplate(mdb.Config(m, kind), &Message{m})
|
||||
func _title_menu(m *ice.Message, name, text string, arg ...string) *ice.Message {
|
||||
m.Options(mdb.DATA, _title_parse(m, text))
|
||||
return _wiki_template(m, name, name, text, arg...)
|
||||
}
|
||||
func _title_show(m *ice.Message, kind, text string, arg ...string) *ice.Message {
|
||||
switch title, _ := m.Optionv(TITLE).(map[string]int); kind {
|
||||
func _title_show(m *ice.Message, name, text string, arg ...string) *ice.Message {
|
||||
switch title, _ := m.Optionv(TITLE).(map[string]int); name {
|
||||
case SECTION:
|
||||
title[SECTION]++
|
||||
m.Option(LEVEL, "h3")
|
||||
m.Option(PREFIX, kit.Format("%d.%d ", title[CHAPTER], title[SECTION]))
|
||||
m.Options(LEVEL, "h3", PREFIX, kit.Format("%d.%d ", title[CHAPTER], title[SECTION]))
|
||||
case CHAPTER:
|
||||
title[CHAPTER]++
|
||||
title[SECTION] = 0
|
||||
m.Option(LEVEL, "h2")
|
||||
m.Option(PREFIX, kit.Format("%d ", title[CHAPTER]))
|
||||
m.Options(LEVEL, "h2", PREFIX, kit.Format("%d ", title[CHAPTER]))
|
||||
default:
|
||||
m.Option(LEVEL, "h1")
|
||||
m.Option(PREFIX, "")
|
||||
m.Options(LEVEL, "h1", PREFIX, "")
|
||||
}
|
||||
_wiki_template(m, "", text, arg...)
|
||||
menu, _ := m.Optionv(MENU).(ice.Map)
|
||||
menu[mdb.LIST] = append(menu[mdb.LIST].([]ice.Any), kit.Dict(m.OptionSimple("level,prefix,text")))
|
||||
return m
|
||||
return _wiki_template(m, "", name, text, arg...)
|
||||
}
|
||||
|
||||
const (
|
||||
PREFIX = "prefix"
|
||||
LEVEL = "level"
|
||||
MENU = "menu"
|
||||
PREFIX = "prefix"
|
||||
)
|
||||
const (
|
||||
NAVMENU = "navmenu"
|
||||
@ -61,21 +51,15 @@ const TITLE = "title"
|
||||
|
||||
func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
TITLE: {Name: "title [navmenu|premenu|chapter|section|endmenu] text", Actions: WordAction(
|
||||
`<{{.Option "level"}} {{.OptionTemplate}}>{{.Option "prefix"}} {{.Option "text"}}</{{.Option "level"}}>`,
|
||||
NAVMENU, `<div {{.OptionTemplate}} data-data='{{.Option "data"}}'></div>`,
|
||||
PREMENU, `<ul {{.OptionTemplate}}></ul>`,
|
||||
ENDMENU, `<ul {{.OptionTemplate}}>{{$menu := .Optionv "menu"}}
|
||||
{{range $index, $value := Value $menu "list"}}<li>{{Value $value "prefix"}} {{Value $value "text"}}</li>{{end}}
|
||||
</ul>`), Help: "标题", Hand: func(m *ice.Message, arg ...string) {
|
||||
TITLE: {Name: "title type=navmenu,premenu,chapter,section,endmenu text", Help: "标题", Hand: func(m *ice.Message, arg ...string) {
|
||||
switch arg[0] {
|
||||
case NAVMENU:
|
||||
case NAVMENU: // navmenu text arg...
|
||||
_title_menu(m, arg[0], arg[1], arg[2:]...)
|
||||
case PREMENU, ENDMENU:
|
||||
case PREMENU, ENDMENU: // premenu arg...
|
||||
_title_menu(m, arg[0], "", arg[1:]...)
|
||||
case CHAPTER, SECTION:
|
||||
case CHAPTER, SECTION: // chapter text arg...
|
||||
_title_show(m, arg[0], arg[1], arg[2:]...)
|
||||
default:
|
||||
default: // title text arg...
|
||||
_title_show(m, "", arg[0], arg[1:]...)
|
||||
}
|
||||
}},
|
||||
|
@ -2,6 +2,7 @@ package wiki
|
||||
|
||||
import (
|
||||
ice "shylinux.com/x/icebergs"
|
||||
"shylinux.com/x/icebergs/base/ctx"
|
||||
"shylinux.com/x/icebergs/base/nfs"
|
||||
)
|
||||
|
||||
@ -14,8 +15,8 @@ const VIDEO = "video"
|
||||
|
||||
func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
VIDEO: {Name: "video url run", Help: "视频", Actions: WordAction(
|
||||
`<video {{.OptionTemplate}} title="{{.Option "text"}}" src="{{.Option "text"}}" controls></video>`, nfs.PATH, ice.USR_LOCAL_IMAGE,
|
||||
), Hand: func(m *ice.Message, arg ...string) { _image_show(m, arg[0], arg[1:]...) }},
|
||||
VIDEO: {Name: "video url run", Help: "视频", Actions: ice.MergeActions(ctx.ConfAction(nfs.PATH, ice.USR_LOCAL_IMAGE)), Hand: func(m *ice.Message, arg ...string) {
|
||||
_image_show(m, arg[0], arg[1:]...)
|
||||
}},
|
||||
})
|
||||
}
|
||||
|
@ -14,45 +14,31 @@ import (
|
||||
)
|
||||
|
||||
func _name(m *ice.Message, arg []string) []string {
|
||||
if len(arg) == 1 {
|
||||
return []string{"", arg[0]}
|
||||
}
|
||||
kit.If(len(arg) == 1, func() { arg = []string{"", arg[0]} })
|
||||
return arg
|
||||
}
|
||||
func _option(m *ice.Message, kind, name, text string, arg ...string) *ice.Message {
|
||||
m.Option(mdb.TYPE, kind)
|
||||
m.Option(mdb.NAME, name)
|
||||
m.Option(mdb.TEXT, text)
|
||||
|
||||
extra := kit.Dict()
|
||||
m.Optionv(mdb.EXTRA, extra)
|
||||
for i := 0; i < len(arg)-1; i += 2 {
|
||||
extra[arg[i]] = kit.Format(kit.Parse(nil, "", kit.Split(arg[i+1])...))
|
||||
}
|
||||
return m
|
||||
kit.For(arg, func(k, v string) { extra[k] = kit.Format(kit.Parse(nil, "", kit.Split(v)...)) })
|
||||
return m.Options(mdb.TYPE, kind, mdb.NAME, name, mdb.TEXT, text, mdb.EXTRA, extra)
|
||||
}
|
||||
|
||||
func _wiki_path(m *ice.Message, arg ...string) string {
|
||||
return path.Join(mdb.Config(m, nfs.PATH), path.Join(arg...))
|
||||
}
|
||||
func _wiki_link(m *ice.Message, text string) string {
|
||||
if !kit.HasPrefix(text, ice.PS, ice.HTTP) {
|
||||
text = path.Join(web.SHARE_LOCAL, _wiki_path(m, text))
|
||||
}
|
||||
kit.If(!kit.HasPrefix(text, ice.PS, ice.HTTP), func() { text = path.Join(web.SHARE_LOCAL, _wiki_path(m, text)) })
|
||||
return text
|
||||
}
|
||||
func _wiki_list(m *ice.Message, arg ...string) bool {
|
||||
if m.Option(nfs.DIR_ROOT, _wiki_path(m)); len(arg) == 0 || kit.HasSuffix(arg[0], ice.PS) {
|
||||
if m.Option(nfs.DIR_DEEP) != ice.TRUE {
|
||||
m.Cmdy(nfs.DIR, kit.Slice(arg, 0, 1), kit.Dict(nfs.DIR_TYPE, nfs.DIR))
|
||||
}
|
||||
kit.If(m.Option(nfs.DIR_DEEP) != ice.TRUE, func() { m.Cmdy(nfs.DIR, kit.Slice(arg, 0, 1), kit.Dict(nfs.DIR_TYPE, nfs.DIR)) })
|
||||
m.Cmdy(nfs.DIR, kit.Slice(arg, 0, 1), kit.Dict(nfs.DIR_TYPE, nfs.CAT, nfs.DIR_REG, mdb.Config(m, lex.REGEXP)))
|
||||
m.StatusTimeCount()
|
||||
m.SortStrR(mdb.TIME)
|
||||
m.SortStrR(mdb.TIME).StatusTimeCount()
|
||||
return true
|
||||
} else {
|
||||
ctx.DisplayLocal(m, path.Join(kit.PathName(2), kit.Keys(kit.FileName(2), nfs.JS)))
|
||||
return false
|
||||
}
|
||||
ctx.DisplayLocal(m, path.Join(kit.PathName(2), kit.Keys(kit.FileName(2), ice.JS)))
|
||||
return false
|
||||
}
|
||||
func _wiki_show(m *ice.Message, name string, arg ...string) {
|
||||
m.Cmdy(nfs.CAT, name, kit.Dict(nfs.DIR_ROOT, _wiki_path(m)))
|
||||
@ -63,8 +49,8 @@ func _wiki_save(m *ice.Message, name, text string, arg ...string) {
|
||||
func _wiki_upload(m *ice.Message, dir string) {
|
||||
m.Cmdy(web.CACHE, web.WATCH, m.Option(ice.MSG_UPLOAD), _wiki_path(m, dir, m.Option(mdb.NAME)))
|
||||
}
|
||||
func _wiki_template(m *ice.Message, name, text string, arg ...string) *ice.Message {
|
||||
return _option(m, m.CommandKey(), name, strings.TrimSpace(text), arg...).RenderTemplate(mdb.Config(m, nfs.TEMPLATE), &Message{m})
|
||||
func _wiki_template(m *ice.Message, file, name, text string, arg ...string) *ice.Message {
|
||||
return m.Echo(nfs.Template(&Message{_option(m, m.CommandKey(), name, strings.TrimSpace(text), arg...)}, kit.Keys(kit.Select(m.CommandKey(), file), nfs.HTML)))
|
||||
}
|
||||
|
||||
const WIKI = "wiki"
|
||||
@ -73,9 +59,9 @@ var Index = &ice.Context{Name: WIKI, Help: "文档中心"}
|
||||
|
||||
func init() {
|
||||
web.Index.Register(Index, &web.Frame{},
|
||||
TITLE, BRIEF, REFER, SPARK, FIELD, PARSE,
|
||||
TITLE, BRIEF, REFER, SPARK, PARSE, FIELD,
|
||||
ORDER, TABLE, CHART, IMAGE, VIDEO, AUDIO,
|
||||
FEEL, DRAW, DATA, WORD,
|
||||
WORD, DATA, DRAW, FEEL,
|
||||
)
|
||||
}
|
||||
func Prefix(arg ...string) string { return web.Prefix(WIKI, kit.Keys(arg)) }
|
||||
@ -83,8 +69,10 @@ func Prefix(arg ...string) string { return web.Prefix(WIKI, kit.Keys(arg)) }
|
||||
func WikiAction(dir string, ext ...string) ice.Actions {
|
||||
return ice.Actions{ice.CTX_INIT: mdb.AutoConfig(nfs.PATH, dir, lex.REGEXP, kit.ExtReg(ext...)),
|
||||
web.UPLOAD: {Hand: func(m *ice.Message, arg ...string) { _wiki_upload(m, m.Option(nfs.PATH)) }},
|
||||
nfs.TRASH: {Name: "trash path*", Hand: func(m *ice.Message, arg ...string) { nfs.Trash(m, _wiki_path(m, m.Option(nfs.PATH))) }},
|
||||
nfs.SAVE: {Name: "save path* text", Hand: func(m *ice.Message, arg ...string) { _wiki_save(m, m.Option(nfs.PATH), m.Option(mdb.TEXT)) }},
|
||||
nfs.TRASH: {Hand: func(m *ice.Message, arg ...string) {
|
||||
nfs.Trash(m, _wiki_path(m, kit.Select("some", kit.Select(m.Option(nfs.PATH), arg, 0))))
|
||||
}},
|
||||
nfs.SAVE: {Hand: func(m *ice.Message, arg ...string) { _wiki_save(m, m.Option(nfs.PATH), m.Option(mdb.TEXT)) }},
|
||||
mdb.INPUTS: {Hand: func(m *ice.Message, arg ...string) {
|
||||
switch arg[0] {
|
||||
case nfs.PATH:
|
||||
@ -102,36 +90,17 @@ type Message struct{ *ice.Message }
|
||||
func (m *Message) OptionTemplate() string {
|
||||
res := []string{`class="story"`}
|
||||
add := func(pre, key string) {
|
||||
if m.Option(key) != "" {
|
||||
res = append(res, kit.Format(`%s%s="%s"`, pre, key, m.Option(key)))
|
||||
}
|
||||
}
|
||||
for _, key := range kit.Split("type,name,text") {
|
||||
if key == mdb.TEXT && m.Option(mdb.TYPE) == SPARK {
|
||||
continue
|
||||
}
|
||||
add("data-", key)
|
||||
}
|
||||
kit.For(m.Optionv(mdb.EXTRA), func(key string, value string) {
|
||||
switch key {
|
||||
case PADDING:
|
||||
return
|
||||
}
|
||||
if !strings.Contains(key, "-") {
|
||||
add("data-", key)
|
||||
}
|
||||
})
|
||||
for _, key := range kit.Split(ctx.STYLE) {
|
||||
add("", key)
|
||||
kit.If(m.Option(key), func() { res = append(res, kit.Format(`%s%s=%q`, pre, key, m.Option(key))) })
|
||||
}
|
||||
kit.For(kit.Split("type,name,text"), func(k string) { add("data-", k) })
|
||||
kit.For(m.Optionv(mdb.EXTRA), func(k string, v string) { kit.If(!strings.Contains(k, "-"), func() { add("data-", k) }) })
|
||||
kit.For(kit.Split(ctx.STYLE), func(k string) { add("", k) })
|
||||
return kit.Join(res, ice.SP)
|
||||
}
|
||||
func (m *Message) OptionKV(key ...string) string {
|
||||
res := []string{}
|
||||
for _, k := range kit.Split(kit.Join(key)) {
|
||||
if m.Option(k) != "" {
|
||||
res = append(res, kit.Format("%s='%s'", k, m.Option(k)))
|
||||
}
|
||||
}
|
||||
kit.For(kit.Split(kit.Join(key)), func(k string) {
|
||||
kit.If(m.Option(k), func() { res = append(res, kit.Format("%s='%s'", k, m.Option(k))) })
|
||||
})
|
||||
return kit.Join(res, ice.SP)
|
||||
}
|
||||
|
@ -1,20 +1,19 @@
|
||||
wiki.shy
|
||||
wiki.go
|
||||
word.go
|
||||
feel.go
|
||||
data.go
|
||||
draw.go
|
||||
feel.go
|
||||
word.go
|
||||
|
||||
title.go
|
||||
brief.go
|
||||
refer.go
|
||||
brief.go
|
||||
spark.go
|
||||
field.go
|
||||
parse.go
|
||||
|
||||
chart.go
|
||||
order.go
|
||||
table.go
|
||||
chart.go
|
||||
field.go
|
||||
image.go
|
||||
video.go
|
||||
audio.go
|
||||
|
@ -7,12 +7,13 @@ import (
|
||||
"shylinux.com/x/icebergs/base/mdb"
|
||||
"shylinux.com/x/icebergs/base/nfs"
|
||||
"shylinux.com/x/icebergs/base/ssh"
|
||||
"shylinux.com/x/icebergs/core/code"
|
||||
"shylinux.com/x/icebergs/misc/git"
|
||||
kit "shylinux.com/x/toolkits"
|
||||
)
|
||||
|
||||
func _word_show(m *ice.Message, name string, arg ...string) {
|
||||
m.Options(ice.MSG_ALIAS, mdb.Configv(m, mdb.ALIAS), TITLE, map[string]int{}, MENU, kit.Dict(mdb.LIST, kit.List()))
|
||||
m.Options(ice.MSG_ALIAS, mdb.Configv(m, mdb.ALIAS), TITLE, map[string]int{})
|
||||
m.Cmdy(ssh.SOURCE, name, kit.Dict(nfs.DIR_ROOT, _wiki_path(m)))
|
||||
}
|
||||
|
||||
@ -20,7 +21,7 @@ const WORD = "word"
|
||||
|
||||
func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
WORD: {Name: "word path=src/main.shy@key list play", Help: "笔记文档", Actions: ice.MergeActions(ice.Actions{
|
||||
WORD: {Name: "word path=src/main.shy@key auto play", Help: "笔记文档", Actions: ice.MergeActions(ice.Actions{
|
||||
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) {
|
||||
WordAlias(m, NAVMENU, TITLE, NAVMENU)
|
||||
WordAlias(m, PREMENU, TITLE, PREMENU)
|
||||
@ -35,32 +36,26 @@ func init() {
|
||||
mdb.INPUTS: {Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmd(git.REPOS, ice.OptionFields(nfs.PATH)).Table(func(value ice.Maps) {
|
||||
if m.Option(nfs.DIR_DEEP, ice.TRUE); kit.Path(value[nfs.PATH]) == kit.Path("") {
|
||||
_wiki_list(m, "src/")
|
||||
_wiki_list(m, nfs.SRC)
|
||||
} else {
|
||||
_wiki_list(m, value[nfs.PATH])
|
||||
}
|
||||
})
|
||||
m.Cut("path,size,time")
|
||||
}}, "play": {Name: "play", Help: "演示"},
|
||||
ice.STORY: {Hand: func(m *ice.Message, arg ...string) {
|
||||
if kit.Ext(m.Option(nfs.PATH)) == nfs.SHY {
|
||||
m.Option(nfs.PATH, "")
|
||||
}
|
||||
m.Cmdy(arg[0], ice.RUN, arg[2:])
|
||||
}}, "play": {Help: "演示"},
|
||||
ice.STORY: {Hand: func(m *ice.Message, arg ...string) { m.Cmdy(arg[0], ice.RUN, arg[2:]) }},
|
||||
code.COMPLETE: {Hand: func(m *ice.Message, arg ...string) {
|
||||
ls := kit.Split(m.Option(mdb.TEXT))
|
||||
kit.If(kit.IsIn(ls[0], IMAGE, VIDEO, AUDIO), func() { m.Cmdy(FEEL).CutTo(nfs.PATH, mdb.NAME) })
|
||||
}},
|
||||
}, WikiAction("", nfs.SHY), ctx.CmdAction(), aaa.RoleAction("story.field")), Hand: func(m *ice.Message, arg ...string) {
|
||||
if m.Option(nfs.DIR_DEEP, ice.TRUE); len(arg) == 0 {
|
||||
arg = append(arg, "src/")
|
||||
}
|
||||
if !_wiki_list(m, arg...) {
|
||||
_word_show(m, arg[0])
|
||||
arg = append(arg, nfs.SRC)
|
||||
}
|
||||
kit.If(!_wiki_list(m, arg...), func() { _word_show(m, arg[0]) })
|
||||
}},
|
||||
})
|
||||
}
|
||||
func WordAction(template string, arg ...ice.Any) ice.Actions {
|
||||
return ice.Actions{ice.CTX_INIT: mdb.AutoConfig(append([]ice.Any{nfs.TEMPLATE, template}, arg...)...)}
|
||||
}
|
||||
func WordAlias(m *ice.Message, cmd string, cmds ...string) {
|
||||
mdb.Conf(m, WORD, kit.Keym(mdb.ALIAS, cmd), cmds)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user