manifest_serializer.rb 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. # frozen_string_literal: true
  2. class ManifestSerializer < ActiveModel::Serializer
  3. include RoutingHelper
  4. include ActionView::Helpers::TextHelper
  5. ICON_SIZES = %w(
  6. 36
  7. 48
  8. 72
  9. 96
  10. 144
  11. 192
  12. 256
  13. 384
  14. 512
  15. ).freeze
  16. attributes :name, :short_name,
  17. :icons, :theme_color, :background_color,
  18. :display, :start_url, :scope,
  19. :share_target, :shortcuts
  20. def name
  21. object.title
  22. end
  23. def short_name
  24. object.title
  25. end
  26. def icons
  27. ICON_SIZES.map do |size|
  28. {
  29. src: full_pack_url("media/icons/android-chrome-#{size}x#{size}.png"),
  30. sizes: "#{size}x#{size}",
  31. type: 'image/png',
  32. }
  33. end
  34. end
  35. def theme_color
  36. '#6364FF'
  37. end
  38. def background_color
  39. '#191b22'
  40. end
  41. def display
  42. 'standalone'
  43. end
  44. def start_url
  45. '/web/home'
  46. end
  47. def scope
  48. '/'
  49. end
  50. def share_target
  51. {
  52. url_template: 'share?title={title}&text={text}&url={url}',
  53. action: 'share',
  54. method: 'GET',
  55. enctype: 'application/x-www-form-urlencoded',
  56. params: {
  57. title: 'title',
  58. text: 'text',
  59. url: 'url',
  60. },
  61. }
  62. end
  63. def shortcuts
  64. [
  65. {
  66. name: 'Compose new post',
  67. url: '/web/publish',
  68. },
  69. {
  70. name: 'Notifications',
  71. url: '/web/notifications',
  72. },
  73. ]
  74. end
  75. end