mirror of
https://shylinux.com/x/icebergs
synced 2025-05-03 20:07:01 +08:00
opt wiki
This commit is contained in:
parent
9ae43d9b96
commit
028da6be6b
23
core/wiki/brief.go
Normal file
23
core/wiki/brief.go
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
package wiki
|
||||||
|
|
||||||
|
import (
|
||||||
|
ice "github.com/shylinux/icebergs"
|
||||||
|
kit "github.com/shylinux/toolkits"
|
||||||
|
)
|
||||||
|
|
||||||
|
const BRIEF = "brief"
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
Index.Merge(&ice.Context{
|
||||||
|
Commands: map[string]*ice.Command{
|
||||||
|
BRIEF: {Name: "brief [name] text", Help: "摘要", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||||
|
_word_template(m, cmd, arg...)
|
||||||
|
}},
|
||||||
|
},
|
||||||
|
Configs: map[string]*ice.Config{
|
||||||
|
BRIEF: {Name: BRIEF, Help: "摘要", Value: kit.Data(
|
||||||
|
kit.MDB_TEMPLATE, `<p {{.OptionTemplate}}>{{.Option "text"}}</p>`,
|
||||||
|
)},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
98
core/wiki/field.go
Normal file
98
core/wiki/field.go
Normal file
@ -0,0 +1,98 @@
|
|||||||
|
package wiki
|
||||||
|
|
||||||
|
import (
|
||||||
|
"path"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
ice "github.com/shylinux/icebergs"
|
||||||
|
"github.com/shylinux/icebergs/base/cli"
|
||||||
|
kit "github.com/shylinux/toolkits"
|
||||||
|
)
|
||||||
|
|
||||||
|
func _field_show(m *ice.Message, name, text string, arg ...string) {
|
||||||
|
// 基本参数
|
||||||
|
m.Option(kit.MDB_TYPE, FIELD)
|
||||||
|
m.Option(kit.MDB_NAME, name)
|
||||||
|
m.Option(kit.MDB_TEXT, text)
|
||||||
|
|
||||||
|
// 命令参数
|
||||||
|
data := kit.Dict(kit.MDB_NAME, name)
|
||||||
|
cmds := kit.Split(text)
|
||||||
|
m.Search(cmds[0], func(p *ice.Context, s *ice.Context, key string, cmd *ice.Command) {
|
||||||
|
data["feature"], data["inputs"] = cmd.Meta, cmd.List
|
||||||
|
})
|
||||||
|
|
||||||
|
// 扩展参数
|
||||||
|
for i := 0; i < len(arg)-1; i += 2 {
|
||||||
|
if strings.HasPrefix(arg[i], "args.") {
|
||||||
|
m.Option(arg[i], strings.TrimSpace(arg[i+1]))
|
||||||
|
kit.Value(data, arg[i], m.Option(arg[i]))
|
||||||
|
} else if strings.HasPrefix(arg[i], "args") {
|
||||||
|
m.Option(arg[i], kit.Split(strings.TrimSuffix(strings.TrimPrefix(arg[i+1], "["), "]")))
|
||||||
|
kit.Value(data, arg[i], m.Optionv(arg[i]))
|
||||||
|
} else {
|
||||||
|
m.Parse("option", arg[i], arg[i+1])
|
||||||
|
kit.Value(data, arg[i], m.Optionv(arg[i]))
|
||||||
|
}
|
||||||
|
|
||||||
|
switch arg[i] {
|
||||||
|
case "content":
|
||||||
|
data[arg[i]] = arg[i+1]
|
||||||
|
|
||||||
|
case "args":
|
||||||
|
args := kit.Simple(m.Optionv(arg[i]))
|
||||||
|
|
||||||
|
count := 0
|
||||||
|
kit.Fetch(data["inputs"], func(index int, value map[string]interface{}) {
|
||||||
|
if value["_input"] != "button" && value["type"] != "button" {
|
||||||
|
count++
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
if len(args) > count {
|
||||||
|
list := data["inputs"].([]interface{})
|
||||||
|
for i := count; i < len(args); i++ {
|
||||||
|
list = append(list, kit.Dict(
|
||||||
|
"_input", "text", "name", "args", "value", args[i],
|
||||||
|
))
|
||||||
|
}
|
||||||
|
data["inputs"] = list
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 渲染引擎
|
||||||
|
m.Option(kit.MDB_META, data)
|
||||||
|
m.RenderTemplate(m.Conf(FIELD, kit.Keym(kit.MDB_TEMPLATE)))
|
||||||
|
}
|
||||||
|
|
||||||
|
const FIELD = "field"
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
Index.Merge(&ice.Context{
|
||||||
|
Commands: map[string]*ice.Command{
|
||||||
|
FIELD: {Name: "field [name] cmd", Help: "插件", Action: map[string]*ice.Action{
|
||||||
|
cli.RUN: {Name: "run", Help: "执行", Hand: func(m *ice.Message, arg ...string) {
|
||||||
|
if !m.Warn(!m.Right(arg[1:]), ice.ErrNotRight, arg[1:]) {
|
||||||
|
m.Cmdy(arg[1:])
|
||||||
|
}
|
||||||
|
}},
|
||||||
|
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||||
|
arg = _name(m, arg)
|
||||||
|
_field_show(m, strings.ReplaceAll(kit.Select(path.Base(arg[1]), arg[0]), " ", "_"), arg[1], arg[2:]...)
|
||||||
|
}},
|
||||||
|
},
|
||||||
|
Configs: map[string]*ice.Config{
|
||||||
|
FIELD: {Name: FIELD, Help: "插件", Value: kit.Data(
|
||||||
|
kit.MDB_TEMPLATE, `<fieldset class="story {{.Option "name"}}"
|
||||||
|
data-type="{{.Option "type"}}" data-name="{{.Option "name"}}" data-text="{{.Option "text"}}" 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>`,
|
||||||
|
)},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
32
core/wiki/local.go
Normal file
32
core/wiki/local.go
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
package wiki
|
||||||
|
|
||||||
|
import (
|
||||||
|
ice "github.com/shylinux/icebergs"
|
||||||
|
"github.com/shylinux/icebergs/base/nfs"
|
||||||
|
kit "github.com/shylinux/toolkits"
|
||||||
|
)
|
||||||
|
|
||||||
|
func _local_show(m *ice.Message, name, text string, arg ...string) {
|
||||||
|
m.Option("input", m.Cmdx(nfs.CAT, text))
|
||||||
|
_option(m, LOCAL, name, text, arg...)
|
||||||
|
m.RenderTemplate(m.Conf(LOCAL, kit.Keym(kit.MDB_TEMPLATE)))
|
||||||
|
}
|
||||||
|
|
||||||
|
const LOCAL = "local"
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
Index.Merge(&ice.Context{
|
||||||
|
Commands: map[string]*ice.Command{
|
||||||
|
LOCAL: {Name: "local [name] file", Help: "文件", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||||
|
arg = _name(m, arg)
|
||||||
|
_local_show(m, arg[0], kit.Select(arg[0], arg[1]), arg[2:]...)
|
||||||
|
}},
|
||||||
|
},
|
||||||
|
Configs: map[string]*ice.Config{
|
||||||
|
LOCAL: {Name: LOCAL, Help: "文件", Value: kit.Data(
|
||||||
|
kit.MDB_TEMPLATE, `<code class="story" {{.OptionTemplate}}
|
||||||
|
>{{range $index, $value := .Optionv "input"}}{{$value}}{{end}}</code>`,
|
||||||
|
)},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
35
core/wiki/order.go
Normal file
35
core/wiki/order.go
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
package wiki
|
||||||
|
|
||||||
|
import (
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
ice "github.com/shylinux/icebergs"
|
||||||
|
kit "github.com/shylinux/toolkits"
|
||||||
|
)
|
||||||
|
|
||||||
|
func _order_show(m *ice.Message, name, text string, arg ...string) {
|
||||||
|
m.Optionv("list", kit.Split(strings.TrimSpace(text), "\n"))
|
||||||
|
_option(m, ORDER, name, text, arg...)
|
||||||
|
m.RenderTemplate(m.Conf(ORDER, kit.Keym(kit.MDB_TEMPLATE)))
|
||||||
|
}
|
||||||
|
|
||||||
|
const ORDER = "order"
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
Index.Merge(&ice.Context{
|
||||||
|
Commands: map[string]*ice.Command{
|
||||||
|
ORDER: {Name: "order [name] `[item \n]...`", Help: "列表", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||||
|
arg = _name(m, arg)
|
||||||
|
_order_show(m, arg[0], kit.Select(arg[0], arg[1]), arg[2:]...)
|
||||||
|
}},
|
||||||
|
},
|
||||||
|
Configs: map[string]*ice.Config{
|
||||||
|
ORDER: {Name: ORDER, Help: "列表", Value: kit.Data(
|
||||||
|
kit.MDB_TEMPLATE, `<ul class="story"
|
||||||
|
{{range $k, $v := .Optionv "extra"}}data-{{$k}}='{{$v}}'{{end}}
|
||||||
|
data-type="{{.Option "type"}}" data-name="{{.Option "name"}}" data-text="{{.Option "text"}}">
|
||||||
|
{{range $index, $value := .Optionv "list"}}<li>{{$value}}</li>{{end}}</ul>`,
|
||||||
|
)},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
29
core/wiki/other.go
Normal file
29
core/wiki/other.go
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
package wiki
|
||||||
|
|
||||||
|
import (
|
||||||
|
ice "github.com/shylinux/icebergs"
|
||||||
|
kit "github.com/shylinux/toolkits"
|
||||||
|
)
|
||||||
|
|
||||||
|
func _other_show(m *ice.Message, name, text string, arg ...string) {
|
||||||
|
_option(m, OTHER, name, text, arg...)
|
||||||
|
m.RenderTemplate(m.Conf(OTHER, kit.Keym(kit.MDB_TEMPLATE)))
|
||||||
|
}
|
||||||
|
|
||||||
|
const OTHER = "other"
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
Index.Merge(&ice.Context{
|
||||||
|
Commands: map[string]*ice.Command{
|
||||||
|
OTHER: {Name: "other [name] url", Help: "网页", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||||
|
arg = _name(m, arg)
|
||||||
|
_other_show(m, arg[0], kit.Select(arg[0], arg[1]), arg[2:]...)
|
||||||
|
}},
|
||||||
|
},
|
||||||
|
Configs: map[string]*ice.Config{
|
||||||
|
OTHER: {Name: FIELD, Help: "网页", Value: kit.Data(
|
||||||
|
kit.MDB_TEMPLATE, ``,
|
||||||
|
)},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
60
core/wiki/parse.go
Normal file
60
core/wiki/parse.go
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
package wiki
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/url"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
ice "github.com/shylinux/icebergs"
|
||||||
|
"github.com/shylinux/icebergs/base/mdb"
|
||||||
|
kit "github.com/shylinux/toolkits"
|
||||||
|
)
|
||||||
|
|
||||||
|
const PARSE = "parse"
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
Index.Merge(&ice.Context{
|
||||||
|
Commands: map[string]*ice.Command{
|
||||||
|
PARSE: {Name: "parse type=auto,json,http,form,list auto text:textarea", Help: "解析", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||||
|
if len(arg) < 2 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if arg[0] == "auto" && (strings.HasPrefix(arg[1], "{") || strings.HasPrefix(arg[1], "[")) {
|
||||||
|
arg[0] = "json"
|
||||||
|
} else if strings.HasPrefix(arg[1], "http") {
|
||||||
|
arg[0] = "http"
|
||||||
|
} else if strings.Contains(arg[1], "=") {
|
||||||
|
arg[0] = "form"
|
||||||
|
} else {
|
||||||
|
arg[0] = "list"
|
||||||
|
}
|
||||||
|
|
||||||
|
m.Option(mdb.FIELDS, mdb.DETAIL)
|
||||||
|
switch arg[0] {
|
||||||
|
case "json":
|
||||||
|
m.Echo(kit.Formats(kit.UnMarshal(arg[1])))
|
||||||
|
case "http":
|
||||||
|
u, _ := url.Parse(arg[1])
|
||||||
|
for k, v := range u.Query() {
|
||||||
|
for _, v := range v {
|
||||||
|
m.Push(k, v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
m.EchoQRCode(arg[1])
|
||||||
|
|
||||||
|
case "form":
|
||||||
|
for _, v := range kit.Split(arg[1], "&", "&", "&") {
|
||||||
|
ls := kit.Split(v, "=", "=", "=")
|
||||||
|
key, _ := url.QueryUnescape(ls[0])
|
||||||
|
value, _ := url.QueryUnescape(kit.Select("", ls, 1))
|
||||||
|
m.Push(key, value)
|
||||||
|
}
|
||||||
|
case "list":
|
||||||
|
for i, v := range kit.Split(arg[1]) {
|
||||||
|
m.Push(kit.Format(i), v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}},
|
||||||
|
},
|
||||||
|
Configs: map[string]*ice.Config{},
|
||||||
|
})
|
||||||
|
}
|
45
core/wiki/refer.go
Normal file
45
core/wiki/refer.go
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
package wiki
|
||||||
|
|
||||||
|
import (
|
||||||
|
"path"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
ice "github.com/shylinux/icebergs"
|
||||||
|
kit "github.com/shylinux/toolkits"
|
||||||
|
)
|
||||||
|
|
||||||
|
func _refer_show(m *ice.Message, name, text string, arg ...string) {
|
||||||
|
list := [][]string{}
|
||||||
|
for _, v := range kit.Split(strings.TrimSpace(text), "\n", "\n") {
|
||||||
|
if ls := kit.Split(v); len(ls) == 1 {
|
||||||
|
list = append(list, []string{path.Base(ls[0]), ls[0]})
|
||||||
|
} else {
|
||||||
|
list = append(list, ls)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
m.Optionv("list", list)
|
||||||
|
|
||||||
|
_option(m, REFER, name, text, arg...)
|
||||||
|
m.RenderTemplate(m.Conf(REFER, kit.Keym(kit.MDB_TEMPLATE)))
|
||||||
|
}
|
||||||
|
|
||||||
|
const REFER = "refer"
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
Index.Merge(&ice.Context{
|
||||||
|
Commands: map[string]*ice.Command{
|
||||||
|
REFER: {Name: "refer [name] `[name url]...`", Help: "参考", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||||
|
arg = _name(m, arg)
|
||||||
|
_refer_show(m, arg[0], arg[1], arg[2:]...)
|
||||||
|
}},
|
||||||
|
},
|
||||||
|
Configs: map[string]*ice.Config{
|
||||||
|
REFER: {Name: REFER, Help: "参考", Value: kit.Data(
|
||||||
|
kit.MDB_TEMPLATE, `<ul class="story"
|
||||||
|
{{range $k, $v := .Optionv "extra"}}data-{{$k}}='{{$v}}'{{end}}
|
||||||
|
data-type="{{.Option "type"}}" data-name="{{.Option "name"}}" data-text="{{.Option "text"}}">
|
||||||
|
{{range $index, $value := .Optionv "list"}}<li>{{index $value 0}}: <a href="{{index $value 1}}" target="_blank">{{index $value 1}}</a></li>{{end}}</ul>`,
|
||||||
|
)},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
35
core/wiki/shell.go
Normal file
35
core/wiki/shell.go
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
package wiki
|
||||||
|
|
||||||
|
import (
|
||||||
|
ice "github.com/shylinux/icebergs"
|
||||||
|
"github.com/shylinux/icebergs/base/cli"
|
||||||
|
kit "github.com/shylinux/toolkits"
|
||||||
|
)
|
||||||
|
|
||||||
|
func _shell_show(m *ice.Message, name, text string, arg ...string) {
|
||||||
|
m.Option("output", m.Cmdx(cli.SYSTEM, "sh", "-c", m.Option("input", text)))
|
||||||
|
_option(m, SHELL, name, text, arg...)
|
||||||
|
m.RenderTemplate(m.Conf(SHELL, kit.Keym(kit.MDB_TEMPLATE)))
|
||||||
|
}
|
||||||
|
|
||||||
|
const SHELL = "shell"
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
Index.Merge(&ice.Context{
|
||||||
|
Commands: map[string]*ice.Command{
|
||||||
|
SHELL: {Name: "shell [name] cmd", Help: "命令", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||||
|
arg = _name(m, arg)
|
||||||
|
_shell_show(m, arg[0], kit.Select(arg[0], arg[1]), arg[2:]...)
|
||||||
|
}},
|
||||||
|
},
|
||||||
|
Configs: map[string]*ice.Config{
|
||||||
|
SHELL: {Name: SHELL, Help: "命令", Value: kit.Data(
|
||||||
|
kit.MDB_TEMPLATE, `<code class="story"
|
||||||
|
{{range $k, $v := .Optionv "extra"}}data-{{$k}}='{{$v}}'{{end}}
|
||||||
|
data-type="{{.Option "type"}}" data-name="{{.Option "name"}}" data-text="{{.Option "input"}}"
|
||||||
|
>$ {{.Option "input"}} # {{.Option "name"}}
|
||||||
|
{{.Option "output"}}</code>`,
|
||||||
|
)},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
49
core/wiki/spark.go
Normal file
49
core/wiki/spark.go
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
package wiki
|
||||||
|
|
||||||
|
import (
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
ice "github.com/shylinux/icebergs"
|
||||||
|
kit "github.com/shylinux/toolkits"
|
||||||
|
)
|
||||||
|
|
||||||
|
func _spark_show(m *ice.Message, name, text string, arg ...string) {
|
||||||
|
if name == "" {
|
||||||
|
_wiki_template(m, SPARK, name, text, arg...)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
prompt := kit.Select(name+"> ", m.Conf(SPARK, kit.Keym("prompt", name)))
|
||||||
|
m.Echo(`<div class="story" data-type="spark" data-name="%s">`, name)
|
||||||
|
for _, l := range strings.Split(text, "\n") {
|
||||||
|
m.Echo("<div>")
|
||||||
|
m.Echo("<label>").Echo(prompt).Echo("</label>")
|
||||||
|
m.Echo("<span>").Echo(l).Echo("</span>")
|
||||||
|
m.Echo("</div>")
|
||||||
|
}
|
||||||
|
m.Echo("</div>")
|
||||||
|
}
|
||||||
|
|
||||||
|
const SPARK = "spark"
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
Index.Merge(&ice.Context{
|
||||||
|
Commands: map[string]*ice.Command{
|
||||||
|
SPARK: {Name: "spark [name] text", Help: "段落", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||||
|
if len(arg) == 0 {
|
||||||
|
m.Echo(`<br class="story" data-type="spark">`)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
arg = _name(m, arg)
|
||||||
|
_spark_show(m, arg[0], strings.TrimSpace(arg[1]), arg[2:]...)
|
||||||
|
}},
|
||||||
|
},
|
||||||
|
Configs: map[string]*ice.Config{
|
||||||
|
SPARK: {Name: SPARK, Help: "段落", Value: kit.Data(
|
||||||
|
kit.MDB_TEMPLATE, `<p {{.OptionTemplate}}>{{.Option "text"}}</p>`,
|
||||||
|
"prompt", kit.Dict("shell", "$ "),
|
||||||
|
)},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
65
core/wiki/table.go
Normal file
65
core/wiki/table.go
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
package wiki
|
||||||
|
|
||||||
|
import (
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
ice "github.com/shylinux/icebergs"
|
||||||
|
kit "github.com/shylinux/toolkits"
|
||||||
|
)
|
||||||
|
|
||||||
|
func _table_show(m *ice.Message, name, text string, arg ...string) {
|
||||||
|
head, list := []string{}, [][]string{}
|
||||||
|
for i, v := range kit.Split(strings.TrimSpace(text), "\n") {
|
||||||
|
if v = strings.ReplaceAll(v, "%", "%%"); i == 0 {
|
||||||
|
head = kit.Split(v)
|
||||||
|
} else {
|
||||||
|
line := kit.Split(v)
|
||||||
|
for i, v := range line {
|
||||||
|
if ls := kit.Split(v); len(ls) > 1 {
|
||||||
|
style := []string{}
|
||||||
|
for i := 1; i < len(ls)-1; i += 2 {
|
||||||
|
switch ls[i] {
|
||||||
|
case "bg":
|
||||||
|
ls[i] = "background-color"
|
||||||
|
case "fg":
|
||||||
|
ls[i] = "color"
|
||||||
|
}
|
||||||
|
style = append(style, ls[i]+":"+ls[i+1])
|
||||||
|
}
|
||||||
|
line[i] = kit.Format(`<span style="%s">%s</span>`, strings.Join(style, ";"), ls[0])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
list = append(list, line)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
m.Optionv("head", head)
|
||||||
|
m.Optionv("list", list)
|
||||||
|
|
||||||
|
_option(m, TABLE, name, text, arg...)
|
||||||
|
m.RenderTemplate(m.Conf(TABLE, kit.Keym(kit.MDB_TEMPLATE)))
|
||||||
|
}
|
||||||
|
|
||||||
|
const TABLE = "table"
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
Index.Merge(&ice.Context{
|
||||||
|
Commands: map[string]*ice.Command{
|
||||||
|
TABLE: {Name: "table [name] `[item item\n]...`", Help: "表格", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||||
|
arg = _name(m, arg)
|
||||||
|
_table_show(m, arg[0], kit.Select(arg[0], arg[1]), arg[2:]...)
|
||||||
|
}},
|
||||||
|
},
|
||||||
|
Configs: map[string]*ice.Config{
|
||||||
|
TABLE: {Name: TABLE, Help: "表格", Value: kit.Data(
|
||||||
|
kit.MDB_TEMPLATE, `<table class="story"
|
||||||
|
{{range $k, $v := .Optionv "extra"}}data-{{$k}}='{{$v}}'{{end}}
|
||||||
|
data-type="{{.Option "type"}}" data-name="{{.Option "name"}}" data-text="{{.Option "text"}}">
|
||||||
|
<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>`,
|
||||||
|
)},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
82
core/wiki/title.go
Normal file
82
core/wiki/title.go
Normal file
@ -0,0 +1,82 @@
|
|||||||
|
package wiki
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
ice "github.com/shylinux/icebergs"
|
||||||
|
kit "github.com/shylinux/toolkits"
|
||||||
|
)
|
||||||
|
|
||||||
|
func _title_show(m *ice.Message, kind, text string, arg ...string) {
|
||||||
|
title, _ := m.Optionv(TITLE).(map[string]int)
|
||||||
|
switch kind {
|
||||||
|
case PREMENU: // 前置目录
|
||||||
|
m.RenderTemplate(premenu)
|
||||||
|
return
|
||||||
|
|
||||||
|
case ENDMENU: // 后置目录
|
||||||
|
m.RenderTemplate(endmenu)
|
||||||
|
return
|
||||||
|
|
||||||
|
case SECTION: // 分节标题
|
||||||
|
title[SECTION]++
|
||||||
|
m.Option("level", "h3")
|
||||||
|
m.Option("prefix", fmt.Sprintf("%d.%d ", title[CHAPTER], title[SECTION]))
|
||||||
|
|
||||||
|
case CHAPTER: // 章节标题
|
||||||
|
title[CHAPTER]++
|
||||||
|
title[SECTION] = 0
|
||||||
|
m.Option("level", "h2")
|
||||||
|
m.Option("prefix", fmt.Sprintf("%d ", title[CHAPTER]))
|
||||||
|
|
||||||
|
default: // 文章标题
|
||||||
|
m.Option("level", "h1")
|
||||||
|
m.Option("prefix", "")
|
||||||
|
}
|
||||||
|
|
||||||
|
// 添加目录
|
||||||
|
menu, _ := m.Optionv("menu").(map[string]interface{})
|
||||||
|
menu["list"] = append(menu["list"].([]interface{}), map[string]interface{}{
|
||||||
|
"level": m.Option("level"), "prefix": m.Option("prefix"), "content": m.Option("content", text),
|
||||||
|
})
|
||||||
|
|
||||||
|
// 渲染引擎
|
||||||
|
_wiki_template(m, TITLE, "", text, arg...)
|
||||||
|
}
|
||||||
|
|
||||||
|
const (
|
||||||
|
PREMENU = "premenu"
|
||||||
|
CHAPTER = "chapter"
|
||||||
|
SECTION = "section"
|
||||||
|
ENDMENU = "endmenu"
|
||||||
|
)
|
||||||
|
|
||||||
|
const TITLE = "title"
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
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) {
|
||||||
|
if len(arg) == 0 {
|
||||||
|
ns := strings.Split(ice.Info.NodeName, "-")
|
||||||
|
arg = append(arg, kit.Select(ns[len(ns)-1], ""))
|
||||||
|
}
|
||||||
|
if len(arg) == 1 {
|
||||||
|
arg = append(arg, "")
|
||||||
|
}
|
||||||
|
_title_show(m, arg[0], kit.Select(arg[0], arg[1]), arg[2:]...)
|
||||||
|
}},
|
||||||
|
},
|
||||||
|
Configs: map[string]*ice.Config{
|
||||||
|
TITLE: {Name: TITLE, Help: "标题", Value: kit.Data(
|
||||||
|
kit.MDB_TEMPLATE, `<{{.Option "level"}} {{.OptionTemplate}}>{{.Option "prefix"}} {{.Option "content"}}</{{.Option "level"}}>`,
|
||||||
|
)},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
var premenu = `<ul class="story" data-type="premenu"></ul>`
|
||||||
|
var endmenu = `<ul class="story" data-type="endmenu">{{$menu := .Optionv "menu"}}{{range $index, $value := Value $menu "list"}}
|
||||||
|
<li>{{Value $value "prefix"}} {{Value $value "content"}}</li>{{end}}
|
||||||
|
</ul>`
|
Loading…
x
Reference in New Issue
Block a user