diff --git a/core/code/css.go b/core/code/css.go new file mode 100644 index 00000000..c975c995 --- /dev/null +++ b/core/code/css.go @@ -0,0 +1,75 @@ +package code + +import ( + "strings" + "path" + + ice "shylinux.com/x/icebergs" + "shylinux.com/x/icebergs/base/ctx" + "shylinux.com/x/icebergs/base/mdb" + "shylinux.com/x/icebergs/base/nfs" + kit "shylinux.com/x/toolkits" +) + +func _css_stat(m *ice.Message, stats map[string]int) { + msg := m.Spawn() + for k, v := range stats { + msg.Push("name", k) + msg.Push("value", v) + msg.Push("block", "stats") + } + msg.SortIntR("value") + m.Copy(msg) +} +func _css_show(m *ice.Message, arg ...string) { + block := "" + stats_key := map[string]int{} + stats_value := map[string]int{} + m.Cmd(nfs.CAT, path.Join(arg[2], arg[1]), func(line string) { + if line = strings.TrimSpace(line); line == "" || strings.HasPrefix(line, "//") || strings.HasPrefix(line, "/*") { + return + } + switch { + case strings.HasSuffix(line, "{"): + block = strings.TrimSuffix(line, "{") + case strings.HasSuffix(line, "}"): + if line == "}" { + break + } + ls := strings.Split(strings.TrimSuffix(line, "}"), "{") + for _, l := range strings.Split(ls[1], ";") { + list := strings.Split(l, ":") + if len(list) < 2 { + continue + } + m.Push("name", list[0]) + m.Push("value", list[1]) + m.Push("block", ls[0]) + stats_key[list[0]]++ + stats_value[list[1]]++ + } + default: + } + }) + _css_stat(m, stats_key) + _css_stat(m, stats_value) + m.StatusTimeCount() +} +func _css_exec(m *ice.Message, arg ...string) { + if arg[2] == "usr/volcanos/" && strings.HasPrefix(arg[1], "plugin/local/") { + key := "web."+strings.ReplaceAll(strings.TrimSuffix(strings.TrimPrefix(arg[1], "plugin/local/"), ".css"), ice.PS, ice.PT) + ctx.ProcessCommand(m, kit.Select("can.plugin", key), kit.Simple()) + return + } +} + +const CSS = "css" + +func init() { + Index.MergeCommands(ice.Commands{ + CSS: {Name: "css path auto", Help: "样式表", Actions: ice.MergeActions(ice.Actions{ + mdb.RENDER: {Hand: func(m *ice.Message, arg ...string) { _css_show(m, arg...) }}, + mdb.ENGINE: {Hand: func(m *ice.Message, arg ...string) { _css_exec(m, arg...) }}, + }, PlugAction(), LangAction())}, + }) +} \ No newline at end of file diff --git a/core/code/js.go b/core/code/js.go index 68a247df..f86d41f2 100644 --- a/core/code/js.go +++ b/core/code/js.go @@ -76,7 +76,7 @@ func _js_show(m *ice.Message, arg ...string) { func _js_exec(m *ice.Message, arg ...string) { if arg[2] == "usr/volcanos/" && strings.HasPrefix(arg[1], "plugin/local/") { key := "web."+strings.ReplaceAll(strings.TrimSuffix(strings.TrimPrefix(arg[1], "plugin/local/"), ".js"), ice.PS, ice.PT) - ctx.ProcessCommand(m, kit.Select("can.code.inner._plugin", key), kit.Simple()) + ctx.ProcessCommand(m, kit.Select("can.plugin", key), kit.Simple()) return } m.Display(path.Join("/require", path.Join(arg[2], arg[1]))) @@ -88,7 +88,6 @@ func _js_exec(m *ice.Message, arg ...string) { } const JS = "js" -const CSS = "css" const HTML = "html" const JSON = "json" diff --git a/core/code/vimer.go b/core/code/vimer.go index 9059284f..497ffcea 100644 --- a/core/code/vimer.go +++ b/core/code/vimer.go @@ -166,7 +166,7 @@ func init() { }}, }, Hand: func(m *ice.Message, arg ...string) { if m.Cmdy(INNER, arg); arg[0] != ctx.ACTION { - m.Action(nfs.SAVE, COMPILE, AUTOGEN, nfs.SCRIPT, web.WEBSITE, web.DREAM, XTERM) + m.Action(AUTOGEN, nfs.SCRIPT, web.WEBSITE, web.DREAM, nfs.SAVE, COMPILE, XTERM) m.Option("tabs", m.Config("show.tabs")) m.Option("plug", m.Config("show.plug")) m.Option("exts", m.Config("show.exts"))