mirror of
https://shylinux.com/x/ContextOS
synced 2025-04-25 16:58:06 +08:00
add wiki.commit
This commit is contained in:
parent
16acf908d6
commit
deb1b9b5c8
@ -26,3 +26,4 @@
|
||||
~cli
|
||||
|
||||
~code
|
||||
~wiki
|
||||
|
@ -135,6 +135,21 @@ var CGI = template.FuncMap{
|
||||
}
|
||||
return nil
|
||||
},
|
||||
"trans": func(arg ...interface{}) interface{} {
|
||||
switch m := arg[0].(type) {
|
||||
case *Message:
|
||||
list := [][]string{m.Meta["append"]}
|
||||
m.Table(func(index int, value map[string]string) {
|
||||
line := []string{}
|
||||
for _, k := range m.Meta["append"] {
|
||||
line = append(line, value[k])
|
||||
}
|
||||
list = append(list, line)
|
||||
})
|
||||
return list
|
||||
}
|
||||
return nil
|
||||
},
|
||||
"result": func(arg ...interface{}) interface{} {
|
||||
switch m := arg[0].(type) {
|
||||
case *Message:
|
||||
@ -153,33 +168,6 @@ var CGI = template.FuncMap{
|
||||
|
||||
func LocalCGI(m *Message, c *Context) *template.FuncMap {
|
||||
cgi := template.FuncMap{
|
||||
"table": func(arg ...interface{}) interface{} {
|
||||
if len(arg) == 0 {
|
||||
return ""
|
||||
}
|
||||
switch msg := arg[0].(type) {
|
||||
case *Message:
|
||||
res := []map[string]string{}
|
||||
msg.Table(func(index int, value map[string]string) {
|
||||
res = append(res, value)
|
||||
})
|
||||
return res
|
||||
case string:
|
||||
sub := m.Spawn()
|
||||
head := []string{}
|
||||
for i, l := range strings.Split(strings.TrimSpace(msg), "\n") {
|
||||
if i == 0 {
|
||||
head = kit.Split(l, ' ', 100)
|
||||
continue
|
||||
}
|
||||
for j, v := range strings.Split(l, " ") {
|
||||
sub.Push(head[j], v)
|
||||
}
|
||||
}
|
||||
return sub
|
||||
}
|
||||
return nil
|
||||
},
|
||||
"format": func(arg ...interface{}) interface{} {
|
||||
switch msg := arg[0].(type) {
|
||||
case *Message:
|
||||
|
@ -51,6 +51,12 @@ var Index = &ctx.Context{Name: "wiki", Help: "文档中心",
|
||||
"level": {Name: "level", Value: "usr/local/wiki", Help: "文档路径"},
|
||||
"class": {Name: "class", Value: "", Help: "文档目录"},
|
||||
"favor": {Name: "favor", Value: "index.md", Help: "默认文档"},
|
||||
|
||||
"commit": {Name: "data", Value: map[string]interface{}{
|
||||
"data": map[string]interface{}{},
|
||||
"ship": map[string]interface{}{},
|
||||
"head": map[string]interface{}{},
|
||||
}, Help: "数据"},
|
||||
},
|
||||
Commands: map[string]*ctx.Command{
|
||||
"tree": {Name: "tree", Help: "目录", Form: map[string]int{"level": 1, "class": 1}, Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
||||
@ -69,18 +75,82 @@ var Index = &ctx.Context{Name: "wiki", Help: "文档中心",
|
||||
tmpl = template.Must(tmpl.ParseFiles(which))
|
||||
|
||||
m.Optionv("tmpl", tmpl)
|
||||
m.Assert(tmpl.ExecuteTemplate(buffer, path.Base(which), m))
|
||||
m.Assert(tmpl.ExecuteTemplate(buffer, m.Option("filename", path.Base(which)), m))
|
||||
m.Echo(string(markdown.ToHTML(buffer.Bytes(), nil, nil)))
|
||||
return
|
||||
}},
|
||||
"note": {Name: "note file", Help: "便签", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
||||
if len(arg) > 0 {
|
||||
if len(arg) > 1 && arg[0] == "commit" {
|
||||
m.Cmd("commit", arg[1:])
|
||||
} else if len(arg) > 0 {
|
||||
m.Cmd(kit.Select("tree", "text", strings.HasSuffix(arg[0], ".md")), arg[0])
|
||||
} else {
|
||||
m.Cmd("tree")
|
||||
}
|
||||
return
|
||||
}},
|
||||
"commit": {Name: "commit file name type text", Help: "提交", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
||||
head := kit.Hashs(arg[0], arg[1])
|
||||
prev := m.Conf("commit", []string{"head", head, "ship"})
|
||||
m.Log("info", "head: %v %v", head, m.Conf("commit", []string{"head", head}))
|
||||
if len(arg) == 2 {
|
||||
meta := m.Confm("commit", []string{"ship", prev})
|
||||
m.Push("time", meta["time"])
|
||||
m.Push("data", m.Conf("commit", []string{"data", kit.Format(meta["data"])}))
|
||||
m.Table()
|
||||
return
|
||||
}
|
||||
|
||||
data := kit.Hashs(arg[3])
|
||||
m.Log("info", "data: %v %v", data, arg[3])
|
||||
m.Conf("commit", []string{"data", data}, arg[3])
|
||||
|
||||
meta := map[string]interface{}{
|
||||
"prev": prev,
|
||||
"time": m.Time(),
|
||||
"file": arg[0],
|
||||
"name": arg[1],
|
||||
"type": arg[2],
|
||||
"data": data,
|
||||
}
|
||||
ship := kit.Hashs(kit.Format(meta))
|
||||
m.Log("info", "ship: %v %v", ship, meta)
|
||||
m.Conf("commit", []string{"ship", ship}, meta)
|
||||
|
||||
m.Log("info", "head: %v %v", head, ship)
|
||||
m.Conf("commit", []string{"head", head, "ship"}, ship)
|
||||
m.Echo("%v", kit.Formats(meta))
|
||||
return
|
||||
}},
|
||||
"table": {Name: "table", Help: "表格", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
||||
if len(arg) == 0 {
|
||||
return
|
||||
}
|
||||
switch arg[1] {
|
||||
case "data":
|
||||
arg = []string{arg[0], m.Conf("commit", []string{"data", arg[2]})}
|
||||
|
||||
default:
|
||||
msg := m.Spawn().Cmd("commit", m.Option("filename"), arg[0])
|
||||
m.Option("prev_data", msg.Append("data"))
|
||||
m.Option("prev_time", msg.Append("time"))
|
||||
m.Option("file", m.Option("filename"))
|
||||
m.Option("name", arg[0])
|
||||
m.Option("data", arg[1])
|
||||
}
|
||||
|
||||
head := []string{}
|
||||
for i, l := range strings.Split(strings.TrimSpace(arg[1]), "\n") {
|
||||
if i == 0 {
|
||||
head = kit.Split(l, ' ', 100)
|
||||
continue
|
||||
}
|
||||
for j, v := range strings.Split(l, " ") {
|
||||
m.Push(head[j], v)
|
||||
}
|
||||
}
|
||||
return
|
||||
}},
|
||||
"runs": {Name: "run", Help: "便签", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
||||
m.Cmdy(arg).Set("append")
|
||||
return
|
||||
|
@ -1528,6 +1528,15 @@ function Output(plugin, type, msg, cb, target, option) {
|
||||
target.innerHTML = "", plugin.onfigure.meta.max(target)
|
||||
output.onimport.meta._table(msg, msg.append) || kit.OrderCode(kit.ModifyNode(target, msg.result.join("")))
|
||||
kit._call(cb, [msg])
|
||||
kit.Selector(target, ".commit", function(item) {
|
||||
var data = item.dataset
|
||||
item.oncontextmenu = function(event) {
|
||||
plugin.oncarte(event, shy("", {}, ["提交"], function(event, value, meta) {
|
||||
plugin.Run(event, [option.you.vaule||"", "commit", option.doc.value||"", data.name, "table", data.data], function(msg) {
|
||||
}, true)
|
||||
}))
|
||||
}
|
||||
})
|
||||
},
|
||||
_svg: function(target, width, height, src) {
|
||||
target.innerHTML = '<embed src="'+src+'" width="'+width+'" height="'+height+'" type="image/svg+xml" pluginspage="http://www.adobe.com/svg/viewer/install/" />'
|
||||
|
@ -1,9 +1,11 @@
|
||||
|
||||
{{define "table"}}<table>{{range $i, $line := .|table}}
|
||||
{{if eq $i 0}}
|
||||
<tr>{{range $k, $v := $line}}<th>{{$k}}</th>{{end}}</tr>
|
||||
{{end}}
|
||||
<tr>{{range $k, $v := $line}}<td>{{$v}}</td>{{end}}</tr>
|
||||
{{define "table"}}<table class="commit" data-file='{{options . "file"}}' data-name='{{options . "name"}}' data-data='{{options . "data"}}'
|
||||
data-commit_time='{{options . "prev_time"}}' data-commit_data='{{options . "prev_data"}}'>{{range $i, $line := .|trans}}
|
||||
{{if eq $i 0}}
|
||||
<tr>{{range $i, $v := $line}}<th>{{$v}}</th>{{end}}</tr>
|
||||
{{else}}
|
||||
<tr>{{range $i, $v := $line}}<td>{{$v}}</td>{{end}}</tr>
|
||||
{{end}}
|
||||
{{end}}</table>{{end}}
|
||||
|
||||
{{define "code"}}<div>{{results .}}</div>{{end}}
|
||||
|
Loading…
x
Reference in New Issue
Block a user