diff --git a/src/contexts/ctx/cgi.go b/src/contexts/ctx/cgi.go index 943f4f8d..94d01808 100644 --- a/src/contexts/ctx/cgi.go +++ b/src/contexts/ctx/cgi.go @@ -226,3 +226,15 @@ func ExecuteStr(m *Message, w io.Writer, p string) error { tmpl, _ = tmpl.Parse(p) return tmpl.Execute(w, m) } +func Execute(m *Message, p string) string { + m.Log("fuck", "waht %v", path.Join(m.Conf("route", "template_dir"), "/*.tmpl")) + t := template.Must(template.New("render").Funcs(CGI).ParseGlob(path.Join(m.Conf("route", "template_dir"), "/*.tmpl"))) + for _, v := range t.Templates() { + m.Log("fuck", "waht %v", v.Name()) + } + buf := bytes.NewBuffer(make([]byte, 0, 1024)) + t.ExecuteTemplate(buf, p, m) + m.Log("fuck", "waht %v", p) + m.Log("fuck", "waht %v", buf) + return buf.String() +} diff --git a/src/examples/chat/chat.go b/src/examples/chat/chat.go index 27eff079..8d351103 100644 --- a/src/examples/chat/chat.go +++ b/src/examples/chat/chat.go @@ -6,7 +6,6 @@ import ( mis "github.com/shylinux/toolkits" "fmt" - "io/ioutil" "net/http" "os" "path" @@ -98,7 +97,7 @@ var Index = &ctx.Context{Name: "chat", Help: "会议中心", }, map[string]interface{}{"name": "tail", "tmpl": "tail", "scripts": []interface{}{ - "toolkit.js", "context.js", "example.js", "chat.js", + "volcanos.js", "toolkit.js", "context.js", "example.js", "chat.js", }, }, }, @@ -509,19 +508,22 @@ var Index = &ctx.Context{Name: "chat", Help: "会议中心", case "wiki": // 查看文档 p := path.Join(path.Join("var/share", h)) - if _, e := os.Stat(p); e == nil { - // 读取缓存 - m.Log("info", "read cache %v", p) - r := m.Optionv("request").(*http.Request) - w := m.Optionv("response").(http.ResponseWriter) - http.ServeFile(w, r, p) - break + if !m.Options("force") { + if _, e := os.Stat(p); e == nil { + // 读取缓存 + m.Log("info", "read cache %v", p) + r := m.Optionv("request").(*http.Request) + w := m.Optionv("response").(http.ResponseWriter) + http.ServeFile(w, r, p) + break + } } + m.Option("title", fmt.Sprintf("%v:%v", value["dream"], value["code"])) + m.Option("favicon", "favicon.ico") // 生成模板 - if b, e := ioutil.ReadFile("usr/template/share.tmpl"); e == nil { - m.Echo(string(b)) - } + m.Echo(ctx.Execute(m, "share.tmpl")) + // 生成文档 m.Cmdy("ssh._route", value["dream"], "web.wiki.note", value["code"]) if f, _, e := kit.Create(p); e == nil { diff --git a/src/plugin/story/index.shy b/src/plugin/story/index.shy index 5615b860..0c46169e 100644 --- a/src/plugin/story/index.shy +++ b/src/plugin/story/index.shy @@ -1,6 +1,7 @@ kit share "共享" public "web.chat.share" \ select "" name type values "wiki file" \ text "miss.md" name story imports plugin_story view long \ + feature display chart \ button "共享" kit note "记事本" public "_:web.wiki.note" "@you" \ @@ -46,6 +47,6 @@ kit chart "图表" public "web.wiki.chart" \ textarea "" name happy half 4 height "200px" \ select "" name type values "white red yellow green blue black" action auto \ select "" name type values "black blue green yellow red white" action auto \ - feature display svg \ + feature display chart \ button "查看" diff --git a/usr/librarys/chat.js b/usr/librarys/chat.js index b00bfd0f..6e1cb6b7 100644 --- a/usr/librarys/chat.js +++ b/usr/librarys/chat.js @@ -680,3 +680,4 @@ var page = Page({ setTimeout(update, 1) }, }) + diff --git a/usr/librarys/example.js b/usr/librarys/example.js index 6272f98c..23c507c7 100644 --- a/usr/librarys/example.js +++ b/usr/librarys/example.js @@ -1219,7 +1219,11 @@ function Plugin(page, pane, field, inits, runs) { }, }, function(type, msg, cb) {var meta = arguments.callee.meta type != meta.type && plugin.Save(meta.type, output), meta.type = type - !plugin.Load(type, output) && Output(plugin, type || feature.display, msg || plugin.msg, cb, output, option) + if (type == "chart") { + can.chat.Output(can, plugin, type || feature.display, msg || plugin.msg, cb, output, option) + return + } + !plugin.Load(type, output) && (type=="chart"? can.chat.Output: Output)(plugin, type || feature.display, msg || plugin.msg, cb, output, option) }), onexport: shy("导出数据", { "": function(value, name, line) { @@ -1698,3 +1702,40 @@ function Output(plugin, type, msg, cb, target, option) { output.onimport(type, msg, cb) return plugin.Outputs[type] = target, target.Output = output } + +var can = Volcanos("chat", { + Plugin: shy("构造插件", function(can) {}), + Output: shy("构造组件", function(can, plugin, type, msg, cb, target, option) { + type = "table" + var output = Volcanos(type, { + user: can.user, node: can.node, + core: can.core, type: can.type, + oncarte: plugin.oncarte, + run: plugin.run, + size: function(cb) { + plugin.onfigure.meta.size(function(width, height) { + cb(width, height) + }) + } + }, [type], function(output) { + target.oncontextmenu = function(event) { + plugin.oncarte(event, shy("", output.onchoice, output.onchoice.list, function(event, value, meta) { + typeof meta[value] == "function"? meta[value](event, can, msg, cb, target, option): + typeof output[value] == "function"? output[value](event, can, msg, cb, target, option): + typeof plugin[value] == "function"? plugin[value](event, can, msg, cb, target, option): null + return true + })) + event.stopPropagation() + event.preventDefault() + return true + } + output.load().onimport.init(output, msg, cb, target, option) + }) + kit.Item(output.onaction, function(key, cb) {target[key] = function(event) { + output.onaction(event, can, msg, cb, target, option) + }}) + plugin[type] = output, output.target = target, target.Output = output + }), + Input: shy("构造控件", function(can, plugin, type, meta, target, option) { + }), +}, [], function(can) {can.load()}) diff --git a/usr/librarys/share.css b/usr/librarys/share.css new file mode 100644 index 00000000..01e45bb7 --- /dev/null +++ b/usr/librarys/share.css @@ -0,0 +1,12 @@ +div.story.code { + color:white; + font-size:14px; + font-family:monospace; + background-color:#272822; + white-space:pre; + padding:10px; + border:solid 3px green; + max-height:640px; + overflow:auto; +} + diff --git a/usr/librarys/share.js b/usr/librarys/share.js new file mode 100644 index 00000000..1a77e35d --- /dev/null +++ b/usr/librarys/share.js @@ -0,0 +1,6 @@ +window.onload = function() { + Volcanos("shy", {}, [], function(can) { + can.load() + }) +} + diff --git a/usr/librarys/volcanos.js b/usr/librarys/volcanos.js new file mode 120000 index 00000000..0a1fbe86 --- /dev/null +++ b/usr/librarys/volcanos.js @@ -0,0 +1 @@ +../volcanos/volcanos.js \ No newline at end of file diff --git a/usr/local/wiki/volcano.md b/usr/local/wiki/volcano.md new file mode 100644 index 00000000..482566db --- /dev/null +++ b/usr/local/wiki/volcano.md @@ -0,0 +1,17 @@ +# {{title "Volcanos.js"}} + +volcanos是一个前端框架。 +模块化 +通过建立脚本的依赖关系,按需加载相关文件,从而更加高效的组织项目文件。 +{{chart "chain" ` +Volcanos + Volcanos + Volcanos + Volcanos +`}} + +## {{section "type模块"}} +## {{section "core模块"}} +## {{section "node模块"}} +## {{section "misc模块"}} +## {{section "device模块"}} diff --git a/usr/template/share.tmpl b/usr/template/share.tmpl index f4676eee..bc67bfdf 100644 --- a/usr/template/share.tmpl +++ b/usr/template/share.tmpl @@ -1,13 +1,10 @@ - + +
+ +