1
0
mirror of https://shylinux.com/x/icebergs synced 2025-04-26 01:24:05 +08:00

opt div.go

This commit is contained in:
harveyshao 2022-07-17 12:51:55 +08:00
parent ba52eb6435
commit dfa2834e61
12 changed files with 114 additions and 95 deletions

View File

@ -53,6 +53,8 @@ func _split_list(m *ice.Message, file string, arg ...string) ice.Map {
// 回调函数
ls := kit.Split(text, m.Option(SPLIT_SPACE), m.Option(SPLIT_BLOCK), m.Option(SPLIT_QUOTE), m.Option(SPLIT_TRANS))
switch cb := m.OptionCB(SPLIT).(type) {
case func(int, []string) []string:
ls = cb(deep, ls)
case func(int, []string, ice.Map) []string:
ls = cb(deep, ls, data)
case func([]string, ice.Map) []string:

View File

@ -305,7 +305,7 @@ func init() {
msg := m.Spawn(SERVE, w, r)
repos := kit.Select(ice.INTSHELL, ice.VOLCANOS, strings.Contains(r.Header.Get("User-Agent"), "Mozilla/5.0"))
if repos == ice.VOLCANOS {
if s := msg.Cmdx("web.chat.website", lex.PARSE, "index.iml", "Header", "", "River", ""); s != "" {
if s := msg.Cmdx("web.chat.website", lex.PARSE, "index.iml", "Header", "", "River", "", "Footer", ""); s != "" {
Render(msg, ice.RENDER_RESULT, s)
return true // 定制主页
}

View File

@ -13,10 +13,9 @@ import (
)
func _div_parse(m *ice.Message, text string) string {
m.Option(nfs.CAT_CONTENT, text)
return m.Cmdx(lex.SPLIT, "", "index", "args", func(ls []string, meta ice.Map) []string {
if ls[0] == "div" {
ls = append([]string{"", "", "style", kit.Select("div", ls, 1)}, kit.Slice(ls, 2)...)
return m.Cmdx(lex.SPLIT, "", ctx.INDEX, ctx.ARGS, kit.Dict(nfs.CAT_CONTENT, text), func(deep int, ls []string) []string {
if ls[0] == DIV {
ls = append([]string{"", "", ctx.STYLE, kit.Select(DIV, ls, 1)}, kit.Slice(ls, 2)...)
}
return ls
})
@ -47,34 +46,39 @@ func init() {
}},
DIV: {Name: "div hash auto import", Help: "定制", Actions: ice.MergeAction(ice.Actions{
lex.SPLIT: {Name: "split name=hi text", Help: "生成", Hand: func(m *ice.Message, arg ...string) {
h := m.Cmdx(DIV, mdb.CREATE, m.OptionSimple(mdb.NAME), mdb.TEXT, _div_parse(m, m.Option(mdb.TEXT)))
m.ProcessRewrite(mdb.HASH, h)
m.ProcessRewrite(mdb.HASH, m.Cmdx(DIV, mdb.CREATE, m.OptionSimple(mdb.NAME), mdb.TEXT, _div_parse(m, m.Option(mdb.TEXT))))
}},
mdb.INPUTS: {Name: "inputs", Help: "补全", Hand: func(m *ice.Message, arg ...string) {
switch arg[0] {
case nfs.PATH:
m.Cmdy(nfs.DIR, arg[1:]).ProcessAgain()
case ctx.INDEX:
m.OptionFields(mdb.INDEX)
m.Cmdy(ctx.COMMAND, mdb.SEARCH, ctx.COMMAND, "", "")
case ctx.STYLE:
m.Push(arg[0], "div")
m.Push(arg[0], "span")
m.Push(arg[0], "output")
}
}},
mdb.CREATE: {Name: "create type=page name=hi text", Help: "创建"},
mdb.IMPORT: {Name: "import path=src/", Help: "导入", Hand: func(m *ice.Message, arg ...string) {
m.Cmd(nfs.DIR, kit.Dict(nfs.DIR_ROOT, m.Option(nfs.PATH)), func(p string) {
switch kit.Ext(p) {
case "shy":
case nfs.SHY:
m.Cmd(m.PrefixKey(), lex.SPLIT, mdb.NAME, p, mdb.TEXT, m.Cmdx(nfs.CAT, p))
}
})
}},
}, mdb.HashAction(), ctx.CmdAction()), Hand: func(m *ice.Message, arg ...string) {
switch kit.Ext(kit.Select("", arg, 0)) {
case "shy":
case nfs.SHY:
m.Fields(0)
m.Push(mdb.TEXT, _div_parse(m, m.Cmdx(nfs.CAT, arg[0])))
m.DisplayLocal("")
m.Push(mdb.TEXT, _div_parse(m, m.Cmdx(nfs.CAT, arg[0]))).DisplayLocal("")
default:
if mdb.HashSelect(m, arg...); len(arg) > 0 {
m.Action("添加", "保存", "预览")
m.DisplayLocal("")
m.Action("添加", "保存").DisplayLocal("")
m.StatusTime(mdb.LINK, m.MergeLink("/chat/div/"+arg[0]))
} else {
m.Action(lex.SPLIT, mdb.CREATE)
}

View File

@ -39,7 +39,7 @@ func init() {
m.Cmd(web.DREAM, cli.START, mdb.NAME, arg[0])
}
aaa.UserRoot(m)
if m.RenderWebsite(arg[0], "index.iml", "Header", "", "River", "", "Action", "", "Footer", ""); m.Result() == "" {
if m.RenderWebsite(arg[0], "index.iml", "Header", "", "River", "", "Footer", ""); m.Result() == "" {
m.RenderIndex(web.SERVE, ice.VOLCANOS)
}

View File

@ -16,11 +16,7 @@ import (
)
func _website_url(m *ice.Message, file string) string {
p := path.Join(WEBSITE, file)
if m.Option(ice.MSG_USERPOD) != "" {
p = path.Join(ice.POD, m.Option(ice.MSG_USERPOD), WEBSITE, file)
}
return strings.Split(kit.MergeURL2(m.Option(ice.MSG_USERWEB), path.Join("/chat", p)), "?")[0]
return strings.Split(m.MergeWebsite(file), "?")[0]
}
func _website_parse(m *ice.Message, text string, args ...string) (ice.Map, bool) {
if text == "" {
@ -30,6 +26,7 @@ func _website_parse(m *ice.Message, text string, args ...string) (ice.Map, bool)
const (
HEADER = "Header"
RIVER = "River"
FOOTER = "Footer"
ORDER = "order"
TITLE = "title"
@ -38,15 +35,16 @@ func _website_parse(m *ice.Message, text string, args ...string) (ice.Map, bool)
river, storm, last := kit.Dict(
HEADER, kit.Dict(MENUS, kit.List(), ctx.STYLE, kit.Dict(ctx.DISPLAY, "none")),
RIVER, kit.Dict(MENUS, kit.List(), ctx.ACTION, kit.List()), args,
RIVER, kit.Dict(MENUS, kit.List(), ctx.ACTION, kit.List("")),
FOOTER, kit.Dict(MENUS, kit.List(), ctx.STYLE, kit.Dict(ctx.DISPLAY, "none")),
args,
), kit.Dict(), kit.Dict()
nriver, nstorm, prefix := 0, 0, ""
m.Option(nfs.CAT_CONTENT, text)
m.Cmd(lex.SPLIT, "", mdb.KEY, mdb.NAME, func(deep int, ls []string, meta ice.Map) []string {
nriver, nstorm, prefix := 0, 0, ""
m.Cmd(lex.SPLIT, "", mdb.KEY, mdb.NAME, kit.Dict(nfs.CAT_CONTENT, text), func(deep int, ls []string) []string {
if deep == 1 {
switch ls[0] {
case HEADER, RIVER:
case HEADER, RIVER, FOOTER:
for i := 1; i < len(ls); i += 2 {
kit.Value(river, kit.Keys(ls[0], ls[i]), ls[i+1])
}
@ -58,19 +56,14 @@ func _website_parse(m *ice.Message, text string, args ...string) (ice.Map, bool)
switch kit.Ext(ls[0]) {
case nfs.JS:
ls[0], data[ctx.DISPLAY] = kit.Select(ctx.CAN_PLUGIN, ice.GetFileCmd(ls[0])), ice.FileURI(ls[0])
case nfs.GO:
ls[0] = ice.GetFileCmd(ls[0])
case nfs.SH:
ls[0], data[ctx.ARGS] = "web.code.sh.sh", ls[0]
case nfs.SHY:
ls[0], data[ctx.ARGS] = "web.wiki.word", ls[0]
case nfs.PY:
ls[0], data[ctx.ARGS] = "web.code.sh.py", ls[0]
case "~":
prefix, ls = ls[1], ls[1:]
fallthrough
@ -128,8 +121,11 @@ func _website_parse(m *ice.Message, text string, args ...string) (ice.Map, bool)
func _website_render(m *ice.Message, w http.ResponseWriter, r *http.Request, kind, text string) bool {
msg := m.Spawn(w, r)
switch kind {
case nfs.SVG:
msg.RenderResult(`<body style="background-color:cadetblue">%s</body>`, msg.Cmdx(nfs.CAT, text))
case nfs.ZML:
msg.RenderCmd("can.parse", text)
case nfs.IML:
res, _ := _website_parse(msg, text)
msg.RenderResult(_website_template2, kit.Format(res))
case nfs.SHY:
if r.Method == http.MethodGet {
msg.RenderCmd(msg.Prefix(DIV), text)
@ -137,18 +133,14 @@ func _website_render(m *ice.Message, w http.ResponseWriter, r *http.Request, kin
r.URL.Path = "/chat/cmd/web.chat.div"
return false
}
case nfs.ZML:
msg.RenderCmd("can.parse", text)
case nfs.IML:
res, _ := _website_parse(msg, text)
msg.RenderResult(_website_template2, kit.Format(res))
case nfs.JSON:
msg.RenderResult(_website_template2, kit.Format(kit.UnMarshal(text)))
case nfs.JS:
msg.RenderResult(_website_template, text)
case nfs.HTML:
msg.RenderResult(text)
case nfs.SVG:
msg.RenderResult(`<body style="background-color:cadetblue">%s</body>`, msg.Cmdx(nfs.CAT, text))
default:
msg.RenderDownload(text)
}
@ -168,16 +160,13 @@ const (
const WEBSITE = "website"
func init() {
Index.Merge(&ice.Context{Configs: ice.Configs{
WEBSITE: {Name: "website", Help: "网站", Value: kit.Data(mdb.SHORT, nfs.PATH, mdb.FIELD, "time,path,type,name,text")},
}, Commands: ice.Commands{
"/website/": {Name: "/website/", Help: "网站", Actions: ice.MergeAction(ice.Actions{}, ctx.CmdAction())},
Index.MergeCommands(ice.Commands{"/website/": {Name: "/website/", Help: "网站", Actions: ctx.CmdAction()},
WEBSITE: {Name: "website path auto create import", Help: "网站", Actions: ice.MergeAction(ice.Actions{
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) {
m.Cmd(mdb.RENDER, mdb.CREATE, nfs.IML, m.PrefixKey())
m.Cmd(mdb.ENGINE, mdb.CREATE, nfs.IML, m.PrefixKey())
m.Cmd(mdb.RENDER, mdb.CREATE, nfs.TXT, m.PrefixKey())
m.Cmd(mdb.ENGINE, mdb.CREATE, nfs.TXT, m.PrefixKey())
m.Cmd(mdb.RENDER, mdb.CREATE, nfs.IML, m.PrefixKey())
m.Cmd(mdb.ENGINE, mdb.CREATE, nfs.IML, m.PrefixKey())
web.AddRewrite(func(w http.ResponseWriter, r *http.Request) bool {
if r.Method != http.MethodGet {
@ -198,14 +187,14 @@ func init() {
}},
lex.PARSE: {Hand: func(m *ice.Message, arg ...string) {
switch kit.Ext(arg[0]) {
case nfs.ZML:
m.RenderCmd("can.parse", m.Cmdx(nfs.CAT, path.Join(SRC_WEBSITE, arg[0])))
case nfs.IML:
if res, ok := _website_parse(m, m.Cmdx(nfs.CAT, path.Join(SRC_WEBSITE, arg[0])), arg[1:]...); ok {
m.Echo(_website_template2, kit.Format(res))
}
case nfs.ZML:
m.RenderCmd("can.parse", m.Cmdx(nfs.CAT, path.Join(SRC_WEBSITE, arg[0])))
default:
if text := m.Cmd(m.PrefixKey(), ice.PS+arg[0]).Append(mdb.TEXT); text != "" {
if res, ok := _website_parse(m, text, arg[1:]...); ok {
@ -223,7 +212,11 @@ func init() {
m.EchoIFrame(_website_url(m, strings.TrimPrefix(path.Join(arg[2], arg[1]), SRC_WEBSITE)))
}},
mdb.ENGINE: {Hand: func(m *ice.Message, arg ...string) {
m.Echo(_website_url(m, strings.TrimPrefix(path.Join(arg[2], arg[1]), SRC_WEBSITE)))
if res, ok := _website_parse(m, m.Cmdx(nfs.CAT, path.Join(arg[2], arg[1]))); ok {
m.Echo(kit.Formats(res)).DisplayStoryJSON()
} else {
m.Echo(_website_url(m, strings.TrimPrefix(path.Join(arg[2], arg[1]), SRC_WEBSITE)))
}
}},
mdb.INPUTS: {Name: "inputs", Help: "补全", Hand: func(m *ice.Message, arg ...string) {
switch m.Option(ctx.ACTION) {
@ -236,24 +229,21 @@ func init() {
}
}
}},
mdb.CREATE: {Name: "create path type=iml,json,js,html name text", Help: "创建"},
mdb.CREATE: {Name: "create path type=iml,zml,json,js,html name text", Help: "创建"},
mdb.IMPORT: {Name: "import path=src/website/", Help: "导入", Hand: func(m *ice.Message, arg ...string) {
m.Cmd(nfs.DIR, kit.Dict(nfs.DIR_ROOT, m.Option(nfs.PATH)), func(p string) {
switch name := strings.TrimPrefix(p, m.Option(nfs.PATH)); kit.Ext(p) {
case nfs.HTML, nfs.JS, nfs.JSON, nfs.IML, nfs.TXT:
m.Cmd(m.PrefixKey(), mdb.CREATE, nfs.PATH, ice.PS+name,
mdb.TYPE, kit.Ext(p), mdb.NAME, name, mdb.TEXT, m.Cmdx(nfs.CAT, p))
case nfs.HTML, nfs.JS, nfs.JSON, nfs.ZML, nfs.IML, nfs.TXT:
m.Cmd(m.PrefixKey(), mdb.CREATE, nfs.PATH, ice.PS+name, mdb.TYPE, kit.Ext(p), mdb.NAME, name, mdb.TEXT, m.Cmdx(nfs.CAT, p))
default:
m.Cmd(m.PrefixKey(), mdb.CREATE, nfs.PATH, ice.PS+name,
mdb.TYPE, kit.Ext(p), mdb.NAME, name, mdb.TEXT, p)
m.Cmd(m.PrefixKey(), mdb.CREATE, nfs.PATH, ice.PS+name, mdb.TYPE, kit.Ext(p), mdb.NAME, name, mdb.TEXT, p)
}
})
}},
}, mdb.HashAction()), Hand: func(m *ice.Message, arg ...string) {
mdb.HashSelect(m, arg...).Table(func(index int, value ice.Maps, head []string) {
m.PushAnchor(m.MergeWebsite(value[nfs.PATH]))
})
if len(arg) == 0 {
}, mdb.HashAction(mdb.SHORT, nfs.PATH, mdb.FIELD, "time,path,type,name,text")), Hand: func(m *ice.Message, arg ...string) {
mdb.HashSelect(m, arg...).Table(func(index int, value ice.Maps, head []string) { m.PushAnchor(m.MergeWebsite(value[nfs.PATH])) })
if len(arg) == 0 { // 文件列表
m.Cmd(nfs.DIR, SRC_WEBSITE, func(f os.FileInfo, p string) {
m.Push("", kit.Dict(
mdb.TIME, f.ModTime().Format(ice.MOD_TIME),
@ -263,19 +253,18 @@ func init() {
m.PushAnchor(m.MergeLink(path.Join(CHAT_WEBSITE, strings.TrimPrefix(p, SRC_WEBSITE))))
}).Sort(nfs.PATH)
}
if m.Length() == 0 && len(arg) > 0 {
if m.Length() == 0 && len(arg) > 0 { // 文件详情
m.Push(mdb.TEXT, m.Cmdx(nfs.CAT, path.Join(SRC_WEBSITE, path.Join(arg...))))
m.Push(nfs.PATH, path.Join(CHAT_WEBSITE, path.Join(arg...)))
m.PushAnchor(m.MergeLink(m.Append(nfs.PATH)))
}
if m.FieldsIsDetail() {
if m.FieldsIsDetail() { // 文件预览
m.PushQRCode(mdb.SCAN, m.MergeURL2(m.Append(nfs.PATH)))
m.EchoIFrame(m.Append(nfs.PATH))
}
}},
}})
})
}
var _website_template = `<!DOCTYPE html>

View File

@ -7,51 +7,30 @@ import (
ice "shylinux.com/x/icebergs"
"shylinux.com/x/icebergs/base/mdb"
"shylinux.com/x/icebergs/base/nfs"
kit "shylinux.com/x/toolkits"
)
const (
SRC_WEBSITE = "src/website/"
CHAT_WEBSITE = "/chat/website/"
)
func _website_url(m *ice.Message, file string) string {
const WEBSITE = "website"
p := path.Join(WEBSITE, file)
if m.Option(ice.MSG_USERPOD) != "" {
p = path.Join(ice.POD, m.Option(ice.MSG_USERPOD), WEBSITE, file)
}
return strings.Split(kit.MergeURL2(m.Option(ice.MSG_USERWEB), path.Join("/chat", p)), "?")[0]
return strings.Split(m.MergeWebsite(file), "?")[0]
}
const ZML = nfs.ZML
func init() {
const (
SRC_WEBSITE = "src/website/"
)
Index.Register(&ice.Context{Name: ZML, Help: "网页", Commands: ice.Commands{
ZML: {Name: "zml", Help: "网页", Actions: ice.MergeAction(ice.Actions{
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) {
m.Cmd(mdb.PLUGIN, mdb.CREATE, nfs.ZML, m.PrefixKey())
m.Cmd(mdb.RENDER, mdb.CREATE, nfs.ZML, m.PrefixKey())
LoadPlug(m, ZML)
m.Cmd(mdb.ENGINE, mdb.CREATE, nfs.ZML, m.PrefixKey())
}},
mdb.RENDER: {Hand: func(m *ice.Message, arg ...string) {
m.EchoIFrame(_website_url(m, strings.TrimPrefix(path.Join(arg[2], arg[1]), SRC_WEBSITE)))
}},
}, PlugAction())},
}, Configs: ice.Configs{
ZML: {Name: ZML, Help: "网页", Value: kit.Data(PLUG, kit.Dict(PREFIX, kit.Dict("# ", COMMENT), PREPARE, kit.Dict(
KEYWORD, kit.Simple(
"head", "left", "main", "foot",
"tabs",
),
CONSTANT, kit.Simple(
"auto", "username",
),
FUNCTION, kit.Simple(
"index", "action", "args", "type",
"style", "width",
),
), KEYWORD, kit.Dict(),
))},
mdb.ENGINE: {Hand: func(m *ice.Message, arg ...string) {
m.Echo(_website_url(m, strings.TrimPrefix(path.Join(arg[2], arg[1]), SRC_WEBSITE)))
}},
})},
}}, nil)
}

33
core/team/epic.go Normal file
View File

@ -0,0 +1,33 @@
package team
import (
"time"
ice "shylinux.com/x/icebergs"
"shylinux.com/x/icebergs/base/mdb"
kit "shylinux.com/x/toolkits"
)
const EPIC = "epic"
func init() {
Index.MergeCommands(ice.Commands{
EPIC: {Name: "epic hash list create export import", Help: "史记", Actions: ice.MergeAction(ice.Actions{
mdb.CREATE: {Name: "create time@date type name", Help: "创建"},
mdb.MODIFY: {Name: "modify hash time@date type name", Help: "编辑"},
}, mdb.HashAction(mdb.FIELD, "time,hash,type,name,text")), Hand: func(m *ice.Message, arg ...string) {
mdb.HashSelect(m, arg...).SetAppend(mdb.TEXT).Tables(func(value ice.Maps) {
if span := kit.Time(m.Time()) - kit.Time(value[mdb.TIME]); span > 0 {
m.Push(mdb.TEXT, kit.Format(`已经 <span style="font-size:24px;color:red">%v</span> 天<br>距 %s<br>`,
int(time.Duration(span)/time.Hour/24)+1, kit.Split(value[mdb.TIME])[0],
))
} else {
m.Push(mdb.TEXT, kit.Format(`还有 <span style="font-size:24px;color:green">%v</span> 天<br>距 %s<br>`,
-int(time.Duration(span)/time.Hour/24)+1, kit.Split(value[mdb.TIME])[0],
))
}
})
m.Sort(mdb.TIME).PushAction(mdb.MODIFY, mdb.REMOVE).DisplayTableCard()
}},
})
}

View File

@ -9,7 +9,7 @@ import (
const TODO = "todo"
func init() {
Index.Merge(&ice.Context{Commands: ice.Commands{
Index.MergeCommands(ice.Commands{
TODO: {Name: "todo hash list create export import", Help: "待办", Actions: ice.MergeAction(ice.Actions{
mdb.INPUTS: {Name: "inputs", Help: "补全", Hand: func(m *ice.Message, arg ...string) {
m.Cmdy(mdb.INPUTS, m.PrefixKey(), "", mdb.HASH, arg)
@ -25,5 +25,5 @@ func init() {
mdb.HashSelect(m, arg...).PushAction(cli.START, mdb.REMOVE)
m.PushPodCmd(m.CommandKey(), arg...)
}},
}})
})
}

View File

@ -82,6 +82,9 @@ func init() {
ice.PLAY: {Name: "play", Help: "演示"},
}, ctx.CmdAction(), mdb.HashAction()), Hand: func(m *ice.Message, arg ...string) {
m.Option(nfs.DIR_REG, m.Config(lex.REGEXP))
if len(arg) == 0 {
arg = append(arg, "src/")
}
if m.Option(nfs.DIR_DEEP, ice.TRUE); !_wiki_list(m, m.CommandKey(), arg...) {
if !kit.FileExists(arg[0]) && kit.FileExists(path.Join("src", arg[0])) {
arg[0] = path.Join("src/", arg[0])

View File

@ -111,7 +111,7 @@ func GetFileCmd(dir string) string {
if strings.HasPrefix(dir, "require/") {
dir = "/" + dir
}
for _, dir := range []string{dir, "/require/" + Info.Make.Module + "/" + dir, "/require/" + Info.Make.Module + "/src/" + dir} {
for _, dir := range []string{dir, path.Join("/require/", Info.Make.Module, dir), path.Join("/require/", Info.Make.Module, SRC, dir)} {
if cmd, ok := Info.File[FileCmd(dir)]; ok {
return cmd
}

View File

@ -247,6 +247,12 @@ func (m *Message) DisplayBase(file string, arg ...Any) *Message {
m.Option(MSG_DISPLAY, kit.MergeURL(DisplayBase(file)[DISPLAY], arg...))
return m
}
func (m *Message) DisplayTable(arg ...Any) *Message { // /plugin/story/file
return m.Display(kit.MergeURL("/plugin/table.js", arg...))
}
func (m *Message) DisplayTableCard(arg ...Any) *Message { // /plugin/story/file
return m.Display(kit.MergeURL("/plugin/table.js", "style", "card"))
}
func (m *Message) DisplayStory(file string, arg ...Any) *Message { // /plugin/story/file
if !strings.HasPrefix(file, HTTP) && !strings.HasPrefix(file, PS) {
file = path.Join(PLUGIN_STORY, file)

View File

@ -117,6 +117,9 @@ func (c *Context) Register(s *Context, x Server, n ...string) *Context {
s.server = x
return s
}
func (c *Context) MergeCommands(Commands Commands) *Context {
return c.Merge(&Context{Commands: Commands})
}
func (c *Context) Merge(s *Context) *Context {
if c.Commands == nil {
c.Commands = map[string]*Command{}