forked from x/icebergs
opt some
This commit is contained in:
parent
1dea5983e1
commit
c02663d87d
@ -74,6 +74,7 @@ func Render(msg *ice.Message, cmd string, args ...ice.Any) {
|
|||||||
} {
|
} {
|
||||||
msg.Set(k)
|
msg.Set(k)
|
||||||
}
|
}
|
||||||
|
msg.Debug("what %v %v", cmd, args)
|
||||||
|
|
||||||
if cmd != "" && cmd != ice.RENDER_RAW { // [str [arg...]]
|
if cmd != "" && cmd != ice.RENDER_RAW { // [str [arg...]]
|
||||||
msg.Echo(kit.Format(cmd, args...))
|
msg.Echo(kit.Format(cmd, args...))
|
||||||
|
@ -9,7 +9,7 @@ const AUDIO = "audio"
|
|||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
Index.MergeCommands(ice.Commands{
|
Index.MergeCommands(ice.Commands{
|
||||||
AUDIO: {Name: "audio url", Help: "音频", Actions: WordAction(
|
AUDIO: {Name: "audio url run", Help: "音频", Actions: WordAction(
|
||||||
`<audio {{.OptionTemplate}} title="{{.Option "text"}}" src="{{.Option "text"}}" controls></audio>`, nfs.PATH, ice.USR_LOCAL_IMAGE,
|
`<audio {{.OptionTemplate}} title="{{.Option "text"}}" src="{{.Option "text"}}" controls></audio>`, nfs.PATH, ice.USR_LOCAL_IMAGE,
|
||||||
), Hand: func(m *ice.Message, arg ...string) { _image_show(m, arg[0], arg[1:]...) }},
|
), Hand: func(m *ice.Message, arg ...string) { _image_show(m, arg[0], arg[1:]...) }},
|
||||||
})
|
})
|
||||||
|
@ -8,7 +8,7 @@ const BRIEF = "brief"
|
|||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
Index.MergeCommands(ice.Commands{
|
Index.MergeCommands(ice.Commands{
|
||||||
BRIEF: {Name: "brief text", Help: "摘要", Actions: WordAction(
|
BRIEF: {Name: "brief text run", Help: "摘要", Actions: WordAction(
|
||||||
`<p {{.OptionTemplate}}>{{.Option "text"}}</p>`,
|
`<p {{.OptionTemplate}}>{{.Option "text"}}</p>`,
|
||||||
), Hand: func(m *ice.Message, arg ...string) { _wiki_template(m, "", arg[0], arg[1:]...) }},
|
), Hand: func(m *ice.Message, arg ...string) { _wiki_template(m, "", arg[0], arg[1:]...) }},
|
||||||
})
|
})
|
||||||
|
@ -12,12 +12,8 @@ type Item struct {
|
|||||||
args []ice.Any
|
args []ice.Any
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewItem(list []string, args ...ice.Any) *Item {
|
func NewItem(str string, args ...ice.Any) *Item {
|
||||||
return &Item{list, args}
|
return &Item{[]string{str}, args}
|
||||||
}
|
|
||||||
func (item *Item) Echo(str string, arg ...ice.Any) *Item {
|
|
||||||
item.list = append(item.list, kit.Format(str, arg...))
|
|
||||||
return item
|
|
||||||
}
|
}
|
||||||
func (item *Item) Push(str string, arg ice.Any) *Item {
|
func (item *Item) Push(str string, arg ice.Any) *Item {
|
||||||
switch arg := arg.(type) {
|
switch arg := arg.(type) {
|
||||||
@ -33,6 +29,10 @@ func (item *Item) Push(str string, arg ice.Any) *Item {
|
|||||||
item.list, item.args = append(item.list, str), append(item.args, arg)
|
item.list, item.args = append(item.list, str), append(item.args, arg)
|
||||||
return item
|
return item
|
||||||
}
|
}
|
||||||
|
func (item *Item) Echo(str string, arg ...ice.Any) *Item {
|
||||||
|
item.list = append(item.list, kit.Format(str, arg...))
|
||||||
|
return item
|
||||||
|
}
|
||||||
func (item *Item) Dump(m *ice.Message) *ice.Message {
|
func (item *Item) Dump(m *ice.Message) *ice.Message {
|
||||||
return m.Echo(kit.Join(item.list, ice.SP), item.args...).Echo(ice.NL)
|
return m.Echo(kit.Join(item.list, ice.SP), item.args...).Echo(ice.NL)
|
||||||
}
|
}
|
||||||
@ -57,14 +57,14 @@ func (g *Group) Option(group string, key string, arg ...ice.Any) string {
|
|||||||
func (g *Group) Get(group string) *ice.Message { return g.list[group] }
|
func (g *Group) Get(group string) *ice.Message { return g.list[group] }
|
||||||
|
|
||||||
func (g *Group) Join(arg ...string) string {
|
func (g *Group) Join(arg ...string) string {
|
||||||
args := []string{}
|
res := []string{}
|
||||||
for i := 0; i < len(arg)-1; i += 2 {
|
for i := 0; i < len(arg)-1; i += 2 {
|
||||||
if arg[i] == "" {
|
if arg[i] == "" {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
args = append(args, kit.Format(`%s="%s"`, arg[i], arg[i+1]))
|
res = append(res, kit.Format(`%s="%s"`, arg[i], arg[i+1]))
|
||||||
}
|
}
|
||||||
return kit.Join(args, ice.SP)
|
return kit.Join(res, ice.SP)
|
||||||
}
|
}
|
||||||
func (g *Group) Echo(group string, str string, arg ...ice.Any) *ice.Message {
|
func (g *Group) Echo(group string, str string, arg ...ice.Any) *ice.Message {
|
||||||
return g.Get(group).Echo(str, arg...)
|
return g.Get(group).Echo(str, arg...)
|
||||||
@ -102,7 +102,7 @@ func (g *Group) EchoArrowLine(group string, x1, y1, x2, y2 int, arg ...string) *
|
|||||||
return g.Echo(group, "<line x1=%d y1=%d x2=%d y2=%d marker-end='url(#%s)'></line>", x1, y1, x2, y2, kit.Select("arrowhead", arg, 0))
|
return g.Echo(group, "<line x1=%d y1=%d x2=%d y2=%d marker-end='url(#%s)'></line>", x1, y1, x2, y2, kit.Select("arrowhead", arg, 0))
|
||||||
}
|
}
|
||||||
func (g *Group) Dump(m *ice.Message, group string, arg ...string) *Group {
|
func (g *Group) Dump(m *ice.Message, group string, arg ...string) *Group {
|
||||||
item := NewItem([]string{"<g name=%s"}, group)
|
item := NewItem("<g name=%s", group)
|
||||||
for _, k := range kit.Simple(STROKE_DASHARRAY, STROKE_WIDTH, STROKE, FILL, FONT_SIZE, FONT_FAMILY, arg) {
|
for _, k := range kit.Simple(STROKE_DASHARRAY, STROKE_WIDTH, STROKE, FILL, FONT_SIZE, FONT_FAMILY, arg) {
|
||||||
v := m.Option(kit.Keys(group, k))
|
v := m.Option(kit.Keys(group, k))
|
||||||
switch k {
|
switch k {
|
||||||
|
@ -60,10 +60,10 @@ func (b *Block) Data(m *ice.Message, meta ice.Any) wiki.Chart {
|
|||||||
func (b *Block) Draw(m *ice.Message, x, y int) wiki.Chart {
|
func (b *Block) Draw(m *ice.Message, x, y int) wiki.Chart {
|
||||||
float := kit.Int(kit.Select("2", "7", strings.Contains(m.Option(ice.MSG_USERUA), "iPhone")))
|
float := kit.Int(kit.Select("2", "7", strings.Contains(m.Option(ice.MSG_USERUA), "iPhone")))
|
||||||
if m.Option(HIDE_BLOCK) != ice.TRUE {
|
if m.Option(HIDE_BLOCK) != ice.TRUE {
|
||||||
item := wiki.NewItem([]string{`<rect height="%d" width="%d" rx="4" ry="4" x="%d" y="%d"`}, b.GetHeight(), b.GetWidth(), x+b.MarginX/2, y+b.MarginY/2)
|
item := wiki.NewItem(`<rect height="%d" width="%d" rx="4" ry="4" x="%d" y="%d"`, b.GetHeight(), b.GetWidth(), x+b.MarginX/2, y+b.MarginY/2)
|
||||||
item.Push(`fill="%s"`, b.BackGround).Push(`%v`, b.RectData).Echo("/>").Dump(m)
|
item.Push(`fill="%s"`, b.BackGround).Push(`%v`, b.RectData).Echo("/>").Dump(m)
|
||||||
}
|
}
|
||||||
item := wiki.NewItem([]string{`<text x="%d" y="%d"`}, x+b.GetWidths()/2, y+b.GetHeights()/2+float)
|
item := wiki.NewItem(`<text x="%d" y="%d"`, x+b.GetWidths()/2, y+b.GetHeights()/2+float)
|
||||||
item.Push(`fill="%s"`, kit.Select(m.Option(wiki.STROKE), b.FontColor))
|
item.Push(`fill="%s"`, kit.Select(m.Option(wiki.STROKE), b.FontColor))
|
||||||
item.Push(`stroke-width="%d"`, 1)
|
item.Push(`stroke-width="%d"`, 1)
|
||||||
item.Push(`stroke="%s"`, b.FontColor).Push(`fill="%s"`, b.FontColor).Push("%v", b.TextData).Push(`>%v</text>`, b.Text).Dump(m)
|
item.Push(`stroke="%s"`, b.FontColor).Push(`fill="%s"`, b.FontColor).Push("%v", b.TextData).Push(`>%v</text>`, b.Text).Dump(m)
|
||||||
|
@ -47,9 +47,6 @@ func Render(m *Message, cmd string, args ...Any) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (m *Message) Render(cmd string, args ...Any) *Message {
|
func (m *Message) Render(cmd string, args ...Any) *Message {
|
||||||
m.Optionv(MSG_OUTPUT, cmd)
|
|
||||||
m.Optionv(MSG_ARGS, args)
|
|
||||||
|
|
||||||
switch cmd {
|
switch cmd {
|
||||||
case RENDER_TEMPLATE: // text [data]
|
case RENDER_TEMPLATE: // text [data]
|
||||||
if len(args) == 1 {
|
if len(args) == 1 {
|
||||||
@ -58,7 +55,11 @@ func (m *Message) Render(cmd string, args ...Any) *Message {
|
|||||||
if res, err := kit.Render(args[0].(string), args[1]); m.Assert(err) {
|
if res, err := kit.Render(args[0].(string), args[1]); m.Assert(err) {
|
||||||
m.Echo(string(res))
|
m.Echo(string(res))
|
||||||
}
|
}
|
||||||
|
return m
|
||||||
}
|
}
|
||||||
|
m.Optionv(MSG_OUTPUT, cmd)
|
||||||
|
m.Optionv(MSG_ARGS, args)
|
||||||
|
|
||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
func (m *Message) RenderTemplate(args ...Any) *Message {
|
func (m *Message) RenderTemplate(args ...Any) *Message {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user