1
0
forked from x/icebergs
This commit is contained in:
shaoying 2020-08-07 09:57:28 +08:00
parent 98e018df6d
commit 36b23b5c9b
3 changed files with 73 additions and 107 deletions

View File

@ -19,7 +19,6 @@ import (
const LOGIN = "_login" const LOGIN = "_login"
func _serve_login(msg *ice.Message, cmds []string, w http.ResponseWriter, r *http.Request) ([]string, bool) { func _serve_login(msg *ice.Message, cmds []string, w http.ResponseWriter, r *http.Request) ([]string, bool) {
msg.Debug("what", msg.Conf("aaa.user"))
msg.Option(ice.MSG_USERNAME, "") msg.Option(ice.MSG_USERNAME, "")
msg.Option(ice.MSG_USERROLE, "") msg.Option(ice.MSG_USERROLE, "")

View File

@ -15,7 +15,6 @@ import (
func _inner_ext(name string) string { func _inner_ext(name string) string {
return strings.ToLower(kit.Select(path.Base(name), strings.TrimPrefix(path.Ext(name), "."))) return strings.ToLower(kit.Select(path.Base(name), strings.TrimPrefix(path.Ext(name), ".")))
} }
func _inner_list(m *ice.Message, ext, file, dir string, arg ...string) { func _inner_list(m *ice.Message, ext, file, dir string, arg ...string) {
if !m.Right(strings.Split(dir, "/"), file) { if !m.Right(strings.Split(dir, "/"), file) {
return return
@ -35,13 +34,15 @@ func _inner_show(m *ice.Message, ext, file, dir string, arg ...string) {
} }
} }
} }
func _vimer_save(m *ice.Message, ext, file, dir string, text string) {
const ( if f, p, e := kit.Create(path.Join(dir, file)); e == nil {
LIST = "list" defer f.Close()
PLUG = "plug" if n, e := f.WriteString(text); m.Assert(e) {
SHOW = "show" m.Log_EXPORT("file", path.Join(dir, file), "size", n)
SAVE = "save" }
) m.Echo(p)
}
}
const ( const (
INNER = "inner" INNER = "inner"
@ -51,17 +52,9 @@ const (
func init() { func init() {
Index.Merge(&ice.Context{ Index.Merge(&ice.Context{
Commands: map[string]*ice.Command{ Commands: map[string]*ice.Command{
INNER: {Name: "inner path=usr/demo file=hi.sh line=1 auto", Help: "阅读器", Meta: kit.Dict( INNER: {Name: "inner path=usr/demo file=hi.sh line=1 auto 运行:button 项目:button 搜索:button", Help: "阅读器", Meta: kit.Dict(
"display", "/plugin/local/code/inner.js", "style", "editor", "display", "/plugin/local/code/inner.js", "style", "editor",
), Action: map[string]*ice.Action{ ), Action: map[string]*ice.Action{
web.UPLOAD: {Name: "upload path name", Help: "上传", Hand: func(m *ice.Message, arg ...string) {
m.Cmdy(web.CACHE, web.UPLOAD)
m.Cmdy(web.CACHE, web.WATCH, m.Option(web.DATA), path.Join(m.Option("path"), m.Option("name")))
}},
mdb.SEARCH: {Name: "search type name text arg...", Help: "搜索", Hand: func(m *ice.Message, arg ...string) {
m.Cmdy(mdb.SEARCH, arg)
}},
mdb.PLUGIN: {Name: "plugin type name text arg...", Help: "插件", Hand: func(m *ice.Message, arg ...string) { mdb.PLUGIN: {Name: "plugin type name text arg...", Help: "插件", Hand: func(m *ice.Message, arg ...string) {
if m.Cmdy(mdb.PLUGIN, arg); m.Result() == "" { if m.Cmdy(mdb.PLUGIN, arg); m.Result() == "" {
if m.Echo(m.Conf(INNER, kit.Keys("meta.plug", arg[0]))); m.Result() == "" { if m.Echo(m.Conf(INNER, kit.Keys("meta.plug", arg[0]))); m.Result() == "" {
@ -69,6 +62,9 @@ func init() {
} }
} }
}}, }},
mdb.SEARCH: {Name: "search type name text arg...", Help: "搜索", Hand: func(m *ice.Message, arg ...string) {
m.Cmdy(mdb.SEARCH, arg)
}},
mdb.RENDER: {Name: "render type name text arg...", Help: "渲染", Hand: func(m *ice.Message, arg ...string) { mdb.RENDER: {Name: "render type name text arg...", Help: "渲染", Hand: func(m *ice.Message, arg ...string) {
_inner_list(m, arg[0], arg[1], arg[2], arg[3:]...) _inner_list(m, arg[0], arg[1], arg[2], arg[3:]...)
}}, }},
@ -82,9 +78,21 @@ func init() {
} }
_inner_list(m, _inner_ext(arg[1]), arg[1], arg[0]) _inner_list(m, _inner_ext(arg[1]), arg[1], arg[0])
}}, }},
VIMER: {Name: "vimer path=usr/demo file=hi.sh line=1 auto", Help: "编辑器", Meta: kit.Dict( VIMER: {Name: "vimer path=usr/demo file=hi.sh line=1 刷新:button=auto 编辑:button 保存:button 运行:button 项目:button", Help: "编辑器", Meta: kit.Dict(
"display", "/plugin/local/code/vimer.js", "style", "editor", "display", "/plugin/local/code/vimer.js", "style", "editor",
), Action: map[string]*ice.Action{}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { ), Action: map[string]*ice.Action{
web.UPLOAD: {Name: "upload path name", Help: "上传", Hand: func(m *ice.Message, arg ...string) {
m.Cmdy(web.CACHE, web.UPLOAD)
m.Cmdy(web.CACHE, web.WATCH, m.Option(web.DATA), path.Join(m.Option("path"), m.Option("name")))
}},
nfs.SAVE: {Name: "save type file path", Help: "保存", Hand: func(m *ice.Message, arg ...string) {
_vimer_save(m, arg[0], arg[1], arg[2], m.Option("content"))
}},
"cmd": {Name: "cmd type file path", Help: "命令", Hand: func(m *ice.Message, arg ...string) {
m.Cmdy(arg)
}},
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
m.Cmdy(INNER, arg) m.Cmdy(INNER, arg)
}}, }},
}, },
@ -94,62 +102,57 @@ func init() {
"license", "true", "license", "true",
"makefile", "true", "makefile", "true",
"shy", "true", "py", "true", "shy", "true", "py", "true",
"csv", "true", "json", "true",
"md", "true", "csv", "true", "css", "true", "html", "true",
"txt", "true", "url", "true", "txt", "true", "url", "true",
"conf", "true", "json", "true",
"md", "true", "conf", "true",
"ts", "true", "tsx", "true", "vue", "true", "sass", "true", "ts", "true", "tsx", "true", "vue", "true", "sass", "true",
"html", "true", "css", "true",
), ),
"plug", kit.Dict( "plug", kit.Dict(
"makefile", kit.Dict(
"prefix", kit.Dict("#", "comment"),
"suffix", kit.Dict(":", "comment"),
"keyword", kit.Dict(
"ifeq", "keyword",
"ifneq", "keyword",
"else", "keyword",
"endif", "keyword",
),
),
"shy", kit.Dict(
"prefix", kit.Dict("#", "comment"),
"keyword", kit.Dict(
"title", "keyword",
"chapter", "keyword",
"section", "keyword",
"refer", "keyword",
"field", "keyword",
"label", "keyword",
"chain", "keyword",
),
),
"py", kit.Dict( "py", kit.Dict(
"prefix", kit.Dict("#", "comment"), "prefix", kit.Dict("#", "comment"),
"keyword", kit.Dict("print", "keyword"), "keyword", kit.Dict("print", "keyword"),
), ),
"md", kit.Dict("display", true, "profile", true),
"csv", kit.Dict("display", true), "csv", kit.Dict("display", true),
"ts", kit.Dict( "json", kit.Dict("link", true),
"prefix", kit.Dict("//", "comment"), "html", kit.Dict(
"split", kit.Dict( "split", kit.Dict(
"space", " ", "space", " ",
"operator", "{[(.:,;!|)]}", "operator", "<>",
), ),
"keyword", kit.Dict( "keyword", kit.Dict(
"import", "keyword", "head", "keyword",
"from", "keyword", "body", "keyword",
"new", "keyword",
"as", "keyword",
"const", "keyword",
"export", "keyword",
"default", "keyword",
"if", "keyword",
"return", "keyword",
"class", "keyword",
"extends", "keyword",
"interface", "keyword",
"declare", "keyword",
"async", "keyword",
"await", "keyword",
"try", "keyword",
"catch", "keyword",
"function", "function",
"arguments", "function",
"console", "function",
"this", "function",
"string", "datatype",
"number", "datatype",
"true", "string",
"false", "string",
), ),
), ),
"tsx", kit.Dict("link", "ts"), "css", kit.Dict(
"vue", kit.Dict("link", "ts"), "suffix", kit.Dict("{", "comment"),
"sass", kit.Dict("link", "ts"), ),
"md", kit.Dict("display", true, "profile", true),
), ),
"show", kit.Dict( "show", kit.Dict(
"sh", []string{"sh"}, "sh", []string{"sh"},

View File

@ -2,69 +2,33 @@ package wiki
import ( import (
ice "github.com/shylinux/icebergs" ice "github.com/shylinux/icebergs"
"github.com/shylinux/icebergs/base/mdb"
"github.com/shylinux/icebergs/base/nfs" "github.com/shylinux/icebergs/base/nfs"
"github.com/shylinux/icebergs/base/web"
kit "github.com/shylinux/toolkits" kit "github.com/shylinux/toolkits"
)
func _draw_show(m *ice.Message, zone, kind, name, text string, arg ...string) { "path"
m.Cmdy(kit.Keys(zone, kind), name, text, arg) )
}
func _draw_plugin(m *ice.Message, arg ...string) {
m.Travel(func(p *ice.Context, s *ice.Context, key string, cmd *ice.Command) {
if m.Target() == s {
return
}
m.Push(s.Name, cmd.Name)
})
}
const DRAW = "draw" const DRAW = "draw"
const (
DrawPlugin = "/plugin/local/wiki/draw.js"
)
func init() { func init() {
sub := Index.Register(&ice.Context{Name: "draw", Help: "思维导图", Index.Register(&ice.Context{Name: "draw", Help: "思维导图",
Configs: map[string]*ice.Config{ Configs: map[string]*ice.Config{
DRAW: {Name: "draw", Help: "思维导图", Value: kit.Data( DRAW: {Name: "draw", Help: "思维导图", Value: kit.Data(
"path", "", "regs", ".*\\.svg", "path", "", "regs", ".*\\.svg",
"prefix", `<svg vertion="1.1" xmlns="http://www.w3.org/2000/svg" width="%v" height="%v">`, "suffix", `</svg>`,
)}, )},
}, },
Commands: map[string]*ice.Command{ Commands: map[string]*ice.Command{
DRAW: {Name: "draw path=src/main.svg auto", Help: "思维导图", Meta: kit.Dict(mdb.PLUGIN, DrawPlugin), Action: map[string]*ice.Action{ DRAW: {Name: "draw path=src/ file=demo.svg 刷新:button=auto 编辑:button 保存:button 项目:button 变参:button", Help: "思维导图", Meta: kit.Dict(
nfs.SAVE: {Name: "save path text", Help: "保存", Hand: func(m *ice.Message, arg ...string) { "display", "/plugin/local/wiki/draw.js", "style", "drawer",
_wiki_save(m, DRAW, arg[0], kit.Select(m.Option("content"), arg, 1)) ), Action: map[string]*ice.Action{
}}, nfs.SAVE: {Name: "save path file text", Help: "保存", Hand: func(m *ice.Message, arg ...string) {
"run": {Name: "show zone type name text", Help: "运行", Hand: func(m *ice.Message, arg ...string) { _wiki_save(m, DRAW, path.Join(arg...), m.Option("content"))
_draw_show(m, arg[0], arg[1], arg[2], arg[3], arg[4:]...)
}},
mdb.PLUGIN: {Name: "plugin", Help: "插件", Hand: func(m *ice.Message, arg ...string) {
_draw_plugin(m, arg...)
}}, }},
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { }, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
if !_wiki_list(m, DRAW, kit.Select("./", arg, 0)) { if !_wiki_list(m, DRAW, kit.Select("./", path.Join(arg...))) {
_wiki_show(m, DRAW, arg[0]) _wiki_show(m, DRAW, path.Join(arg...))
} }
}}, }},
}, },
}, nil) }, nil)
sub.Register(&ice.Context{Name: "工作", Help: "工作",
Commands: map[string]*ice.Command{
"项目开发": {Name: "项目开发", Help: "项目开发", Action: map[string]*ice.Action{
"run": {Hand: func(m *ice.Message, arg ...string) {
m.Echo("hello world")
}},
}, Hand: func(m *ice.Message, c *ice.Context, key string, arg ...string) {
m.Echo("hello world")
}},
"项目测试": {Name: "项目测试", Help: "项目测试", Hand: func(m *ice.Message, c *ice.Context, key string, arg ...string) {
}},
},
}, &web.Frame{})
} }