vuetifyjs.go 1006 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. package vuetify
  2. import (
  3. "embed"
  4. "strings"
  5. "github.com/qor5/web"
  6. )
  7. //go:embed dist
  8. var assetsbox embed.FS
  9. func JSComponentsPack() web.ComponentsPack {
  10. v, err := assetsbox.ReadFile("dist/vuetify.min.js")
  11. if err != nil {
  12. panic(err)
  13. }
  14. return web.ComponentsPack(v)
  15. }
  16. func CSSComponentsPack() web.ComponentsPack {
  17. v, err := assetsbox.ReadFile("dist/vuetify.min.css")
  18. if err != nil {
  19. panic(err)
  20. }
  21. return web.ComponentsPack(v)
  22. }
  23. const initVuetify = `
  24. (window.__goplaidVueComponentRegisters =
  25. window.__goplaidVueComponentRegisters || []).push(function(Vue, vueOptions) {
  26. var vuetify = new Vuetify({{vuetifyOpts}});
  27. Vue.use(Vuetify);
  28. vueOptions.vuetify = vuetify;
  29. });
  30. `
  31. const defaultVuetifyOpts = `{
  32. icons: {
  33. iconfont: 'md', // 'mdi' || 'mdiSvg' || 'md' || 'fa' || 'fa4'
  34. },
  35. }`
  36. func Vuetify(opts string) web.ComponentsPack {
  37. if opts == "" {
  38. opts = defaultVuetifyOpts
  39. }
  40. return web.ComponentsPack(
  41. strings.NewReplacer("{{vuetifyOpts}}", opts).
  42. Replace(initVuetify),
  43. )
  44. }