redactor.go 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. package redactor
  2. import (
  3. "context"
  4. h "github.com/theplant/htmlgo"
  5. )
  6. type Builder struct {
  7. tag *h.HTMLTagBuilder
  8. }
  9. type Config struct {
  10. Plugins []string `json:"plugins"`
  11. }
  12. func New() (r *Builder) {
  13. r = &Builder{
  14. tag: h.Tag("redactor"),
  15. }
  16. return
  17. }
  18. func (b *Builder) Value(v string) (r *Builder) {
  19. b.tag.Attr(":value", h.JSONString(v))
  20. return b
  21. }
  22. func (b *Builder) Placeholder(v string) (r *Builder) {
  23. b.tag.Attr(":placeholder", h.JSONString(v))
  24. return b
  25. }
  26. func (b *Builder) Config(v Config) (r *Builder) {
  27. b.tag.Attr(":config", h.JSONString(v))
  28. return b
  29. }
  30. func (b *Builder) RawConfig(v interface{}) (r *Builder) {
  31. b.tag.Attr(":config", h.JSONString(v))
  32. return b
  33. }
  34. func (b *Builder) SetAttr(k string, v interface{}) {
  35. b.tag.SetAttr(k, v)
  36. }
  37. func (b *Builder) Attr(vs ...interface{}) (r *Builder) {
  38. b.tag.Attr(vs...)
  39. return b
  40. }
  41. func (b *Builder) Children(children ...h.HTMLComponent) (r *Builder) {
  42. b.tag.Children(children...)
  43. return b
  44. }
  45. func (b *Builder) AppendChildren(children ...h.HTMLComponent) (r *Builder) {
  46. b.tag.AppendChildren(children...)
  47. return b
  48. }
  49. func (b *Builder) PrependChildren(children ...h.HTMLComponent) (r *Builder) {
  50. b.tag.PrependChildren(children...)
  51. return b
  52. }
  53. func (b *Builder) Class(names ...string) (r *Builder) {
  54. b.tag.Class(names...)
  55. return b
  56. }
  57. func (b *Builder) ClassIf(name string, add bool) (r *Builder) {
  58. b.tag.ClassIf(name, add)
  59. return b
  60. }
  61. func (b *Builder) MarshalHTML(ctx context.Context) (r []byte, err error) {
  62. return b.tag.MarshalHTML(ctx)
  63. }