feat(web): Go plugin W-G1 assemble/render + SQLite smoke path
Port table/compose/style/render/db/form/app bags, register ABI symbols, prefer MARQDO_WEB_PLUGIN over ~/.marqdo, and pass web-smoke + web-zh-smoke. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
fd3f1724e6
commit
7a0309284a
17 files changed
+4120
-18
No files matched your search
@@ -0,0 +1,63 @@
|
||||
// Package style implements web_style (CSS from GFM style tables).
|
||||
package style
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/marqdo/marqdo/plugins/web/internal/table"
|
||||
)
|
||||
|
||||
// Style matches Rust web_style: args name + table + optional strict → CSS string.
|
||||
func Style(args map[string]any) (string, error) {
|
||||
name := ""
|
||||
if v, ok := args["name"]; ok && v != nil {
|
||||
name = cellStr(v)
|
||||
}
|
||||
var tbl any = []any{}
|
||||
if v, ok := args["table"]; ok && v != nil {
|
||||
tbl = v
|
||||
}
|
||||
strict := false
|
||||
for _, k := range []string{"strict", "strict_css_cells", "严格"} {
|
||||
if v, ok := args[k]; ok {
|
||||
strict = boolishStrict(v)
|
||||
break
|
||||
}
|
||||
}
|
||||
return table.AsCSSNamedChecked(name, tbl, strict)
|
||||
}
|
||||
|
||||
func cellStr(v any) string {
|
||||
switch t := v.(type) {
|
||||
case string:
|
||||
return t
|
||||
case float64:
|
||||
if t == float64(int64(t)) {
|
||||
return strconv.FormatInt(int64(t), 10)
|
||||
}
|
||||
return strconv.FormatFloat(t, 'f', -1, 64)
|
||||
case bool:
|
||||
return strconv.FormatBool(t)
|
||||
default:
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
func boolishStrict(v any) bool {
|
||||
switch t := v.(type) {
|
||||
case bool:
|
||||
return t
|
||||
case float64:
|
||||
return int64(t) != 0
|
||||
case string:
|
||||
s := strings.TrimSpace(t)
|
||||
switch s {
|
||||
case "1", "true", "True", "yes", "on", "真", "是":
|
||||
return true
|
||||
}
|
||||
return false
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package style_test
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/marqdo/marqdo/plugins/web/internal/style"
|
||||
)
|
||||
|
||||
func TestStyleSimple(t *testing.T) {
|
||||
css, err := style.Style(map[string]any{
|
||||
"name": "card",
|
||||
"table": []any{
|
||||
map[string]any{"选择器": ".card", "属性": "color", "值": "navy"},
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !strings.Contains(css, ".card {") || !strings.Contains(css, "color: navy;") {
|
||||
t.Fatalf("%q", css)
|
||||
}
|
||||
}
|
||||
|
||||
func TestStyleStrictRejectsNumeric(t *testing.T) {
|
||||
_, err := style.Style(map[string]any{
|
||||
"name": "x",
|
||||
"strict": true,
|
||||
"table": []any{
|
||||
map[string]any{"选择器": ".x", "属性": "grid-column", "值": float64(0)},
|
||||
},
|
||||
})
|
||||
if err == nil || !strings.Contains(err.Error(), "suspicious") {
|
||||
t.Fatalf("err=%v", err)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user