diff --git a/src/contexts/ctx/ctx_type.go b/src/contexts/ctx/ctx_type.go index 427e1dd9..8f7252ee 100644 --- a/src/contexts/ctx/ctx_type.go +++ b/src/contexts/ctx/ctx_type.go @@ -1123,6 +1123,37 @@ func (m *Message) Parse(arg interface{}) string { } return "" } +func (m *Message) ToHTML() string { + cmd := strings.Join(m.Meta["detail"], " ") + result := []string{} + if len(m.Meta["append"]) > 0 { + result = append(result, "") + result = append(result, "") + m.Table(func(maps map[string]string, list []string, line int) bool { + if line == -1 { + result = append(result, "") + for _, v := range list { + result = append(result, "") + } + result = append(result, "") + return true + } + result = append(result, "") + for _, v := range list { + result = append(result, "") + } + result = append(result, "") + return true + }) + result = append(result, "
", cmd, "
", v, "
", v, "
") + } else { + result = append(result, "
")
+		result = append(result, fmt.Sprintf("%s", m.Find("shy", false).Conf("prompt")), cmd, "\n")
+		result = append(result, m.Meta["result"]...)
+		result = append(result, "
") + } + return strings.Join(result, "") +} func (m *Message) Gdb(arg ...interface{}) interface{} { if g := m.Sess("gdb", false); g != nil { diff --git a/src/contexts/nfs/nfs.go b/src/contexts/nfs/nfs.go index 8df993d4..db65ce6b 100644 --- a/src/contexts/nfs/nfs.go +++ b/src/contexts/nfs/nfs.go @@ -40,10 +40,8 @@ type NFS struct { func dir(m *ctx.Message, name string, level int, deep bool, dir_type string, trip int, dir_reg *regexp.Regexp, fields []string, format string) { back, e := os.Getwd() m.Assert(e) - os.Chdir(name) - defer os.Chdir(back) - if fs, e := ioutil.ReadDir("."); m.Assert(e) { + if fs, e := ioutil.ReadDir(name); m.Assert(e) { for _, f := range fs { if f.Name() == "." || f.Name() == ".." { continue @@ -53,7 +51,7 @@ func dir(m *ctx.Message, name string, level int, deep bool, dir_type string, tri continue } - f, e := os.Stat(f.Name()) + f, e := os.Stat(path.Join(name, f.Name())) if e != nil { m.Log("info", "%s", e) continue @@ -91,11 +89,11 @@ func dir(m *ctx.Message, name string, level int, deep bool, dir_type string, tri case "line": nline := 0 if f.IsDir() { - d, e := ioutil.ReadDir(f.Name()) + d, e := ioutil.ReadDir(path.Join(name, f.Name())) m.Assert(e) nline = len(d) } else { - f, e := os.Open(f.Name()) + f, e := os.Open(path.Join(name, f.Name())) m.Assert(e) defer f.Close() @@ -108,7 +106,7 @@ func dir(m *ctx.Message, name string, level int, deep bool, dir_type string, tri m.Add("append", "line", nline) case "hash": if f.IsDir() { - d, e := ioutil.ReadDir(f.Name()) + d, e := ioutil.ReadDir(path.Join(name, f.Name())) m.Assert(e) meta := []string{} for _, v := range d { @@ -121,7 +119,7 @@ func dir(m *ctx.Message, name string, level int, deep bool, dir_type string, tri break } - f, e := ioutil.ReadFile(f.Name()) + f, e := ioutil.ReadFile(path.Join(name, f.Name())) m.Assert(e) h := sha1.Sum(f) m.Add("append", "hash", hex.EncodeToString(h[:])) @@ -129,7 +127,7 @@ func dir(m *ctx.Message, name string, level int, deep bool, dir_type string, tri } } if f.IsDir() && deep { - dir(m, f.Name(), level+1, deep, dir_type, trip, dir_reg, fields, format) + dir(m, path.Join(name, f.Name()), level+1, deep, dir_type, trip, dir_reg, fields, format) } } } diff --git a/src/contexts/web/web.go b/src/contexts/web/web.go index b729b5ee..9a44a87f 100644 --- a/src/contexts/web/web.go +++ b/src/contexts/web/web.go @@ -858,6 +858,12 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心", return }}, "componet": &ctx.Command{Name: "componet [group [order [arg...]]]", Help: "添加组件, group: 组件分组, arg...: 组件参数", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) { + if len(arg) > 0 && arg[0] == "share" { + m.Cmd("aaa.role", arg[1], "componet", arg[2], "command", arg[3:]) + m.Echo("%s/?componet_group=%s&relay=%s", m.Conf("serve", "site"), arg[2], m.Cmdx("aaa.relay", "share", arg[1])) + return + } + switch len(arg) { case 0: m.Cmdy("ctx.config", "componet") @@ -971,7 +977,7 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心", } } } - msg.Log("fuck", "what %v", val) + msg.Log("fuck", "%s", msg.Option("componet_name")) // 添加设备 arg = arg[:0] diff --git a/src/examples/code/code.go b/src/examples/code/code.go index 648526a1..8bea8bc0 100644 --- a/src/examples/code/code.go +++ b/src/examples/code/code.go @@ -64,9 +64,19 @@ var Index = &ctx.Context{Name: "code", Help: "代码中心", map[string]interface{}{"name": "viewport", "content": "width=device-width, initial-scale=0.7, user-scalable=no"}, }, "favicon": "favicon.ico", "styles": []interface{}{"example.css", "code.css"}}, + map[string]interface{}{"componet_name": "com", "componet_help": "com", "componet_tmpl": "componet", + "componet_view": "ComList", "componet_init": "initComList", + "componet_ctx": "web.code", "componet_cmd": "componet", "componet_args": []interface{}{"share", "@role", "@componet_group", "@tips"}, "inputs": []interface{}{ + map[string]interface{}{"type": "text", "name": "role", "value": "tech", "label": "role"}, + map[string]interface{}{"type": "text", "name": "tips", "value": "schedule", "label": "tips"}, + map[string]interface{}{"type": "button", "value": "共享页面"}, + }, + }, + map[string]interface{}{"componet_name": "text", "componet_help": "text", "componet_tmpl": "componet", "componet_view": "ScheduleText", "componet_init": "initScheduleText", - "componet_ctx": "web.code", "componet_cmd": "schedule", "componet_args": []interface{}{"@time", "@name", "@place"}, "inputs": []interface{}{ + "componet_ctx": "web.code", "componet_cmd": "schedule", + "componet_args": []interface{}{"@time", "@name", "@place"}, "inputs": []interface{}{ map[string]interface{}{"type": "text", "name": "time", "value": "", "label": "time"}, map[string]interface{}{"type": "text", "name": "name", "value": "", "label": "name"}, map[string]interface{}{"type": "text", "name": "place", "value": "", "label": "place"}, @@ -77,6 +87,15 @@ var Index = &ctx.Context{Name: "code", Help: "代码中心", map[string]interface{}{"componet_name": "list", "componet_help": "list", "componet_tmpl": "componet", "componet_view": "ScheduleList", "componet_init": "initScheduleList", "componet_ctx": "web.code", "componet_cmd": "schedule", + "inputs": []interface{}{ + map[string]interface{}{"type": "choice", "name": "view", "value": "summary", "label": "显示字段", "choice": []interface{}{ + map[string]interface{}{"name": "默认", "value": "default"}, + map[string]interface{}{"name": "行程", "value": "order"}, + map[string]interface{}{"name": "总结", "value": "summary"}, + }}, + map[string]interface{}{"type": "button", "value": "刷新行程"}, + }, + "display_result": "", }, map[string]interface{}{"componet_name": "tail", "componet_tmpl": "tail", @@ -229,6 +248,11 @@ var Index = &ctx.Context{Name: "code", Help: "代码中心", }, Help: "文档管理"}, "schedule": &ctx.Config{Name: "schedule", Value: map[string]interface{}{ "data": []interface{}{}, + "view": map[string]interface{}{ + "default": []interface{}{"面试时间", "面试公司", "面试地点", "面试轮次", "题目类型", "面试题目", "面试总结"}, + "summary": []interface{}{"面试公司", "面试轮次", "题目类型", "面试题目", "面试总结"}, + "order": []interface{}{"面试时间", "面试公司", "面试地点"}, + }, "maps": map[string]interface{}{"baidu": "%s"}, }, Help: "闪存"}, @@ -405,16 +429,39 @@ var Index = &ctx.Context{Name: "code", Help: "代码中心", "schedule": &ctx.Command{Name: "schedule [time name place]", Help: "行程安排", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) { if len(arg) == 0 { // 会话列表 m.Confm("schedule", "data", func(index int, value map[string]interface{}) { - m.Add("append", "time", kit.Format(value["time"])) - m.Add("append", "name", kit.Format(value["name"])) - m.Add("append", "place", fmt.Sprintf(m.Conf("schedule", "maps.baidu"), value["place"], value["place"])) + for _, v := range kit.View([]string{m.Option("view")}, m.Confm("schedule", "view")) { + if v == "面试地点" { + m.Add("append", "面试地点", fmt.Sprintf(m.Conf("schedule", "maps.baidu"), value["面试地点"], value["面试地点"])) + continue + } + m.Add("append", v, kit.Format(value[v])) + } }) m.Table() return } - m.Conf("schedule", []string{"data", "-1"}, map[string]interface{}{ - "time": arg[0], "name": arg[1], "place": arg[2], - }) + + view := "default" + if m.Confs("schedule", arg[0]) { + view, arg = arg[0], arg[1:] + } + + data := map[string]interface{}{} + for _, k := range kit.View([]string{view}, m.Confm("schedule", "view")) { + if len(arg) == 0 { + data[k] = "" + continue + } + data[k], arg = arg[0], arg[1:] + } + + extra := map[string]interface{}{} + for i := 0; i < len(arg)-1; i += 2 { + data[arg[i]] = arg[i+1] + } + data["extra"] = extra + + m.Conf("schedule", []string{"data", "-1"}, data) return }}, diff --git a/src/examples/wiki/wiki.go b/src/examples/wiki/wiki.go index ebf1af99..0d40c59d 100644 --- a/src/examples/wiki/wiki.go +++ b/src/examples/wiki/wiki.go @@ -14,42 +14,77 @@ import ( "os" "path" "strings" + "toolkit" ) var Index = &ctx.Context{Name: "wiki", Help: "文档中心", Caches: map[string]*ctx.Cache{}, Configs: map[string]*ctx.Config{ - "wiki_dir": &ctx.Config{Name: "wiki_dir", Value: "usr/wiki", Help: "路由数量"}, - "wiki_favor": &ctx.Config{Name: "wiki_favor", Value: "lamp.md", Help: "路由数量"}, + "login": &ctx.Config{Name: "login", Value: map[string]interface{}{"check": "false"}, Help: "默认组件"}, + "componet": &ctx.Config{Name: "componet", Value: map[string]interface{}{ + "index": []interface{}{ + map[string]interface{}{"componet_name": "wiki", "componet_tmpl": "head", "metas": []interface{}{ + map[string]interface{}{"name": "viewport", "content": "width=device-width, initial-scale=0.7, user-scalable=no"}, + }, "favicon": "favicon.ico", "styles": []interface{}{"example.css", "wiki.css"}}, + map[string]interface{}{"componet_name": "header", "componet_tmpl": "fieldset", + "componet_view": "Header", "componet_init": "initHeader", + "title": "shylinux 天行健,君子以自强不息", + }, + map[string]interface{}{"componet_name": "tree", "componet_tmpl": "fieldset", + "componet_view": "Tree", "componet_init": "initTree", + "componet_ctx": "web.wiki", "componet_cmd": "wiki_tree", "arguments": []interface{}{"@wiki_class"}, + }, + map[string]interface{}{"componet_name": "text", "componet_tmpl": "fieldset", + "componet_view": "Text", "componet_init": "initText", + "componet_ctx": "web.wiki", "componet_cmd": "wiki_text", "arguments": []interface{}{"@wiki_favor"}, + }, + + map[string]interface{}{"componet_name": "footer", "componet_tmpl": "fieldset", + "componet_view": "Footer", "componet_init": "initFooter", + "title": "shycontext 地势坤,君子以厚德载物", + }, + map[string]interface{}{"componet_name": "tail", "componet_tmpl": "tail", + "scripts": []interface{}{"toolkit.js", "context.js", "example.js", "wiki.js"}, + }, + }, + }, Help: "组件列表"}, + "componet_group": &ctx.Config{Name: "component_group", Value: "index", Help: "默认组件"}, + + "wiki_level": &ctx.Config{Name: "wiki_level", Value: "wiki/自然/编程", Help: "路由数量"}, + "wiki_favor": &ctx.Config{Name: "wiki_favor", Value: "index.md", Help: "路由数量"}, + + "wiki_dir": &ctx.Config{Name: "wiki_dir", Value: "wiki", Help: "路由数量"}, "wiki_list": &ctx.Config{Name: "wiki_list", Value: []interface{}{}, Help: "路由数量"}, "wiki_list_show": &ctx.Config{Name: "wiki_list_show", Value: map[string]interface{}{ "md": true, }, Help: "路由数量"}, - "bench_disable": &ctx.Config{Name: "bench_disable", Value: "true", Help: "工作流"}, - "login": &ctx.Config{Name: "login", Value: map[string]interface{}{ - "check": "false", - }, Help: "默认组件"}, - - "componet_group": &ctx.Config{Name: "component_group", Value: "index", Help: "默认组件"}, - "componet": &ctx.Config{Name: "componet", Value: map[string]interface{}{ - "index": []interface{}{ - map[string]interface{}{"name": "head", "template": "head"}, - map[string]interface{}{"name": "header", "template": "header"}, - map[string]interface{}{"name": "list", "template": "list", - "componet_ctx": "web.wiki", "componet_cmd": "wiki_list", "arguments": []interface{}{"time", "time_r"}, - "pre_run": true, - }, - map[string]interface{}{"name": "text", "template": "text", - "componet_ctx": "web.wiki", "componet_cmd": "wiki_body", "arguments": []interface{}{"@wiki_favor"}, - "pre_run": true, - }, - map[string]interface{}{"name": "footer", "template": "footer"}, - map[string]interface{}{"name": "tail", "template": "tail"}, - }, - }, Help: "组件列表"}, }, Commands: map[string]*ctx.Command{ + "wiki_tree": &ctx.Command{Name: "wiki_tree", Help: "wiki_tree", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) { + m.Cmdy("nfs.dir", path.Join(m.Confx("wiki_level"), kit.Select(m.Option("wiki_class"), arg, 0)), "dir_sort", "time_r") + return + }}, + "wiki_text": &ctx.Command{Name: "wiki_text", Help: "wiki_text", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) { + which := m.Cmdx("nfs.path", path.Join(m.Confx("wiki_level"), m.Option("wiki_class"), m.Confx("wiki_favor", arg, 0))) + + if ls, e := ioutil.ReadFile(which); e == nil { + buffer := bytes.NewBuffer([]byte{}) + temp, e := template.New("temp").Funcs(ctx.CGI).Parse(string(ls)) + if e != nil { + m.Log("info", "parse %s %s", which, e) + } + temp.Execute(buffer, m) + ls = buffer.Bytes() + + ls = markdown.ToHTML(ls, nil, nil) + m.Echo(string(ls)) + } else { + m.Echo(m.Cmd("nfs.dir", path.Join(m.Confx("wiki_level"), m.Option("wiki_class")), + "dir_deep", "dir_type", "dir", "time", "path").ToHTML()) + } + return + }}, "wiki_list": &ctx.Command{Name: "wiki_list sort_field sort_order", Help: "wiki_list", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) { sort_field, sort_order := "time", "time_r" if len(arg) > 0 { @@ -59,12 +94,13 @@ var Index = &ctx.Context{Name: "wiki", Help: "文档中心", sort_order, arg = arg[0], arg[1:] } - md, e := ioutil.ReadDir(m.Conf("wiki_dir")) + dir := path.Join(m.Conf("wiki_dir"), m.Option("wiki_class")) + md, e := ioutil.ReadDir(dir) m.Assert(e) for _, v := range md { if strings.HasSuffix(v.Name(), ".md") { - f, e := os.Open(path.Join(m.Conf("wiki_dir"), v.Name())) + f, e := os.Open(path.Join(dir, v.Name())) m.Assert(e) defer f.Close() @@ -112,23 +148,6 @@ var Index = &ctx.Context{Name: "wiki", Help: "文档中心", }) return }}, - "wiki_body": &ctx.Command{Name: "wiki_body", Help: "wiki_body", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) { - which := path.Join(m.Conf("wiki_dir"), m.Confx("wiki_favor", arg, 0)) - if ls, e := ioutil.ReadFile(which); e == nil { - - buffer := bytes.NewBuffer([]byte{}) - temp, e := template.New("temp").Funcs(ctx.CGI).Parse(string(ls)) - if e != nil { - m.Log("info", "parse %s %s", which, e) - } - temp.Execute(buffer, m) - ls = buffer.Bytes() - - ls = markdown.ToHTML(ls, nil, nil) - m.Echo(string(ls)) - } - return - }}, "/wiki_tags": &ctx.Command{Name: "/wiki_tags ", Help: "博客", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) { if len(arg) > 0 { diff --git a/usr/librarys/code.css b/usr/librarys/code.css index b5f459a1..c814401d 100644 --- a/usr/librarys/code.css +++ b/usr/librarys/code.css @@ -26,44 +26,6 @@ clear:both; } - fieldset table.append { - font-size:14px; - overflow: auto; - } - fieldset table.append tr:hover { - background-color:lightgreen; - } - fieldset table.append th { - font-family:monospace; - background-color:lightgreen; - cursor:pointer; - } - fieldset table.append th.order { - background-color:red; - cursor:pointer; - } - fieldset table.append td { - max-width:1200px; - font-family:monospace; - padding-left: 10px; - padding-right: 20px; - } - fieldset table.append td.clip { - background-color:red; - } - fieldset table.append td:hover { - background-color:red; - } - fieldset code.result pre { - color:white; - font-size:14px; - background-color:#272822; - overflow:scroll; - padding:5px; - border:solid 2px green; - border-left:solid 4px green; - margin:0; - } fieldset code.result pre.clipboard { height:2em; } @@ -115,4 +77,9 @@ fieldset.KitList li>input { background-color:rgba(0,0,0,0.2); } +/* ----- ScheduleList ----- */ + fieldset.ScheduleList table.append td { + max-width:240px; + min-width:100px; + } diff --git a/usr/librarys/code.js b/usr/librarys/code.js index f21358ba..8fd5e243 100644 --- a/usr/librarys/code.js +++ b/usr/librarys/code.js @@ -1,4 +1,8 @@ var page = Page({ + initComList: function(page, field, option, append, result) { + return + }, + initScheduleText: function(page, field, option, append, result) { option.ondaemon = function(msg) { page.reload() @@ -521,9 +525,6 @@ var page = Page({ var page = this switch (action) { case "scroll": - if (event.target == document.body) { - kit.ScrollPage(event, page.conf) - } break case "keymap": if (event.key == "Escape") { @@ -563,9 +564,6 @@ var page = Page({ init: function(exp) { var page = this var body = document.body - body.onkeydown = function(event) { - page.onaction(event, body, "scroll") - } body.onkeyup = function(event) { page.onaction(event, body, "keymap") } @@ -575,8 +573,8 @@ var page = Page({ var append = field.querySelector("table.append") var result = field.querySelector("code.result pre") page.OrderForm(page, field, option, append, result) - page.OrderTable(append) - page.OrderCode(result) + append && page.OrderTable(append) + result && page.OrderCode(result) var init = page[field.dataset.init] if (typeof init == "function") { diff --git a/usr/librarys/context.js b/usr/librarys/context.js index 29d009d4..c7aa9231 100644 --- a/usr/librarys/context.js +++ b/usr/librarys/context.js @@ -39,7 +39,14 @@ ctx = context = { ret.push(one) } - typeof cb == "function" && ret.forEach(cb) + var list = [] + typeof cb == "function" && ret.forEach(function(value, index, array) { + var item = cb(value, index, array) + item && list.push(item) + }) + if (list.length > 0) { + return list + } return ret }, diff --git a/usr/librarys/example.css b/usr/librarys/example.css index 3f10cc2f..744ece1d 100644 --- a/usr/librarys/example.css +++ b/usr/librarys/example.css @@ -4,3 +4,49 @@ html, body { margin:0px; background-color:#d8d8d8; } + +fieldset table { + font-size:14px; + overflow: auto; + border:solid 1px green; +} +fieldset table caption { + font-size:18px; + font-style:italic; + border:solid 1px green; +} +fieldset table tr:hover { + background-color:lightgreen; +} +fieldset table th { + font-family:monospace; + background-color:lightgreen; + cursor:pointer; +} +fieldset table th.order { + background-color:red; + cursor:pointer; +} +fieldset table td { + max-width:1200px; + font-family:monospace; + padding-left: 10px; + padding-right: 20px; +} +fieldset table td.clip { + background-color:red; +} +fieldset table td:hover { + background-color:red; +} + +fieldset pre code, fieldset code pre { + color:white; + font-size:14px; + background-color:#272822; + overflow:scroll; + padding:5px; + border:solid 2px green; + border-left:solid 4px green; + display:block; +} diff --git a/usr/librarys/example.js b/usr/librarys/example.js index 82dbae09..8b2568c8 100644 --- a/usr/librarys/example.js +++ b/usr/librarys/example.js @@ -2,8 +2,32 @@ exp = example = { __proto__: ctx, _init: function(page) { page.__proto__ = this + + var body = document.body + body.onkeydown = function(event) { + page.onscroll && page.onscroll(event, body, "scroll") + } return this }, + initHeader: function(field, option, output) { + return [{"text": ["shylinux", "div", "title"]}] + }, + initBanner: function(field, option, output) { + return [{"text": ["shylinux", "div", "title"]}] + }, + initFooter: function(field, option) { + return [{"text": ["shycontext", "div", "title"]}] + }, + onscroll: function(event, target, action) { + var page = this + switch (action) { + case "scroll": + if (event.target == document.body) { + kit.ScrollPage(event, page.conf) + } + break + } + }, reload: function() { location.reload() }, diff --git a/usr/librarys/toolkit.js b/usr/librarys/toolkit.js index 4fccadff..1940a2b4 100644 --- a/usr/librarys/toolkit.js +++ b/usr/librarys/toolkit.js @@ -74,6 +74,9 @@ kit = toolkit = { } child.data["style"] = str.join("") } + if (child.click) { + child.data["onclick"] = child.click + } if (child.include) { child.data["src"] = child.include[0] @@ -109,19 +112,20 @@ kit = toolkit = { child.data["innerText"] = child.button[0] child.data["onclick"] = child.button[1] - } else if (child.click) { - child.data["onclick"] = child.click[0] + } else if (child.tree) { + child.type = "ul" + child.list = child.tree } else if (child.fork) { child.type = "li" child.list = [ - {"text": [child.fork[0], "div"]}, + {"text": [child.fork[0], "div"], "click": (child.fork.length>2? child.fork[2]: "")}, {"type": "ul", "list": child.fork[1]}, ] } else if (child.leaf) { child.type = "li" - child.data["innerText"] = child.leaf[0] + child.list = [{"text": [child.leaf[0], "div"]}] if (child.leaf.length > 1 && typeof child.leaf[1] == "function") { child.data["onclick"] = function(event) { child.leaf[1](event, node) @@ -131,7 +135,7 @@ kit = toolkit = { } else if (child.view) { child.data["className"] = child.view[0] child.type = child.view.length > 1? child.view[1]: "div" - child.view.length > 2 && (child.data["innerText"] = child.view[2]) + child.view.length > 2 && (child.data["innerHTML"] = child.view[2]) child.view.length > 3 && (child.name = child.view[3]) } else if (child.text) { @@ -340,6 +344,9 @@ kit = toolkit = { } }) }, + OrderLink: function(link) { + link.target = "_blank" + }, CopyText: function(text) { text = window.getSelection().toString() diff --git a/usr/librarys/wiki.css b/usr/librarys/wiki.css new file mode 100644 index 00000000..91b21205 --- /dev/null +++ b/usr/librarys/wiki.css @@ -0,0 +1,22 @@ +fieldset.Tree>div.output li>div:hover { + background-color:green; +} +fieldset.Tree>div.output>div.tree li { + display:inline; +} +fieldset.Tree>div.output>div.tree li div { + float:left; + padding:5px; + border:solid 1px green; +} +fieldset.Tree>div.output>div.list { + clear:both; + padding-top:5px; +} + +fieldset.Text>div.output>div.menu li>div:hover { + background-color:red; +} +fieldset.Text>div.output>div.text { + position:relative; +} diff --git a/usr/librarys/wiki.js b/usr/librarys/wiki.js index 40a36aeb..97247cbe 100644 --- a/usr/librarys/wiki.js +++ b/usr/librarys/wiki.js @@ -1,392 +1,140 @@ -var wiki = { - layout: { - header: { - height: 40, - }, - nav: { - min_width: 240, - border_width: 2, - }, - article: { - padding: 20, - max_width: 1000, - }, - footer: { - height: 40, - }, +var page = Page({ + initTree: function(field, option, output) { + ctx.Runs(page, option, function(msg) { + output.innerHTML = "" + var back = [{"button": ["知识", function(event) { + ctx.Search({"wiki_class": "", "wiki_favor": ""}) + }]}] + ctx.Search("wiki_class").split("/").forEach(function(value, index, array) { + if (value) { + var favor = [] + for (var i = 0; i <= index; i++) { + favor.push(array[i]) + } + favor.push("") + back.push({"button": [value, function(event) { + ctx.Search({"wiki_class": favor.join("/"), "wiki_favor":""}) + }]}) + } + }) + + var ui = kit.AppendChild(output, [ + {"view": ["back"], "list": back}, + {"view": ["tree"], "list": [{"tree": ctx.Table(msg, function(value, index) { + if (value.filename.endsWith("/")) { + return {"leaf": [value.filename, function(event, target) { + ctx.Search({"wiki_class": ctx.Search("wiki_class")+value.filename, "wiki_favor": ""}) + }]} + } + })}]}, + {"view": ["list"], "list": [{"tree": ctx.Table(msg, function(value, index) { + if (!value.filename.endsWith("/")) { + return {"leaf": [value.filename, function(event, target) { + ctx.Search("wiki_favor", value.filename) + }]} + } + })}]}, + ]) + }) + return + }, + initList: function(field, option, output) { + ctx.Runs(page, option, function(msg) { + output.innerHTML = "" + kit.AppendChild(output, [{"tree": ctx.Table(msg, function(value, index) { + return {"leaf": [value.file, function(event, target) { + ctx.Search("wiki_favor", value.file) + }]} + })}]) + }) + return + }, + initText: function(field, option, output) { + ctx.Runs(page, option, function(msg) { + if (!msg.result) { + return + } + output.innerHTML = "" + var ui = kit.AppendChild(output, [ + {"view": ["menu", "div", "", "menu"]}, + {"view": ["text", "div", msg.result.join(""), "text"]}, + ]) + + ui.text.querySelectorAll("table").forEach(function(value, index, array) { + kit.OrderTable(value, field) + }) + + ui.text.querySelectorAll("a").forEach(function(value, index, array) { + kit.OrderLink(value, field) + }) + + + var i = 0, j = 0, k = 0 + var h0 = [], h2 = [], h3 = [] + ui.text.querySelectorAll("h2,h3,h4").forEach(function(value, index, array) { + var id = "" + var level = 0 + var text = value.innerText + var ratio = parseInt(value.offsetTop/field.scrollHeight*100) + + if (value.tagName == "H2") { + j=k=0 + h2 = [] + id = ++i+"." + text = id+" "+text + h0.push({"fork": [text+" ("+ratio+"%)", h2, function(event) { + console.log(text) + location.hash = id + }]}) + } else if (value.tagName == "H3") { + k=0 + h3 = [] + id = i+"."+(++j) + text = id+" "+text + h2.push({"fork": [text+" ("+ratio+"%)", h3, function(event) { + console.log(text) + location.hash = id + }]}) + } else if (value.tagName == "H4") { + id = i+"."+(++j)+"."+(++k) + text = id+" "+text + h3.push({"leaf": [text+" ("+ratio+"%)", function(event) { + console.log(text) + location.hash = id + }]}) + } + value.innerText = text + value.id = id + }) + kit.AppendChild(ui.menu, [{"tree": h0}]) + }) + return }, - show_result: false, - show_height: "30px", - hide_height: "14px", - scroll_x: 50, - scroll_y: 50, -} - -function set_layout() { - var nav = document.querySelector("nav") - var article = document.querySelector("article") - - if (window.innerWidth > 600) { - nav.className = "fixed" - wiki.layout.article.width = window.innerWidth - nav.offsetWidth- 2*wiki.layout.article.padding - article.style.width = wiki.layout.article.width+"px" - var space = wiki.layout.article.width - wiki.layout.article.max_width - article.style["margin-right"] = (space>0 ? space/2: 0) + "px" - } else { - nav.className = "" - article.style.width = "" - - var space = wiki.layout.article.width - article.style.maxWidth - if (space > 0) { - article.style.marginRight = space / 2 + onaction: function(event, target, action) { + var page = this + switch (action) { + case "scroll": + break } - } -} + }, + init: function(exp) { + var page = this + document.querySelectorAll("body>fieldset").forEach(function(field) { + var option = field.querySelector("form.option") + var output = field.querySelector("div.output") -function action(event, cmd) { - var target = event.target - var dataset = target.dataset - - switch (cmd) { - case "toggle_nav": - var nav = document.querySelector("nav") - nav.hidden = !nav.hidden - set_layout(event) - break - case "toggle_list": - var list = event.target.nextElementSibling - list.hidden = !list.hidden - break - case "scroll": - if (target.tagName == "BODY") { - scroll_page(event, wiki) + var init = page[field.dataset.init] + if (typeof init == "function") { + var conf = init(field, option, output) + if (conf) { + kit.AppendChild(output, conf) + } } - break - } -} -function init_layout() { - var header = document.querySelector("header") - var nav = document.querySelector("nav") - var article = document.querySelector("article") - var footer = document.querySelector("footer") - - wiki.layout.nav.height = window.innerHeight - wiki.layout.header.height - wiki.layout.footer.height - wiki.layout.article.min_height = window.innerHeight - wiki.layout.header.height - wiki.layout.footer.height - 2*wiki.layout.article.padding - - header.style.height = wiki.layout.header.height+"px" - footer.style.height = wiki.layout.footer.height+"px" - nav.style.height = wiki.layout.nav.height-wiki.layout.nav.border_width+"px" - nav.style.minWidth = wiki.layout.nav.min_width+"px" - nav.style.marginTop = wiki.layout.header.height+"px" - article.style.minHeight = wiki.layout.article.min_height+"px" - article.style.marginTop = wiki.layout.header.height+"px" - article.style.padding = wiki.layout.article.padding+"px" - article.style.maxWidth = wiki.layout.article.max_width+"px" - - set_layout() -} -function init_menu() { - var max = 0; - var min = 1000; - var list = []; - var hs = ["h2", "h3", "h4"]; - for (var i = 0; i < hs.length; i++) { - var head = document.getElementsByTagName(hs[i]); - for (var j = 0; j < head.length; j++) { - head[j].id = hs[i]+"_"+j - head[j].onclick = function(event) { - location.hash=event.target.id - } - list.push({"level": hs[i], "position": head[j].offsetTop, "title": head[j].innerText, "hash": head[j].id}) - if (head[j].offsetTop > max) { - max = head[j].offsetTop; - } - if (head[j].offsetTop < min) { - min = head[j].offsetTop; - } - } - } - - max = max - min; - for (var i = 0; i < list.length-1; i++) { - for (var j = i+1; j < list.length; j++) { - if (list[j].position < list[i].position) { - var a = list[i]; - list[i] = list[j]; - list[j] = a; - } - } - } - - var index = [-1, 0, 0] - for (var i = 0; i < list.length; i++) { - if (list[i].level == "h2") { - index[0]++; - index[1]=0; - index[2]=0; - } else if (list[i].level == "h3") { - index[1]++; - index[2]=0; - } else { - index[2]++; - } - - list[i].index4 = index[2]; - list[i].index3 = index[1]; - list[i].index2 = index[0]; - } - - var m = document.getElementsByClassName("menu"); - for (var i = 0; i < m.length; i++) { - for (var j = 0; j < list.length; j++) { - var text = list[j].index2+"." - if (list[j].level == "h3") { - text += list[j].index3 - } else if (list[j].level == "h4") { - text += list[j].index3+"."+list[j].index4 - } - - text += " " - text += list[j].title; - - var h = document.getElementById(list[j].hash) - h.innerText = text - - var one = append_child(m[i], "li") - var a = append_child(one, "a") - a.href = "#"+list[j].hash; - a.innerText = text+" ("+parseInt((list[j].position-min)/max*100)+"%)"; - - one.className = list[j].level; - } - } -} -function init_link() { - var link = document.querySelector("nav .link"); - document.querySelectorAll("article a").forEach(function(item) { - append_child(append_child(link, "li", {"innertText": item.innerText}), "a", { - "href": item.href, - "innerText": item.href, }) - }) -} -function init_code() { - var fuck = kit.isMobile? 22: 16 - - document.querySelectorAll("article pre").forEach(function(item, i) { - var nu = insert_before(item, "div", {"className": "number1"}) - - var line = (item.clientHeight-10)/fuck - for (var j = 1; j <= line; j++) { - append_child(nu, "div", { - "style": { - "fontSize": kit.isMobile?"20px":"14px", - "lineHeight": kit.isMobile?"22px":"16px", - }, - "id": "code"+i+"_"+"line"+j, - "onclick": function(event) { - location.href = "#"+event.target.id - }, - }).appendChild(document.createTextNode(""+j)); - } - - item.onclick = function(event) { - window.getSelection().toString() && document.execCommand("copy") - } - }) -} -function init_table(event) { - var append = document.querySelectorAll("article table").forEach(add_sort) -} -function adjust() { - window.setTimeout(function(){ - window.scrollBy(0, -80) - }, 100) -} - -window.onresize = function (event) { - init_layout() -} -window.onload = function(event) { - init_menu() - init_link() - init_code() - init_table() - init_layout() -} - -function modify_node(which, html) { - var node = which - if (typeof which == "string") { - node = document.querySelector(which) - } - - html && typeof html == "string" && (node.innerHTML = html) - if (html && typeof html == "object") { - for (var k in html) { - if (typeof html[k] == "object") { - for (var d in html[k]) { - node[k][d] = html[k][d] - } - continue - } - node[k] = html[k] - } - } - return node -} -function create_node(element, html) { - var node = document.createElement(element) - return modify_node(node, html) -} -function append_child(parent, element, html) { - var elm = create_node(element, html) - parent.append(elm) - return elm -} -function insert_before(self, element, html) { - var elm = create_node(element, html) - return self.parentElement.insertBefore(elm, self) -} - -function format(str) { - if (str.indexOf("http") == 0 && str.indexOf(""+str+"" - } - return str -} -function sort_table(table, index, sort_asc) { - var list = table.querySelectorAll("tr") - var new_list = [] - - var is_time = true - var is_number = true - for (var i = 1; i < list.length; i++) { - var value = Date.parse(list[i].childNodes[index].innerText) - if (!(value > 0)) { - is_time = false - } - - var value = parseInt(list[i].childNodes[index].innerText) - if (!(value >= 0 || value <= 0)) { - is_number = false - } - - new_list.push(list[i]) - } - - var sort_order = "" - if (is_time) { - if (sort_asc) { - method = function(a, b) {return Date.parse(a) > Date.parse(b)} - sort_order = "time" - } else { - method = function(a, b) {return Date.parse(a) < Date.parse(b)} - sort_order = "time_r" - } - } else if (is_number) { - if (sort_asc) { - method = function(a, b) {return parseInt(a) > parseInt(b)} - sort_order = "int" - } else { - method = function(a, b) {return parseInt(a) < parseInt(b)} - sort_order = "int_r" - } - } else { - if (sort_asc) { - method = function(a, b) {return a > b} - sort_order = "str" - } else { - method = function(a, b) {return a < b} - sort_order = "str_r" - } - } - - list = new_list - new_list = [] - for (var i = 0; i < list.length; i++) { - list[i].parentElement && list[i].parentElement.removeChild(list[i]) - for (var j = i+1; j < list.length; j++) { - if (typeof method == "function" && method(list[i].childNodes[index].innerText, list[j].childNodes[index].innerText)) { - var temp = list[i] - list[i] = list[j] - list[j] = temp - } - } - new_list.push(list[i]) - } - - for (var i = 0; i < new_list.length; i++) { - table.appendChild(new_list[i]) - } - return sort_order -} -function add_sort(append, field, cb) { - append.onclick = function(event) { - var target = event.target - var dataset = target.dataset - var nodes = target.parentElement.childNodes - for (var i = 0; i < nodes.length; i++) { - if (nodes[i] == target) { - if (target.tagName == "TH") { - dataset["sort_asc"] = (dataset["sort_asc"] == "1") ? 0: 1 - sort_table(append, i, dataset["sort_asc"] == "1") - } else if (target.tagName == "TD") { - var tr = target.parentElement.parentElement.querySelector("tr") - if (tr.childNodes[i].innerText.startsWith(field)) { - typeof cb == "function" && cb(event) - } - } - } - } - } -} -function scroll_page(event, page) { - var body = document.querySelector("body") - - switch (event.key) { - case "h": - if (event.ctrlKey) { - window.scrollBy(-page.scroll_x*10, 0) - } else { - window.scrollBy(-page.scroll_x, 0) - } - break - case "H": - window.scrollBy(-body.scrollWidth, 0) - break - case "l": - if (event.ctrlKey) { - window.scrollBy(page.scroll_x*10, 0) - } else { - window.scrollBy(page.scroll_x, 0) - } - break - case "L": - window.scrollBy(body.scrollWidth, 0) - break - case "j": - if (event.ctrlKey) { - window.scrollBy(0, page.scroll_y*10) - } else { - window.scrollBy(0, page.scroll_y) - } - break - case "J": - window.scrollBy(0, body.scrollHeight) - break - case "k": - if (event.ctrlKey) { - window.scrollBy(0, -page.scroll_y*10) - } else { - window.scrollBy(0, -page.scroll_y) - } - break - case "K": - window.scrollBy(0, -body.scrollHeight) - break - } - return -} - + }, + conf: { + scroll_x: 50, + scroll_y: 50, + }, +}) diff --git a/usr/template/code/code.tmpl b/usr/template/code/code.tmpl index 761a45c1..4a542b75 100644 --- a/usr/template/code/code.tmpl +++ b/usr/template/code/code.tmpl @@ -1,25 +1,3 @@ -{{define "head"}} - - - - {{range $index, $meta := option . "metas"}} - - {{end}} - - {{options . "componet_name"}} - - {{range $index, $lib := option . "styles"}} - - {{end}} - - - -{{end}} {{define "toolkit"}}
{{options . "componet_name"}}({{options . "componet_help"}})
@@ -31,8 +9,8 @@ {{$msg := .}}
@@ -112,10 +90,3 @@ wx.error(function(res){}) {{end}} -{{define "tail"}} - {{range $index, $lib := option . "scripts"}} - - {{end}} - -{{end}} - diff --git a/usr/template/web/web.tmpl b/usr/template/web/web.tmpl index 2a5a4751..0423cc4b 100644 --- a/usr/template/web/web.tmpl +++ b/usr/template/web/web.tmpl @@ -1,198 +1,29 @@ {{define "head"}} - - - - -{{option .Meta "page_title"}} - - + + + + {{range $index, $meta := option . "metas"}} + + {{end}} - - + {{options . "componet_name"}} + + {{range $index, $lib := option . "styles"}} + + {{end}} + + + {{end}} - -{{define "void"}}{{end}} - -{{define "detail"}}{{detail .}}{{end}} -{{define "option"}}{{option .}}{{end}} -{{define "append"}}{{append .}}{{end}} -{{define "result"}}{{result .}}{{end}} - -{{define "clipboard"}} -
clipboard - - - -
-{{end}} - -{{define "componet"}} -
{{option .Meta "help"}}({{option .Meta "context"}}.{{option .Meta "command"}}) - {{$form_type := option . "form_type"|meta}} - - {{if eq $form_type "upload"}} - {{end}} - - - {{range $index, $input := option . "inputs"}} -
- {{$type := index $input "type"}} - {{if index $input "label"}} - - {{end}} - {{if eq $type "button"}} - - {{else if eq $type "submit"}} - - {{else if eq $type "file"}} - - {{else if eq $type "choice"}} - {{$default_value := index $input "value"}} - - {{else}} - - {{end}} -
- {{end}} -
- - {{if eq $form_type "upload"}} - {{end}} - - {{if index .Meta "display_append"}} - {{option .Meta "display_append"}} - {{else}} - - {{$msg := .}} - {{range $field := append .}}{{end}} - {{range $line := table .}} - {{range $field := append $msg}}{{end}} - {{end}} -
{{$field}}
{{index $line $field|unescape}}
- {{end}} - - {{if index .Meta "display_result"}} - {{option .Meta "display_result"}} - {{else}} -
{{result .Meta}}
- {{end}} -
-{{end}} - {{define "tail"}} - - - + {{range $index, $lib := option . "scripts"}} + + {{end}} + {{end}} + diff --git a/usr/template/wiki/wiki.tmpl b/usr/template/wiki/wiki.tmpl deleted file mode 100644 index 6fe8df0f..00000000 --- a/usr/template/wiki/wiki.tmpl +++ /dev/null @@ -1,221 +0,0 @@ -{{define "head"}} - - - - - -{{option .Meta "page_title"}} - - - -{{end}} - -{{define "header"}} -
-
- -
shylinux 天行健,君子以自强不息
-
-{{end}} - -{{define "list"}} - -{{end}} - -{{define "text"}} -
{{result .|meta|unescape}}
-{{end}} - -{{define "footer"}} - -{{end}} - -{{define "tail"}} - - - -{{end}} diff --git a/usr/wiki/mysql.md b/usr/wiki/mysql.md deleted file mode 100644 index a74df95b..00000000 --- a/usr/wiki/mysql.md +++ /dev/null @@ -1,7 +0,0 @@ -## 简介 -MySQL 是一个开源的关系数据库管理系统。 - -- 官网: -- MAC客户端: - -变量的定义与引用: diff --git a/usr/wiki/自然/编程/前端小程序/chrome.md b/usr/wiki/自然/编程/前端小程序/chrome.md new file mode 100644 index 00000000..e69de29b diff --git a/usr/wiki/html5.css b/usr/wiki/自然/编程/前端小程序/html5.css similarity index 100% rename from usr/wiki/html5.css rename to usr/wiki/自然/编程/前端小程序/html5.css diff --git a/usr/wiki/html5.js b/usr/wiki/自然/编程/前端小程序/html5.js similarity index 100% rename from usr/wiki/html5.js rename to usr/wiki/自然/编程/前端小程序/html5.js diff --git a/usr/wiki/html5.md b/usr/wiki/自然/编程/前端小程序/html5.md similarity index 100% rename from usr/wiki/html5.md rename to usr/wiki/自然/编程/前端小程序/html5.md diff --git a/usr/wiki/自然/编程/前端小程序/index.md b/usr/wiki/自然/编程/前端小程序/index.md new file mode 100644 index 00000000..e69de29b diff --git a/usr/wiki/自然/编程/前端小程序/javascript.md b/usr/wiki/自然/编程/前端小程序/javascript.md new file mode 100644 index 00000000..e69de29b diff --git a/usr/wiki/自然/编程/前端小程序/nodejs.md b/usr/wiki/自然/编程/前端小程序/nodejs.md new file mode 100644 index 00000000..e69de29b diff --git a/usr/wiki/自然/编程/前端小程序/weixin.md b/usr/wiki/自然/编程/前端小程序/weixin.md new file mode 100644 index 00000000..e69de29b diff --git a/usr/wiki/自然/编程/后端技术栈/consul.md b/usr/wiki/自然/编程/后端技术栈/consul.md new file mode 100644 index 00000000..e69de29b diff --git a/usr/wiki/docker.md b/usr/wiki/自然/编程/后端技术栈/docker.md similarity index 100% rename from usr/wiki/docker.md rename to usr/wiki/自然/编程/后端技术栈/docker.md diff --git a/usr/wiki/lamp.md b/usr/wiki/自然/编程/后端技术栈/index.md similarity index 100% rename from usr/wiki/lamp.md rename to usr/wiki/自然/编程/后端技术栈/index.md diff --git a/usr/wiki/自然/编程/后端技术栈/kafka.md b/usr/wiki/自然/编程/后端技术栈/kafka.md new file mode 100644 index 00000000..e69de29b diff --git a/usr/wiki/自然/编程/后端技术栈/linux.md b/usr/wiki/自然/编程/后端技术栈/linux.md new file mode 100644 index 00000000..e69de29b diff --git a/usr/wiki/自然/编程/后端技术栈/mysql.md b/usr/wiki/自然/编程/后端技术栈/mysql.md new file mode 100644 index 00000000..50733e07 --- /dev/null +++ b/usr/wiki/自然/编程/后端技术栈/mysql.md @@ -0,0 +1,37 @@ +## 简介 + +MySQL 是一个开源的关系型数据库管理系统。 + +- 官网: +- 源码: +- 文档: +- 开源: + +## 基础命令 + +## 存储引擎 + +- 下载: + +- 博客: + +变量的定义与引用: + +show engines +show engine innodb status +show variables + +show databases +create database demo +drop database demo +use demo + +show tables +create table t(a int unsigned not null, b char(10), primary key(a)) +drop table t + +select * from t; +insert into t values() +update t set b='1234' +delete from t + diff --git a/usr/wiki/nginx.md b/usr/wiki/自然/编程/后端技术栈/nginx.md similarity index 100% rename from usr/wiki/nginx.md rename to usr/wiki/自然/编程/后端技术栈/nginx.md diff --git a/usr/wiki/自然/编程/后端技术栈/python.md b/usr/wiki/自然/编程/后端技术栈/python.md new file mode 100644 index 00000000..e69de29b diff --git a/usr/wiki/redis.md b/usr/wiki/自然/编程/后端技术栈/redis.md similarity index 96% rename from usr/wiki/redis.md rename to usr/wiki/自然/编程/后端技术栈/redis.md index 5645dab2..68df9ee3 100644 --- a/usr/wiki/redis.md +++ b/usr/wiki/自然/编程/后端技术栈/redis.md @@ -1,11 +1,11 @@ ## 简介 + Redis是一个使用ANSI C编写的开源、支持网络、基于内存、可持久性的键值对存储数据库。 Redis是最流行的键值对存储数据库。 -- 维基百科: -- 官网: -- 源码: -- github: +- 官网: +- 源码: +- 文档: ## 源码安装 ``` diff --git a/usr/wiki/自然/编程/后端技术栈/thrift.md b/usr/wiki/自然/编程/后端技术栈/thrift.md new file mode 100644 index 00000000..e69de29b diff --git a/usr/wiki/自然/编程/后端技术栈/uwsgi.md b/usr/wiki/自然/编程/后端技术栈/uwsgi.md new file mode 100644 index 00000000..e69de29b diff --git a/usr/wiki/context.md b/usr/wiki/自然/编程/终端工具链/context.md similarity index 100% rename from usr/wiki/context.md rename to usr/wiki/自然/编程/终端工具链/context.md diff --git a/usr/wiki/自然/编程/终端工具链/git.md b/usr/wiki/自然/编程/终端工具链/git.md new file mode 100644 index 00000000..e69de29b diff --git a/usr/wiki/golang.md b/usr/wiki/自然/编程/终端工具链/golang.md similarity index 100% rename from usr/wiki/golang.md rename to usr/wiki/自然/编程/终端工具链/golang.md diff --git a/usr/wiki/zsh_tmux_vim.md b/usr/wiki/自然/编程/终端工具链/index.md similarity index 100% rename from usr/wiki/zsh_tmux_vim.md rename to usr/wiki/自然/编程/终端工具链/index.md diff --git a/usr/wiki/自然/编程/终端工具链/tmux.md b/usr/wiki/自然/编程/终端工具链/tmux.md new file mode 100644 index 00000000..e69de29b diff --git a/usr/wiki/自然/编程/终端工具链/vim.md b/usr/wiki/自然/编程/终端工具链/vim.md new file mode 100644 index 00000000..e69de29b diff --git a/usr/wiki/自然/编程/终端工具链/zsh.md b/usr/wiki/自然/编程/终端工具链/zsh.md new file mode 100644 index 00000000..e69de29b