1
0
mirror of https://shylinux.com/x/icebergs synced 2025-06-26 18:37:29 +08:00
This commit is contained in:
harveyshao 2021-11-01 19:22:12 +08:00
parent f4258e4092
commit 51eb0852c2
21 changed files with 337 additions and 432 deletions

View File

@ -22,8 +22,8 @@ Volcanos("onimport", {help: "导入数据", list: [], _init: function(can, msg,
return can.onimport._task(can, msg, get(begin_time, col, row, hash), set(begin_time, col, row)) return can.onimport._task(can, msg, get(begin_time, col, row, hash), set(begin_time, col, row))
})} })}
}) }]) }) }])
can.core.Timer(10, function() { can.core.Timer(10, function() { if (!can.sup.task) { return }
var target = can.sup.task._target||can.sup.task._target var target = can.sup.task._target||can.task._target
can.sup.task = null, target.click() can.sup.task = null, target.click()
can.Status("count", msg.Length()) can.Status("count", msg.Length())
}) })

View File

@ -8,16 +8,13 @@ import (
const BRIEF = "brief" const BRIEF = "brief"
func init() { func init() {
Index.Merge(&ice.Context{ Index.Merge(&ice.Context{Commands: map[string]*ice.Command{
Commands: map[string]*ice.Command{
BRIEF: {Name: "brief text", Help: "摘要", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { BRIEF: {Name: "brief text", Help: "摘要", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
_wiki_template(m, cmd, "", arg[0], arg[1:]...) _wiki_template(m, cmd, "", arg[0], arg[1:]...)
}}, }},
}, }, Configs: map[string]*ice.Config{
Configs: map[string]*ice.Config{
BRIEF: {Name: BRIEF, Help: "摘要", Value: kit.Data( BRIEF: {Name: BRIEF, Help: "摘要", Value: kit.Data(
kit.MDB_TEMPLATE, `<p {{.OptionTemplate}}>{{.Option "text"}}</p>`, kit.MDB_TEMPLATE, `<p {{.OptionTemplate}}>{{.Option "text"}}</p>`,
)}, )},
}, }})
})
} }

View File

@ -2,6 +2,7 @@ package wiki
import ( import (
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"
"strings" "strings"
@ -38,22 +39,22 @@ type Block struct {
func (b *Block) Init(m *ice.Message, arg ...string) Chart { func (b *Block) Init(m *ice.Message, arg ...string) Chart {
b.Text = kit.Select(b.Text, arg, 0) b.Text = kit.Select(b.Text, arg, 0)
b.FontSize = kit.Int(kit.Select(m.Option("font-size"), kit.Select(kit.Format(b.FontSize), arg, 1))) b.FontSize = kit.Int(kit.Select(m.Option(FONT_SIZE), kit.Select(kit.Format(b.FontSize), arg, 1)))
b.FontColor = kit.Select(m.Option("stroke"), kit.Select(b.FontColor, arg, 2)) b.FontColor = kit.Select(m.Option(STROKE), kit.Select(b.FontColor, arg, 2))
b.BackGround = kit.Select(m.Option("fill"), kit.Select(b.BackGround, arg, 3)) b.BackGround = kit.Select(m.Option(FILL), kit.Select(b.BackGround, arg, 3))
b.Padding = kit.Int(kit.Select(m.Option("padding"), kit.Select(kit.Format(b.Padding), arg, 4))) b.Padding = kit.Int(kit.Select(m.Option(PADDING), kit.Select(kit.Format(b.Padding), arg, 4)))
b.MarginX = kit.Int(kit.Select(m.Option("marginx"), kit.Select(kit.Format(b.MarginX), arg, 5))) b.MarginX = kit.Int(kit.Select(m.Option(MARGINX), kit.Select(kit.Format(b.MarginX), arg, 5)))
b.MarginY = kit.Int(kit.Select(m.Option("marginy"), kit.Select(kit.Format(b.MarginY), arg, 5))) b.MarginY = kit.Int(kit.Select(m.Option(MARGINY), kit.Select(kit.Format(b.MarginY), arg, 5)))
return b return b
} }
func (b *Block) Data(m *ice.Message, root interface{}) Chart { func (b *Block) Data(m *ice.Message, root interface{}) Chart {
b.Text = kit.Select(b.Text, kit.Value(root, "text")) b.Text = kit.Select(b.Text, kit.Value(root, kit.MDB_TEXT))
kit.Fetch(root, func(key string, value string) { kit.Fetch(root, func(key string, value string) {
switch key { switch key {
case "fg": case FG:
b.TextData += kit.Format("%s='%s' ", "fill", value) b.TextData += kit.Format("%s='%s' ", FILL, value)
case "bg": case BG:
b.RectData += kit.Format("%s='%s' ", "fill", value) b.RectData += kit.Format("%s='%s' ", FILL, value)
} }
}) })
kit.Fetch(kit.Value(root, "data"), func(key string, value string) { kit.Fetch(kit.Value(root, "data"), func(key string, value string) {
@ -71,7 +72,7 @@ func (b *Block) Draw(m *ice.Message, x, y int) Chart {
} }
m.Echo(`<rect x="%d" y="%d" width="%d" height="%d" rx="4" ry="4" fill="%s" %v/>`, m.Echo(`<rect x="%d" y="%d" width="%d" height="%d" rx="4" ry="4" fill="%s" %v/>`,
x+b.MarginX/2, y+b.MarginY/2, b.GetWidth(), b.GetHeight(), b.BackGround, b.RectData) x+b.MarginX/2, y+b.MarginY/2, b.GetWidth(), b.GetHeight(), b.BackGround, b.RectData)
m.Echo("\n") m.Echo(ice.NL)
m.Echo(`<text x="%d" y="%d" stroke-width="1" fill="%s" stroke=%s %v>%v</text>`, m.Echo(`<text x="%d" y="%d" stroke-width="1" fill="%s" stroke=%s %v>%v</text>`,
x+b.GetWidths()/2, y+b.GetHeights()/2+float, b.FontColor, b.FontColor, b.TextData, b.Text) x+b.GetWidths()/2, y+b.GetHeights()/2+float, b.FontColor, b.FontColor, b.TextData, b.Text)
m.Echo("\n") m.Echo("\n")
@ -109,19 +110,19 @@ type Label struct {
func (b *Label) Init(m *ice.Message, arg ...string) Chart { func (b *Label) Init(m *ice.Message, arg ...string) Chart {
b.Text = kit.Select(b.Text, arg, 0) b.Text = kit.Select(b.Text, arg, 0)
b.FontSize = kit.Int(m.Option("font-size")) b.FontSize = kit.Int(m.Option(FONT_SIZE))
b.Padding = kit.Int(m.Option("padding")) b.Padding = kit.Int(m.Option(PADDING))
b.MarginX = kit.Int(m.Option("marginx")) b.MarginX = kit.Int(m.Option(MARGINX))
b.MarginY = kit.Int(m.Option("marginy")) b.MarginY = kit.Int(m.Option(MARGINY))
// 解析数据 // 解析数据
b.max = map[int]int{} b.max = map[int]int{}
for _, v := range strings.Split(arg[0], "\n") { for _, v := range strings.Split(arg[0], ice.NL) {
l := kit.Split(v, " ", " ") l := kit.Split(v, ice.SP, ice.SP)
for i, v := range l { for i, v := range l {
switch data := kit.Parse(nil, "", kit.Split(v)...).(type) { switch data := kit.Parse(nil, "", kit.Split(v)...).(type) {
case map[string]interface{}: case map[string]interface{}:
v = kit.Select("", data["text"]) v = kit.Select("", data[kit.MDB_TEXT])
} }
if w := b.GetWidth(v); w > b.max[i] { if w := b.GetWidth(v); w > b.max[i] {
@ -157,9 +158,9 @@ func (b *Label) Draw(m *ice.Message, x, y int) Chart {
if w := kit.Int(kit.Value(order, "index")); w != 0 && i%w == 0 { if w := kit.Int(kit.Value(order, "index")); w != 0 && i%w == 0 {
for k, v := range order { for k, v := range order {
switch k { switch k {
case "fg": case FG:
item.FontColor = kit.Format(v) item.FontColor = kit.Format(v)
case "bg": case BG:
item.BackGround = kit.Format(v) item.BackGround = kit.Format(v)
} }
} }
@ -168,13 +169,13 @@ func (b *Label) Draw(m *ice.Message, x, y int) Chart {
switch data := kit.Parse(nil, "", kit.Split(text)...).(type) { switch data := kit.Parse(nil, "", kit.Split(text)...).(type) {
case map[string]interface{}: case map[string]interface{}:
item.Init(m, kit.Select(text, data["text"])).Data(m, data) item.Init(m, kit.Select(text, data[kit.MDB_TEXT])).Data(m, data)
default: default:
item.Init(m, text) item.Init(m, text)
} }
// 输出 // 输出
switch m.Option("compact") { switch m.Option(COMPACT) {
case "max": case "max":
item.Width = b.Width/len(line) - b.MarginX item.Width = b.Width/len(line) - b.MarginX
case ice.TRUE: case ice.TRUE:
@ -200,10 +201,10 @@ type Chain struct {
} }
func (b *Chain) Init(m *ice.Message, arg ...string) Chart { func (b *Chain) Init(m *ice.Message, arg ...string) Chart {
b.FontSize = kit.Int(m.Option("font-size")) b.FontSize = kit.Int(m.Option(FONT_SIZE))
b.Padding = kit.Int(m.Option("padding")) b.Padding = kit.Int(m.Option(PADDING))
b.MarginX = kit.Int(m.Option("marginx")) b.MarginX = kit.Int(m.Option(MARGINX))
b.MarginY = kit.Int(m.Option("marginy")) b.MarginY = kit.Int(m.Option(MARGINY))
// 解析数据 // 解析数据
b.data = kit.Parse(nil, "", b.show(m, arg[0])...).(map[string]interface{}) b.data = kit.Parse(nil, "", b.show(m, arg[0])...).(map[string]interface{})
@ -222,7 +223,7 @@ func (b *Chain) Draw(m *ice.Message, x, y int) Chart {
} }
func (b *Chain) show(m *ice.Message, str string) (res []string) { func (b *Chain) show(m *ice.Message, str string) (res []string) {
miss := []int{} miss := []int{}
for _, line := range kit.Split(str, "\n", "\n") { for _, line := range kit.Split(str, ice.NL, ice.NL) {
// 计算缩进 // 计算缩进
dep := 0 dep := 0
loop: loop:
@ -269,7 +270,7 @@ func (b *Chain) size(m *ice.Message, root map[string]interface{}, depth int, wid
meta := root[kit.MDB_META].(map[string]interface{}) meta := root[kit.MDB_META].(map[string]interface{})
// 最大宽度 // 最大宽度
if w := b.GetWidths(kit.Format(meta["text"])); w > width[depth] { if w := b.GetWidths(kit.Format(meta[kit.MDB_TEXT])); w > width[depth] {
width[depth] = w width[depth] = w
} }
@ -283,7 +284,7 @@ func (b *Chain) size(m *ice.Message, root map[string]interface{}, depth int, wid
height = 1 height = 1
} }
meta["height"] = height meta[HEIGHT] = height
return height return height
} }
func (b *Chain) draw(m *ice.Message, root map[string]interface{}, depth int, width map[int]int, x, y int, p *Block) int { func (b *Chain) draw(m *ice.Message, root map[string]interface{}, depth int, width map[int]int, x, y int, p *Block) int {
@ -292,19 +293,19 @@ func (b *Chain) draw(m *ice.Message, root map[string]interface{}, depth int, wid
// 当前节点 // 当前节点
item := &Block{ item := &Block{
BackGround: kit.Select(b.BackGround, kit.Select(p.BackGround, meta["bg"])), BackGround: kit.Select(b.BackGround, kit.Select(p.BackGround, meta[BG])),
FontColor: kit.Select(b.FontColor, kit.Select(p.FontColor, meta["fg"])), FontColor: kit.Select(b.FontColor, kit.Select(p.FontColor, meta[FG])),
FontSize: b.FontSize, FontSize: b.FontSize,
Padding: b.Padding, Padding: b.Padding,
MarginX: b.MarginX, MarginX: b.MarginX,
MarginY: b.MarginY, MarginY: b.MarginY,
} }
if m.Option("compact") != ice.TRUE { if m.Option(COMPACT) != ice.TRUE {
item.Width = b.max[depth] item.Width = b.max[depth]
} }
item.x = x item.x = x
item.y = y + (kit.Int(meta["height"])-1)*b.GetHeights()/2 item.y = y + (kit.Int(meta[HEIGHT])-1)*b.GetHeights()/2
item.Init(m, kit.Format(meta["text"])).Data(m, meta) item.Init(m, kit.Format(meta[kit.MDB_TEXT])).Data(m, meta)
item.Draw(m, item.x, item.y) item.Draw(m, item.x, item.y)
if p != nil && p.y != 0 { if p != nil && p.y != 0 {
@ -328,35 +329,6 @@ func (b *Chain) draw(m *ice.Message, root map[string]interface{}, depth int, wid
return h return h
} }
// 栈
func Stack(m *ice.Message, name string, level int, data interface{}) {
style := []string{}
kit.Fetch(kit.Value(data, "meta"), func(key string, value string) {
switch key {
case "bg":
style = append(style, "background:"+value)
case "fg":
style = append(style, "color:"+value)
}
})
l, ok := kit.Value(data, "list").([]interface{})
if !ok || len(l) == 0 {
m.Echo(`<div class="%s" style="%s"><span class="state">o</span> %s</div>`, name, strings.Join(style, ";"), kit.Value(data, "meta.text"))
return
}
m.Echo(`<div class="%s %s" style="%s"><span class="state">%s</span> %s</div>`,
kit.Select("span", "fold", level > 2), name, strings.Join(style, ";"), kit.Select("v", ">", level > 2), kit.Value(data, "meta.text"))
m.Echo("<ul class='%s' %s>", name, kit.Select("", `style="display:none"`, level > 2))
kit.Fetch(kit.Value(data, "list"), func(index int, value map[string]interface{}) {
m.Echo("<li>")
Stack(m, name, level+1, value)
m.Echo("</li>")
})
m.Echo("</ul>")
}
func _chart_show(m *ice.Message, kind, text string, arg ...string) { func _chart_show(m *ice.Message, kind, text string, arg ...string) {
var chart Chart var chart Chart
switch kind { switch kind {
@ -367,34 +339,34 @@ func _chart_show(m *ice.Message, kind, text string, arg ...string) {
} }
// 扩展参数 // 扩展参数
m.Option("font-size", "24") m.Option(FONT_SIZE, "24")
m.Option("stroke", "blue") m.Option(STROKE, cli.BLUE)
m.Option("fill", "yellow") m.Option(FILL, cli.YELLOW)
// 扩展参数 // 扩展参数
m.Option("style", "") m.Option(STYLE, "")
m.Option("stroke-width", "2") m.Option(STROKE_WIDTH, "2")
m.Option("font-family", "monospace") m.Option(FONT_FAMILY, "monospace")
// 扩展参数 // 扩展参数
m.Option("compact", ice.FALSE) m.Option(COMPACT, ice.FALSE)
m.Option("padding", "10") m.Option(PADDING, "10")
m.Option("marginx", "10") m.Option(MARGINX, "10")
m.Option("marginy", "10") m.Option(MARGINY, "10")
// m.Option("font-family", kit.Select("", "monospace", len(text) == len([]rune(text)))) // m.Option("font-family", kit.Select("", "monospace", len(text) == len([]rune(text))))
for i := 0; i < len(arg)-1; i++ { for i := 0; i < len(arg)-1; i++ {
m.Option(arg[i], arg[i+1]) m.Option(arg[i], arg[i+1])
} }
if m.Option("bg") != "" { if m.Option(BG) != "" {
m.Option("fill", m.Option("bg")) m.Option(FILL, m.Option(BG))
} }
if m.Option("fg") != "" { if m.Option(FG) != "" {
m.Option("stroke", m.Option("fg")) m.Option(STROKE, m.Option(FG))
} }
// 计算尺寸 // 计算尺寸
chart.Init(m, text) chart.Init(m, text)
m.Option("width", chart.GetWidth()) m.Option(WIDTH, chart.GetWidth())
m.Option("height", chart.GetHeight()) m.Option(HEIGHT, chart.GetHeight())
// 渲染引擎 // 渲染引擎
_wiki_template(m, CHART, "", text) _wiki_template(m, CHART, "", text)
@ -403,19 +375,36 @@ func _chart_show(m *ice.Message, kind, text string, arg ...string) {
} }
const ( const (
FG = "fg"
BG = "bg"
FILL = "fill"
STROKE = "stroke"
STYLE = "style"
WIDTH = "width"
HEIGHT = "height"
PADDING = "padding"
MARGINX = "marginx"
MARGINY = "marginy"
FONT_SIZE = "font-size"
FONT_FAMILY = "font-family"
STROKE_WIDTH = "stroke-width"
COMPACT = "compact"
LABEL = "label" LABEL = "label"
CHAIN = "chain" CHAIN = "chain"
) )
const CHART = "chart" const CHART = "chart"
func init() { func init() {
Index.Merge(&ice.Context{ Index.Merge(&ice.Context{Commands: map[string]*ice.Command{
Commands: map[string]*ice.Command{
CHART: {Name: "chart label|chain text", Help: "图表", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { CHART: {Name: "chart label|chain text", Help: "图表", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
_chart_show(m, arg[0], strings.TrimSpace(arg[1]), arg[2:]...) _chart_show(m, arg[0], strings.TrimSpace(arg[1]), arg[2:]...)
}}, }},
}, }, Configs: map[string]*ice.Config{
Configs: map[string]*ice.Config{
CHART: {Name: CHART, Help: "图表", Value: kit.Data( CHART: {Name: CHART, Help: "图表", Value: kit.Data(
kit.MDB_TEMPLATE, `<svg {{.OptionTemplate}} kit.MDB_TEMPLATE, `<svg {{.OptionTemplate}}
vertion="1.1" xmlns="http://www.w3.org/2000/svg" dominant-baseline="middle" text-anchor="middle" vertion="1.1" xmlns="http://www.w3.org/2000/svg" dominant-baseline="middle" text-anchor="middle"
@ -424,6 +413,5 @@ stroke-width="{{.Option "stroke-width"}}" font-family="{{.Option "font-family"}}
width="{{.Option "width"}}" height="{{.Option "height"}}" width="{{.Option "width"}}" height="{{.Option "height"}}"
>`, >`,
)}, )},
}, }})
})
} }

View File

@ -9,24 +9,21 @@ import (
const DATA = "data" const DATA = "data"
func init() { func init() {
Index.Merge(&ice.Context{ Index.Merge(&ice.Context{Configs: map[string]*ice.Config{
Configs: map[string]*ice.Config{
DATA: {Name: DATA, Help: "数据表格", Value: kit.Data( DATA: {Name: DATA, Help: "数据表格", Value: kit.Data(
kit.MDB_PATH, ice.USR_LOCAL_EXPORT, kit.MDB_REGEXP, ".*\\.csv", kit.MDB_PATH, ice.USR_LOCAL_EXPORT, kit.MDB_REGEXP, ".*\\.csv",
)}, )},
}, }, Commands: map[string]*ice.Command{
Commands: map[string]*ice.Command{
DATA: {Name: "data path auto", Help: "数据表格", Meta: kit.Dict( DATA: {Name: "data path auto", Help: "数据表格", Meta: kit.Dict(
ice.Display("/plugin/local/wiki/data.js"), ice.Display("/plugin/local/wiki/data.js"),
), Action: map[string]*ice.Action{ ), Action: map[string]*ice.Action{
nfs.SAVE: {Name: "save path text", Help: "保存", Hand: func(m *ice.Message, arg ...string) { nfs.SAVE: {Name: "save path text", Help: "保存", Hand: func(m *ice.Message, arg ...string) {
_wiki_save(m, DATA, arg[0], arg[1]) _wiki_save(m, m.CommandKey(), arg[0], arg[1])
}}, }},
}, 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, DATA, kit.Select("./", arg, 0)) { if !_wiki_list(m, m.CommandKey(), kit.Select("./", arg, 0)) {
m.CSV(m.Cmd(nfs.CAT, arg[0]).Result()) m.CSV(m.Cmd(nfs.CAT, arg[0]).Result())
} }
}}, }},
}, }})
})
} }

View File

@ -11,13 +11,11 @@ import (
const DRAW = "draw" const DRAW = "draw"
func init() { func init() {
Index.Merge(&ice.Context{ Index.Merge(&ice.Context{Configs: map[string]*ice.Config{
Configs: map[string]*ice.Config{
DRAW: {Name: DRAW, Help: "思维导图", Value: kit.Data( DRAW: {Name: DRAW, Help: "思维导图", Value: kit.Data(
kit.MDB_PATH, "", kit.MDB_REGEXP, ".*\\.svg", kit.MDB_PATH, "", kit.MDB_REGEXP, ".*\\.svg",
)}, )},
}, }, Commands: map[string]*ice.Command{
Commands: map[string]*ice.Command{
DRAW: {Name: "draw path=src/main.svg refresh:button=auto 编辑 save 项目 参数", Help: "思维导图", Meta: kit.Dict( DRAW: {Name: "draw path=src/main.svg refresh:button=auto 编辑 save 项目 参数", Help: "思维导图", Meta: kit.Dict(
ice.Display("/plugin/local/wiki/draw.js"), ice.Display("/plugin/local/wiki/draw.js"),
), Action: map[string]*ice.Action{ ), Action: map[string]*ice.Action{
@ -29,6 +27,5 @@ func init() {
_wiki_show(m, DRAW, path.Join(arg...)) _wiki_show(m, DRAW, path.Join(arg...))
} }
}}, }},
}, }})
})
} }

View File

@ -9,22 +9,19 @@ import (
const FEEL = "feel" const FEEL = "feel"
func init() { func init() {
Index.Merge(&ice.Context{ Index.Merge(&ice.Context{Configs: map[string]*ice.Config{
Configs: map[string]*ice.Config{
FEEL: {Name: FEEL, Help: "影音媒体", Value: kit.Data( FEEL: {Name: FEEL, Help: "影音媒体", Value: kit.Data(
kit.MDB_PATH, ice.USR_LOCAL_IMAGE, kit.MDB_REGEXP, ".*.(png|PNG|jpg|JPG|jpeg|mp4|m4v|MOV)", kit.MDB_PATH, ice.USR_LOCAL_IMAGE, kit.MDB_REGEXP, ".*.(png|PNG|jpg|JPG|jpeg|mp4|m4v|MOV)",
)}, )},
}, }, Commands: map[string]*ice.Command{
Commands: map[string]*ice.Command{
FEEL: {Name: "feel path auto upload 上一页 下一页 参数", Help: "影音媒体", Meta: kit.Dict( FEEL: {Name: "feel path auto upload 上一页 下一页 参数", Help: "影音媒体", Meta: kit.Dict(
ice.Display("/plugin/local/wiki/feel.js"), ice.Display("/plugin/local/wiki/feel.js"),
), Action: map[string]*ice.Action{ ), Action: map[string]*ice.Action{
web.UPLOAD: {Name: "upload", Help: "上传", Hand: func(m *ice.Message, arg ...string) { web.UPLOAD: {Name: "upload", Help: "上传", Hand: func(m *ice.Message, arg ...string) {
_wiki_upload(m, FEEL, m.Option(kit.MDB_PATH)) _wiki_upload(m, m.CommandKey(), m.Option(kit.MDB_PATH))
}}, }},
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { }, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
_wiki_list(m, FEEL, kit.Select("./", arg, 0)) _wiki_list(m, m.CommandKey(), kit.Select("./", arg, 0))
}}, }},
}, }})
})
} }

View File

@ -37,7 +37,7 @@ func _field_show(m *ice.Message, name, text string, arg ...string) {
} }
}) })
name = strings.ReplaceAll(name, " ", "_") name = strings.ReplaceAll(name, ice.SP, "_")
meta[kit.MDB_NAME] = name meta[kit.MDB_NAME] = name
meta[kit.MDB_INDEX] = text meta[kit.MDB_INDEX] = text
@ -96,20 +96,18 @@ const (
const FIELD = "field" const FIELD = "field"
func init() { func init() {
Index.Merge(&ice.Context{ Index.Merge(&ice.Context{Commands: map[string]*ice.Command{
Commands: map[string]*ice.Command{
FIELD: {Name: "field [name] cmd", Help: "插件", Action: map[string]*ice.Action{ FIELD: {Name: "field [name] cmd", Help: "插件", Action: map[string]*ice.Action{
ice.RUN: {Name: "run", Help: "执行", Hand: func(m *ice.Message, arg ...string) { ice.RUN: {Name: "run", Help: "执行", Hand: func(m *ice.Message, arg ...string) {
m.Cmdy(arg) m.Cmdy(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 arg = _name(m, arg); strings.Contains(arg[1], "\n") { if arg = _name(m, arg); strings.Contains(arg[1], ice.NL) {
arg = append([]string{arg[0], "web.chat.div", "auto.cmd", "make", "opts.line", arg[1]}, arg[2:]...) arg = append([]string{arg[0], "web.chat.div", "auto.cmd", "split", "opts.text", arg[1]}, arg[2:]...)
} }
_field_show(m, arg[0], arg[1], arg[2:]...) _field_show(m, arg[0], arg[1], arg[2:]...)
}}, }},
}, }, Configs: map[string]*ice.Config{
Configs: map[string]*ice.Config{
FIELD: {Name: FIELD, Help: "插件", Value: kit.Data( FIELD: {Name: FIELD, Help: "插件", Value: kit.Data(
kit.MDB_TEMPLATE, `<fieldset {{.OptionTemplate}}" data-meta='{{.Optionv "meta"|Format}}'> kit.MDB_TEMPLATE, `<fieldset {{.OptionTemplate}}" data-meta='{{.Optionv "meta"|Format}}'>
<legend>{{.Option "name"}}</legend> <legend>{{.Option "name"}}</legend>
@ -119,6 +117,5 @@ func init() {
<div class="status"></div> <div class="status"></div>
</fieldset>`, </fieldset>`,
)}, )},
}, }})
})
} }

View File

@ -20,8 +20,7 @@ const (
const IMAGE = "image" const IMAGE = "image"
func init() { func init() {
Index.Merge(&ice.Context{ Index.Merge(&ice.Context{Commands: map[string]*ice.Command{
Commands: map[string]*ice.Command{
ice.CTX_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { 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.Cmd(mdb.RENDER, mdb.CREATE, PNG, m.Prefix(IMAGE))
}}, }},
@ -32,12 +31,10 @@ func init() {
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { }, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
_image_show(m, arg[0], arg[1:]...) _image_show(m, arg[0], arg[1:]...)
}}, }},
}, }, Configs: map[string]*ice.Config{
Configs: map[string]*ice.Config{
IMAGE: {Name: IMAGE, Help: "图片", Value: kit.Data( IMAGE: {Name: IMAGE, Help: "图片", Value: kit.Data(
kit.MDB_TEMPLATE, `<img {{.OptionTemplate}} title="{{.Option "text"}}" src="{{.Option "text"}}">`, kit.MDB_TEMPLATE, `<img {{.OptionTemplate}} title="{{.Option "text"}}" src="{{.Option "text"}}">`,
kit.MDB_PATH, ice.USR_LOCAL_IMAGE, kit.MDB_PATH, ice.USR_LOCAL_IMAGE,
)}, )},
}, }})
})
} }

View File

@ -50,14 +50,14 @@ func _json_show(m *ice.Message, data interface{}) {
const JSON = "json" const JSON = "json"
func init() { func init() {
Index.Merge(&ice.Context{ Index.Merge(&ice.Context{Configs: map[string]*ice.Config{
Configs: map[string]*ice.Config{
JSON: {Name: JSON, Help: "数据结构", Value: kit.Data( JSON: {Name: JSON, Help: "数据结构", Value: kit.Data(
kit.MDB_PATH, ice.USR_LOCAL_EXPORT, kit.MDB_REGEXP, ".*\\.json", kit.MDB_PATH, ice.USR_LOCAL_EXPORT, kit.MDB_REGEXP, ".*\\.json",
)}, )},
}, }, Commands: map[string]*ice.Command{
Commands: map[string]*ice.Command{ JSON: {Name: "json path auto", Help: "数据结构", Meta: kit.Dict(
JSON: {Name: "json path auto", Help: "数据结构", Meta: kit.Dict(ice.Display("/plugin/local/wiki/json.js")), Action: map[string]*ice.Action{ ice.Display("/plugin/local/wiki/json.js"),
), Action: map[string]*ice.Action{
nfs.SAVE: {Name: "save path text", Help: "保存", Hand: func(m *ice.Message, arg ...string) { nfs.SAVE: {Name: "save path text", Help: "保存", Hand: func(m *ice.Message, arg ...string) {
_wiki_save(m, JSON, arg[0], arg[1]) _wiki_save(m, JSON, arg[0], arg[1])
}}, }},
@ -74,6 +74,5 @@ func init() {
m.Cmdy(nfs.CAT, arg[0]) m.Cmdy(nfs.CAT, arg[0])
} }
}}, }},
}, }})
})
} }

View File

@ -14,17 +14,14 @@ func _local_show(m *ice.Message, name, text string, arg ...string) {
const LOCAL = "local" const LOCAL = "local"
func init() { func init() {
Index.Merge(&ice.Context{ Index.Merge(&ice.Context{Commands: map[string]*ice.Command{
Commands: map[string]*ice.Command{
LOCAL: {Name: "local [name] file", Help: "文件", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { LOCAL: {Name: "local [name] file", Help: "文件", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
arg = _name(m, arg) arg = _name(m, arg)
_local_show(m, arg[0], kit.Select(arg[0], arg[1]), arg[2:]...) _local_show(m, arg[0], kit.Select(arg[0], arg[1]), arg[2:]...)
}}, }},
}, }, Configs: map[string]*ice.Config{
Configs: map[string]*ice.Config{
LOCAL: {Name: LOCAL, Help: "文件", Value: kit.Data( LOCAL: {Name: LOCAL, Help: "文件", Value: kit.Data(
kit.MDB_TEMPLATE, `<code {{.OptionTemplate}}>{{range $index, $value := .Optionv "input"}}{{$value}}{{end}}</code>`, kit.MDB_TEMPLATE, `<code {{.OptionTemplate}}>{{range $index, $value := .Optionv "input"}}{{$value}}{{end}}</code>`,
)}, )},
}, }})
})
} }

View File

@ -15,16 +15,13 @@ func _order_show(m *ice.Message, text string, arg ...string) {
const ORDER = "order" const ORDER = "order"
func init() { func init() {
Index.Merge(&ice.Context{ Index.Merge(&ice.Context{Commands: map[string]*ice.Command{
Commands: map[string]*ice.Command{
ORDER: {Name: "order `[item\n]...`", Help: "列表", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { ORDER: {Name: "order `[item\n]...`", Help: "列表", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
_order_show(m, arg[0], arg[1:]...) _order_show(m, arg[0], arg[1:]...)
}}, }},
}, }, Configs: map[string]*ice.Config{
Configs: map[string]*ice.Config{
ORDER: {Name: ORDER, Help: "列表", Value: kit.Data( ORDER: {Name: ORDER, Help: "列表", Value: kit.Data(
kit.MDB_TEMPLATE, `<ul {{.OptionTemplate}}>{{range $index, $value := .Optionv "list"}}<li>{{$value}}</li>{{end}}</ul>`, kit.MDB_TEMPLATE, `<ul {{.OptionTemplate}}>{{range $index, $value := .Optionv "list"}}<li>{{$value}}</li>{{end}}</ul>`,
)}, )},
}, }})
})
} }

View File

@ -24,16 +24,13 @@ func _refer_show(m *ice.Message, text string, arg ...string) {
const REFER = "refer" const REFER = "refer"
func init() { func init() {
Index.Merge(&ice.Context{ Index.Merge(&ice.Context{Commands: map[string]*ice.Command{
Commands: map[string]*ice.Command{
REFER: {Name: "refer `[[name] url\n]...`", Help: "参考", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { REFER: {Name: "refer `[[name] url\n]...`", Help: "参考", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
_refer_show(m, arg[0], arg[1:]...) _refer_show(m, arg[0], arg[1:]...)
}}, }},
}, }, Configs: map[string]*ice.Config{
Configs: map[string]*ice.Config{
REFER: {Name: REFER, Help: "参考", Value: kit.Data( REFER: {Name: REFER, Help: "参考", Value: kit.Data(
kit.MDB_TEMPLATE, `<ul {{.OptionTemplate}}>{{range $index, $value := .Optionv "list"}}<li>{{index $value 0}}: <a href="{{index $value 1}}" target="_blank">{{index $value 1}}</a></li>{{end}}</ul>`, kit.MDB_TEMPLATE, `<ul {{.OptionTemplate}}>{{range $index, $value := .Optionv "list"}}<li>{{index $value 0}}: <a href="{{index $value 1}}" target="_blank">{{index $value 1}}</a></li>{{end}}</ul>`,
)}, )},
}, }})
})
} }

View File

@ -18,18 +18,15 @@ const (
const SHELL = "shell" const SHELL = "shell"
func init() { func init() {
Index.Merge(&ice.Context{ Index.Merge(&ice.Context{Commands: map[string]*ice.Command{
Commands: map[string]*ice.Command{
SHELL: {Name: "shell [name] cmd", Help: "命令", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { SHELL: {Name: "shell [name] cmd", Help: "命令", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
arg = _name(m, arg) arg = _name(m, arg)
_shell_show(m, arg[0], kit.Select(arg[0], arg[1]), arg[2:]...) _shell_show(m, arg[0], kit.Select(arg[0], arg[1]), arg[2:]...)
}}, }},
}, }, Configs: map[string]*ice.Config{
Configs: map[string]*ice.Config{
SHELL: {Name: SHELL, Help: "命令", Value: kit.Data( SHELL: {Name: SHELL, Help: "命令", Value: kit.Data(
kit.MDB_TEMPLATE, `<code {{.OptionTemplate}}>$ {{.Option "input"}} # {{.Option "name"}} kit.MDB_TEMPLATE, `<code {{.OptionTemplate}}>$ {{.Option "input"}} # {{.Option "name"}}
{{.Option "output"}}</code>`, {{.Option "output"}}</code>`,
)}, )},
}, }})
})
} }

View File

@ -14,7 +14,7 @@ func _spark_show(m *ice.Message, name, text string, arg ...string) {
return return
} }
prompt := kit.Select(name+"> ", m.Conf(SPARK, kit.Keym(ssh.PROMPT, name))) prompt := kit.Select(name+"> ", m.Config(kit.Keys(ssh.PROMPT, name)))
m.Echo(`<div class="story" data-type="spark" data-name="%s">`, name) m.Echo(`<div class="story" data-type="spark" data-name="%s">`, name)
defer m.Echo("</div>") defer m.Echo("</div>")
@ -23,7 +23,7 @@ func _spark_show(m *ice.Message, name, text string, arg ...string) {
return return
} }
for _, l := range strings.Split(text, "\n") { for _, l := range strings.Split(text, ice.NL) {
m.Echo("<div>") m.Echo("<div>")
m.Echo("<label>").Echo(prompt).Echo("</label>") m.Echo("<label>").Echo(prompt).Echo("</label>")
m.Echo("<span>").Echo(l).Echo("</span>") m.Echo("<span>").Echo(l).Echo("</span>")
@ -33,28 +33,23 @@ func _spark_show(m *ice.Message, name, text string, arg ...string) {
const ( const (
PROMPT = "prompt" PROMPT = "prompt"
) BREAK = "break"
const (
SSH_SHELL = "shell"
SSH_BREAK = "break"
) )
const SPARK = "spark" const SPARK = "spark"
func init() { func init() {
Index.Merge(&ice.Context{ Index.Merge(&ice.Context{Commands: map[string]*ice.Command{
Commands: map[string]*ice.Command{
ice.CTX_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { ice.CTX_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
ice.AddRender(ice.RENDER_SCRIPT, func(m *ice.Message, cmd string, args ...interface{}) string { ice.AddRender(ice.RENDER_SCRIPT, func(m *ice.Message, cmd string, args ...interface{}) string {
arg := kit.Simple(args...) arg := kit.Simple(args...)
if len(arg) == 1 && arg[0] != SSH_BREAK { if len(arg) == 1 && arg[0] != BREAK {
arg = []string{SSH_SHELL, arg[0]} arg = []string{SHELL, arg[0]}
} }
list := []string{kit.Format(`<div class="story" data-type="spark" data-name="%s">`, arg[0])} list := []string{kit.Format(`<div class="story" data-type="spark" data-name="%s">`, arg[0])}
for _, l := range strings.Split(strings.Join(arg[1:], "\n"), "\n") { for _, l := range strings.Split(strings.Join(arg[1:], ice.NL), ice.NL) {
switch list = append(list, "<div>"); arg[0] { switch list = append(list, "<div>"); arg[0] {
case SSH_SHELL: case SHELL:
list = append(list, "<label>", "$ ", "</label>") list = append(list, "<label>", "$ ", "</label>")
default: default:
list = append(list, "<label>", "&gt; ", "</label>") list = append(list, "<label>", "&gt; ", "</label>")
@ -75,12 +70,10 @@ func init() {
arg = _name(m, arg) arg = _name(m, arg)
_spark_show(m, arg[0], strings.TrimSpace(arg[1]), arg[2:]...) _spark_show(m, arg[0], strings.TrimSpace(arg[1]), arg[2:]...)
}}, }},
}, }, Configs: map[string]*ice.Config{
Configs: map[string]*ice.Config{
SPARK: {Name: SPARK, Help: "段落", Value: kit.Data( SPARK: {Name: SPARK, Help: "段落", Value: kit.Data(
kit.MDB_TEMPLATE, `<p {{.OptionTemplate}}>{{.Option "text"}}</p>`, kit.MDB_TEMPLATE, `<p {{.OptionTemplate}}>{{.Option "text"}}</p>`,
ssh.PROMPT, kit.Dict("shell", "$ "), ssh.PROMPT, kit.Dict(SHELL, "$ "),
)}, )},
}, }})
})
} }

View File

@ -38,9 +38,9 @@ func _table_show(m *ice.Message, text string, arg ...string) {
style := []string{} style := []string{}
for i := 1; i < len(ls)-1; i += 2 { for i := 1; i < len(ls)-1; i += 2 {
switch ls[i] { switch ls[i] {
case "bg": case BG:
ls[i] = "background-color" ls[i] = "background-color"
case "fg": case FG:
ls[i] = "color" ls[i] = "color"
} }
style = append(style, ls[i]+":"+ls[i+1]) style = append(style, ls[i]+":"+ls[i+1])
@ -60,8 +60,7 @@ func _table_show(m *ice.Message, text string, arg ...string) {
const TABLE = "table" 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: "表格", Action: map[string]*ice.Action{ TABLE: {Name: "table `[item item\n]...`", Help: "表格", Action: map[string]*ice.Action{
ice.RUN: {Name: "run", Help: "执行", Hand: func(m *ice.Message, arg ...string) { ice.RUN: {Name: "run", Help: "执行", Hand: func(m *ice.Message, arg ...string) {
_table_run(m, arg...) _table_run(m, arg...)
@ -69,8 +68,7 @@ func init() {
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { }, 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:]...)
}}, }},
}, }, Configs: map[string]*ice.Config{
Configs: map[string]*ice.Config{
TABLE: {Name: TABLE, Help: "表格", Value: kit.Data( TABLE: {Name: TABLE, Help: "表格", Value: kit.Data(
kit.MDB_TEMPLATE, `<table {{.OptionTemplate}}> kit.MDB_TEMPLATE, `<table {{.OptionTemplate}}>
<tr>{{range $i, $v := .Optionv "head"}}<th>{{$v}}</th>{{end}}</tr> <tr>{{range $i, $v := .Optionv "head"}}<th>{{$v}}</th>{{end}}</tr>
@ -79,6 +77,5 @@ func init() {
{{end}} {{end}}
</table>`, </table>`,
)}, )},
}, }})
})
} }

View File

@ -36,14 +36,11 @@ func _title_parse(m *ice.Message, dir string, root map[string]interface{}, list
ls[1] = path.Join(dir, ls[1]) ls[1] = path.Join(dir, ls[1])
} }
meta := kit.Dict( meta := kit.Dict(kit.MDB_NAME, kit.Select("", ls, 0), kit.MDB_LINK, kit.Select("", ls, 1))
"name", kit.Select("", ls, 0),
"link", kit.Select("", ls, 1),
)
for i := 2; i < len(ls); i += 2 { for i := 2; i < len(ls); i += 2 {
meta[ls[i]] = ls[i+1] meta[ls[i]] = ls[i+1]
} }
last = kit.Dict("meta", meta, "list", kit.List()) last = kit.Data(meta)
kit.Value(root, "list.-2", last) kit.Value(root, "list.-2", last)
} }
return len(list) return len(list)
@ -53,19 +50,19 @@ func _title_show(m *ice.Message, kind, text string, arg ...string) {
switch title, _ := m.Optionv(TITLE).(map[string]int); kind { switch title, _ := m.Optionv(TITLE).(map[string]int); kind {
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.Data()
_title_parse(m, path.Dir(m.Option(ice.MSG_SCRIPT)), 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
case PREMENU: // 前置目录 case PREMENU: // 前置目录
_option(m, kind, "", "", arg...) _option(m, kind, "", "", arg...)
m.RenderTemplate(m.Conf(TITLE, kit.Keym(kind))) m.RenderTemplate(m.Config(kind))
return return
case ENDMENU: // 后置目录 case ENDMENU: // 后置目录
_option(m, kind, "", "", arg...) _option(m, kind, "", "", arg...)
m.RenderTemplate(m.Conf(TITLE, kit.Keym(kind))) m.RenderTemplate(m.Config(kind))
return return
case SECTION: // 分节标题 case SECTION: // 分节标题
@ -104,7 +101,7 @@ const TITLE = "title"
func init() { func init() {
Index.Merge(&ice.Context{Commands: map[string]*ice.Command{ Index.Merge(&ice.Context{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) { TITLE: {Name: "title [navmenu|premenu|chapter|section|endmenu] text", Help: "标题", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
if len(arg) == 0 { if len(arg) == 0 {
ns := kit.Split(ice.Info.NodeName, "-") ns := kit.Split(ice.Info.NodeName, "-")
arg = append(arg, ns[len(ns)-1]) arg = append(arg, ns[len(ns)-1])

View File

@ -21,8 +21,7 @@ const (
const VIDEO = "video" const VIDEO = "video"
func init() { func init() {
Index.Merge(&ice.Context{ Index.Merge(&ice.Context{Commands: map[string]*ice.Command{
Commands: map[string]*ice.Command{
VIDEO: {Name: "video url", Help: "视频", Action: map[string]*ice.Action{ VIDEO: {Name: "video url", Help: "视频", Action: map[string]*ice.Action{
mdb.RENDER: {Name: "render", Help: "渲染", Hand: func(m *ice.Message, arg ...string) { mdb.RENDER: {Name: "render", Help: "渲染", Hand: func(m *ice.Message, arg ...string) {
_video_show(m, path.Join(arg[2], arg[1])) _video_show(m, path.Join(arg[2], arg[1]))
@ -30,12 +29,10 @@ func init() {
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { }, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
_video_show(m, arg[0], arg[1:]...) _video_show(m, arg[0], arg[1:]...)
}}, }},
}, }, Configs: map[string]*ice.Config{
Configs: map[string]*ice.Config{
VIDEO: {Name: "video", Help: "视频", Value: kit.Data( VIDEO: {Name: "video", Help: "视频", Value: kit.Data(
kit.MDB_TEMPLATE, `<video {{.OptionTemplate}} title="{{.Option "text"}}" src="{{.Option "text"}}" controls></video>`, kit.MDB_TEMPLATE, `<video {{.OptionTemplate}} title="{{.Option "text"}}" src="{{.Option "text"}}" controls></video>`,
kit.MDB_PATH, ice.USR_LOCAL_IMAGE, kit.MDB_PATH, ice.USR_LOCAL_IMAGE,
)}, )},
}, }})
})
} }

View File

@ -10,18 +10,36 @@ import (
kit "shylinux.com/x/toolkits" kit "shylinux.com/x/toolkits"
) )
func _name(m *ice.Message, arg []string) []string {
if len(arg) == 1 {
return []string{"", arg[0]}
}
return arg
}
func _option(m *ice.Message, kind, name, text string, arg ...string) {
m.Option(kit.MDB_TYPE, kind)
m.Option(kit.MDB_NAME, name)
m.Option(kit.MDB_TEXT, text)
extra := kit.Dict()
m.Optionv(kit.MDB_EXTRA, extra)
for i := 0; i < len(arg); i += 2 {
extra[arg[i]] = kit.Format(kit.Parse(nil, "", kit.Split(arg[i+1])...))
}
}
func _wiki_path(m *ice.Message, cmd string, arg ...string) string { 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...)) return path.Join(m.Option(ice.MSG_LOCAL), m.Conf(cmd, kit.Keym(nfs.PATH)), path.Join(arg...))
} }
func _wiki_link(m *ice.Message, cmd string, text string) string { func _wiki_link(m *ice.Message, cmd string, text string) string {
if !strings.HasPrefix(text, "http") && !strings.HasPrefix(text, "/") { if !strings.HasPrefix(text, "http") && !strings.HasPrefix(text, ice.PS) {
text = path.Join("/share/local", _wiki_path(m, cmd, text)) text = path.Join("/share/local", _wiki_path(m, cmd, text))
} }
return text return text
} }
func _wiki_list(m *ice.Message, cmd string, arg ...string) bool { func _wiki_list(m *ice.Message, cmd string, arg ...string) bool {
m.Option(nfs.DIR_ROOT, _wiki_path(m, cmd)) m.Option(nfs.DIR_ROOT, _wiki_path(m, cmd))
if len(arg) == 0 || strings.HasSuffix(arg[0], "/") { if len(arg) == 0 || strings.HasSuffix(arg[0], ice.PS) {
if m.Option(nfs.DIR_DEEP) != ice.TRUE { // 目录列表 if m.Option(nfs.DIR_DEEP) != ice.TRUE { // 目录列表
m.Option(nfs.DIR_TYPE, nfs.DIR) m.Option(nfs.DIR_TYPE, nfs.DIR)
m.Cmdy(nfs.DIR, kit.Select("./", arg, 0)) m.Cmdy(nfs.DIR, kit.Select("./", arg, 0))
@ -52,20 +70,13 @@ func _wiki_template(m *ice.Message, cmd string, name, text string, arg ...string
const WIKI = "wiki" const WIKI = "wiki"
var Index = &ice.Context{Name: WIKI, Help: "文档中心", Commands: map[string]*ice.Command{ var Index = &ice.Context{Name: WIKI, Help: "文档中心"}
ice.CTX_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
m.Load()
}},
ice.CTX_EXIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
m.Save()
}},
}}
func init() { func init() {
web.Index.Register(Index, &web.Frame{}, web.Index.Register(Index, &web.Frame{},
FEEL, WORD, DATA, DRAW, TITLE, BRIEF, REFER, SPARK, CHART,
TITLE, BRIEF, REFER, SPARK, ORDER, TABLE, IMAGE, VIDEO,
ORDER, TABLE, CHART, IMAGE, VIDEO,
FIELD, SHELL, LOCAL, PARSE, FIELD, SHELL, LOCAL, PARSE,
FEEL, DRAW, WORD, DATA,
) )
} }

View File

@ -1,29 +1,26 @@
title.go title.go
brief.go brief.go
refer.go refer.go
spark.go spark.go
chart.go
order.go order.go
table.go table.go
chart.go
image.go image.go
video.go video.go
poems.go
field.go field.go
shell.go shell.go
local.go local.go
parse.go parse.go
data.go
draw.go
feel.go feel.go
draw.go
word.go word.go
data.go
json.go
wiki.go wiki.go
wiki.shy wiki.shy
field "影音" web.wiki.feel
field "数据" web.wiki.data
field "文档" web.wiki.word
field "绘图" web.wiki.draw

View File

@ -1,9 +1,6 @@
package wiki package wiki
import ( import (
"net/http"
"strings"
ice "shylinux.com/x/icebergs" ice "shylinux.com/x/icebergs"
"shylinux.com/x/icebergs/base/ctx" "shylinux.com/x/icebergs/base/ctx"
"shylinux.com/x/icebergs/base/nfs" "shylinux.com/x/icebergs/base/nfs"
@ -12,24 +9,6 @@ import (
kit "shylinux.com/x/toolkits" kit "shylinux.com/x/toolkits"
) )
func _name(m *ice.Message, arg []string) []string {
if len(arg) == 1 {
return []string{"", arg[0]}
}
return arg
}
func _option(m *ice.Message, kind, name, text string, arg ...string) {
m.Option(kit.MDB_TYPE, kind)
m.Option(kit.MDB_NAME, name)
m.Option(kit.MDB_TEXT, text)
extra := kit.Dict()
m.Optionv(kit.MDB_EXTRA, extra)
for i := 0; i < len(arg); i += 2 {
extra[arg[i]] = kit.Format(kit.Parse(nil, "", kit.Split(arg[i+1])...))
}
}
func _word_show(m *ice.Message, name string, arg ...string) { func _word_show(m *ice.Message, name string, arg ...string) {
m.Set(ice.MSG_RESULT) m.Set(ice.MSG_RESULT)
m.Option(TITLE, map[string]int{}) m.Option(TITLE, map[string]int{})
@ -40,11 +19,6 @@ func _word_show(m *ice.Message, name string, arg ...string) {
m.Cmdy(ssh.SOURCE, name) m.Cmdy(ssh.SOURCE, name)
} }
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" const WORD = "word"
func init() { func init() {
@ -62,35 +36,17 @@ func init() {
)}, )},
}, Commands: map[string]*ice.Command{ }, Commands: map[string]*ice.Command{
WORD: {Name: "word path=src/main.shy auto play", Help: "语言文字", Meta: kit.Dict( WORD: {Name: "word path=src/main.shy auto play", Help: "语言文字", Meta: kit.Dict(
ice.Display("/plugin/local/wiki/word.js", WORD), ice.Display("/plugin/local/wiki/word.js"),
), Action: ice.MergeAction(map[string]*ice.Action{ ), Action: ice.MergeAction(map[string]*ice.Action{
"play": {Name: "play", Help: "演示"},
web.STORY: {Name: "story", Help: "运行", Hand: func(m *ice.Message, arg ...string) { web.STORY: {Name: "story", Help: "运行", Hand: func(m *ice.Message, arg ...string) {
m.Cmdy(arg[0], ctx.ACTION, ice.RUN, arg[2:]) m.Cmdy(arg[0], ctx.ACTION, ice.RUN, arg[2:])
}}, }},
"play": {Name: "play", Help: "演示"},
}, ctx.CmdAction()), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { }, ctx.CmdAction()), 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))) m.Option(nfs.DIR_REG, m.Config(kit.MDB_REGEXP))
if m.Option(nfs.DIR_DEEP, ice.TRUE); !_wiki_list(m, cmd, arg...) { if m.Option(nfs.DIR_DEEP, ice.TRUE); !_wiki_list(m, cmd, arg...) {
_word_show(m, arg[0]) _word_show(m, arg[0])
} }
}}, }},
"/word/": {Name: "word", Help: "文档", Meta: kit.Dict(
ice.Display("/plugin/local/wiki/word.js", WORD),
), Action: ice.MergeAction(map[string]*ice.Action{
web.STORY: {Name: "story", Help: "运行", Hand: func(m *ice.Message, arg ...string) {
m.Cmdy(arg[0], ctx.ACTION, ice.RUN, arg[2:])
}},
ctx.COMMAND: {Name: "command", Help: "命令", Hand: func(m *ice.Message, arg ...string) {
m.Cmdy(ctx.COMMAND, "web.wiki.word")
if ls := strings.Split(m.Option("_names"), "/word/"); len(ls) > 1 {
m.Push("args", ls[1])
}
}},
}, ctx.CmdAction()), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
if m.R.Method == http.MethodGet {
m.RenderIndex(web.SERVE, ice.VOLCANOS, "page/cmd.html")
return // 目录
}
}},
}}) }})
} }

View File

@ -76,7 +76,7 @@ func init() {
if arg[0] == path.Base(kit.Pwd()) { if arg[0] == path.Base(kit.Pwd()) {
m.Option(nfs.DIR_ROOT, path.Join(ice.SRC)) m.Option(nfs.DIR_ROOT, path.Join(ice.SRC))
} else { } else {
m.Option(nfs.DIR_ROOT, path.Join(ice.USR, arg[0])) m.Option(nfs.DIR_ROOT, path.Join(ice.USR, arg[0])+ice.PS)
} }
if len(arg) == 1 { // 目录列表 if len(arg) == 1 { // 目录列表