1
0
forked from x/icebergs
This commit is contained in:
harveyshao 2022-10-22 16:36:20 +08:00
parent 97442c1104
commit 1348b8a1f5
3 changed files with 77 additions and 3 deletions

75
core/code/css.go Normal file
View File

@ -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())},
})
}

View File

@ -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"

View File

@ -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"))