{{.}}
-
{{end}}
{{else if append . "code"|meta}}
-
{{append . "code"|meta}}
- {{else}} -
{{append . "body"|meta|unscaped}}
+{{append . "code"|meta}}
+ {{else}} +
{{append . "body"|meta|unscaped}}
{{end}}diff --git a/src/contexts/lex/lex.go b/src/contexts/lex/lex.go index 6d09372c..404ee290 100644 --- a/src/contexts/lex/lex.go +++ b/src/contexts/lex/lex.go @@ -341,9 +341,16 @@ func (lex *LEX) Close(m *ctx.Message, arg ...string) bool { // {{{ // }}} var Index = &ctx.Context{Name: "lex", Help: "词法中心", - Caches: map[string]*ctx.Cache{}, + Caches: map[string]*ctx.Cache{ + "nmat": &ctx.Cache{Name: "nmat", Value: "0", Help: "nmat"}, + }, Configs: map[string]*ctx.Config{}, Commands: map[string]*ctx.Command{ + "spawn": &ctx.Command{Name: "spawn", Help: "添加词法规则", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) { + if _, ok := m.Target().Server.(*LEX); m.Assert(ok) { // {{{ + m.Start(fmt.Sprintf("matrix%d", m.Capi("nmat", 1)), "matrix") + } // }}} + }}, "train": &ctx.Command{Name: "train seed [hash [page]", Help: "添加词法规则", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) { if lex, ok := m.Target().Server.(*LEX); m.Assert(ok) { // {{{ page, hash := 1, 1 diff --git a/src/contexts/web/web.go b/src/contexts/web/web.go index bcc13006..1db98234 100644 --- a/src/contexts/web/web.go +++ b/src/contexts/web/web.go @@ -280,20 +280,20 @@ func (web *WEB) Start(m *ctx.Message, arg ...string) bool { // {{{ web.Configs["logheaders"] = &ctx.Config{Name: "日志输出报文头(yes/no)", Value: "no", Help: "日志输出报文头"} m.Capi("nserve", 1) - yac := m.Sess("tags", m.Sess("yac").Cmd("scan")) - yac.Cmd("train", "void", "void", "[\t ]+") - yac.Cmd("train", "other", "other", "[^\n]+") - yac.Cmd("train", "key", "key", "[A-Za-z_][A-Za-z_0-9]*") - yac.Cmd("train", "code", "def", "def", "key", "(", "other") - yac.Cmd("train", "code", "def", "class", "key", "other") - yac.Cmd("train", "code", "struct", "struct", "key", "\\{") - yac.Cmd("train", "code", "struct", "\\}", "key", ";") - yac.Cmd("train", "code", "struct", "typedef", "struct", "key", "key", ";") - yac.Cmd("train", "code", "function", "key", "\\*", "key", "(", "other") - yac.Cmd("train", "code", "function", "key", "key", "(", "other") - yac.Cmd("train", "code", "variable", "struct", "key", "key", "other") - yac.Cmd("train", "code", "define", "#define", "key", "other") - + // yac := m.Sess("tags", m.Sess("yac").Cmd("scan")) + // yac.Cmd("train", "void", "void", "[\t ]+") + // yac.Cmd("train", "other", "other", "[^\n]+") + // yac.Cmd("train", "key", "key", "[A-Za-z_][A-Za-z_0-9]*") + // yac.Cmd("train", "code", "def", "def", "key", "(", "other") + // yac.Cmd("train", "code", "def", "class", "key", "other") + // yac.Cmd("train", "code", "struct", "struct", "key", "\\{") + // yac.Cmd("train", "code", "struct", "\\}", "key", ";") + // yac.Cmd("train", "code", "struct", "typedef", "struct", "key", "key", ";") + // yac.Cmd("train", "code", "function", "key", "\\*", "key", "(", "other") + // yac.Cmd("train", "code", "function", "key", "key", "(", "other") + // yac.Cmd("train", "code", "variable", "struct", "key", "key", "other") + // yac.Cmd("train", "code", "define", "#define", "key", "other") + // if m.Cap("protocol") == "https" { web.Caches["cert"] = &ctx.Cache{Name: "服务证书", Value: m.Conf("cert"), Help: "服务证书"} web.Caches["key"] = &ctx.Cache{Name: "服务密钥", Value: m.Conf("key"), Help: "服务密钥"} diff --git a/src/contexts/yac/yac.go b/src/contexts/yac/yac.go index 0c03836e..aed6655c 100644 --- a/src/contexts/yac/yac.go +++ b/src/contexts/yac/yac.go @@ -34,6 +34,7 @@ type YAC struct { mat []map[byte]*State state map[State]*State + lex *ctx.Message *ctx.Context } diff --git a/usr/library/base.js b/usr/library/base.js new file mode 100644 index 00000000..6ab18a33 --- /dev/null +++ b/usr/library/base.js @@ -0,0 +1,59 @@ + +function update(event, module, details, key) { + if (event) { + window[key+"timer"] = !window[key+"timer"]; + } + if (!window[key+"timer"]) { + return + } + console.log("update "+key) + setTimeout(function() { + action(event, module, details, key); + update(null, module, details, key); + }, refresh_time); +} + +function input(event, module, details, key) { + if (event.code == "Enter") { + action(event, module, details, key); + } +} +function action(event, module, details, key) { + var input = document.getElementsByClassName(key+"_input"); + for (var i = 0; i < input.length; i++ ){ + if (input[i].value != "") { + details.push(input[i].value) + } + } + ctx.POST("", {module:module, details:details}, function(msg) { + if (msg && msg.result) { + var result = document.getElementsByClassName(key+"_result")[0]; + result.innerHTML = msg.result; + } + if (!msg || !msg.append || msg.append.length < 1) { + return + } + + var append = document.getElementsByClassName(key+"_append")[0]; + if (append.rows.length == msg[msg.append[0]].length+1) { + return + } + append.innerHTML = ''; + var tr = append.insertRow(0); + for (var i in msg.append) { + var th = tr.appendChild(document.createElement("th")); + th.appendChild(document.createTextNode(msg.append[i])); + } + + for (var i = 0; i < msg[msg.append[0]].length; i++) { + var tr = append.insertRow(1); + for (var j in msg.append) { + var td = tr.appendChild(document.createElement("td")); + td.appendChild(document.createTextNode(msg[msg.append[j]][i])); + } + } + var div = append.parent; + + }) + return false; +} diff --git a/usr/library/wiki.js b/usr/library/wiki.js new file mode 100644 index 00000000..a0ac942e --- /dev/null +++ b/usr/library/wiki.js @@ -0,0 +1,154 @@ +function jumpto(url) { + if (url == "..") { + var ps = locaiton.href.split(); + } + location.href=url; +} +function keyup(event) { + console.log(event); + if (typeof window.control == "function") { + control(event); + } + if (event.key == "z") { + var input = document.getElementsByClassName("query_input")[0]; + if (!window.query_show) { + window.query_show = true; + var query = document.getElementsByClassName("query_menu")[0]; + var input = query.getElementsByTagName("input")[0]; + input.style.visibility = "visible"; + input.style.width = "80px"; + input.focus(); + } + return true + } + return true +} +document.onkeyup = keyup; +function toggle() { + window.list_hide = !window.list_hide; + var list = document.getElementsByClassName("list")[0]; + var content = document.getElementsByClassName("content")[0]; + if (list_hide) { + list.style.visibility = "hidden"; + list.style.width="0px"; + list.style.height="0px"; + list.style["min-width"]="0px"; + content.style.width="100%"; + } else { + list.style.visibility = "visible"; + list.style.width="15%"; + list.style.height="100%"; + list.style["min-width"]="180px"; + content.style.width="85%"; + } +} +function menu() { + var max = 0; + var min = 1000; + var list = []; + var hs = ["h2", "h3"]; + 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 = "head"+head[j].offsetTop; + 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 index2 = -1; + var index3 = 0; + for (var i = 0; i < list.length; i++) { + if (list[i].level == "h2") { + index2++; + index3=0; + } else { + index3++; + list[i].index3 = index3; + } + list[i].index2 = index2; + } + + 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 + } + text += " " + text += list[j].title; + + var h = document.getElementById(list[j].hash) + h.innerText = text + + var one = m[i].appendChild(document.createElement("div")); + var a = one.appendChild(document.createElement("a")); + a.href = "#"+list[j].hash; + a.innerText = text+" ("+parseInt((list[j].position-min)/max*100)+"%)"; + + one.className = list[j].level; + } + } +} +function query(event) { + if (event) { + if (event.code == "Enter") { + jumpto("/wiki/?query="+encodeURIComponent(event.target.value)); + } + console.log("what") + return true + } + window.query_show = !window.query_show; + var query = document.getElementsByClassName("query_menu")[0]; + var input = query.getElementsByTagName("input")[0]; + if (window.query_show) { + input.style.visibility = "visible"; + input.style.width = "80px"; + + } else { + input.style.visibility = "hidden"; + input.style.width = "0px"; + } +} +var tags_list = {}; +ctx.GET("/wiki/define.json", undefined, function(msg){ + tags_list = msg["define"]; +}) +function tags(event) { + console.log(event); + + if (event.srcElement.tagName == "CODE") { + var tag = document.getSelection().toString(); + console.log(tag); + if (tag && tag.length > 0 && tags_list[tag]) { + var position = tags_list[tag].position; + if (position.length == 1) { + jumpto("/wiki/src/"+position[0].file+"#hash_"+position[0].line); + } else { + jumpto("/wiki/?query="+encodeURIComponent(tag)); + } + } + } +} +document.onmouseup = tags; +window.onload = function() { + toggle(); + menu(); +} diff --git a/usr/template/common/base.html b/usr/template/common/base.html index 26466984..75b7224e 100644 --- a/usr/template/common/base.html +++ b/usr/template/common/base.html @@ -41,66 +41,7 @@ } - +
{{end}} @@ -135,11 +76,10 @@ function action(event, module, details, key) { {{end}} diff --git a/usr/template/common/wiki.html b/usr/template/common/wiki.html index d136ba31..ae1a8c2f 100644 --- a/usr/template/common/wiki.html +++ b/usr/template/common/wiki.html @@ -5,35 +5,6 @@ {{end}} {{define "wiki_list"}} -{{.}}
{{append . "code"|meta}}
- {{else}} -
{{append . "body"|meta|unscaped}}
+{{append . "code"|meta}}
+ {{else}} +
{{append . "body"|meta|unscaped}}
{{end}}