manifest_serializer.rb 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. purpose: 'any maskable',
  33. }
  34. end
  35. end
  36. def theme_color
  37. '#191b22'
  38. end
  39. def background_color
  40. '#191b22'
  41. end
  42. def display
  43. 'standalone'
  44. end
  45. def start_url
  46. '/home'
  47. end
  48. def scope
  49. '/'
  50. end
  51. def share_target
  52. {
  53. url_template: 'share?title={title}&text={text}&url={url}',
  54. action: 'share',
  55. method: 'GET',
  56. enctype: 'application/x-www-form-urlencoded',
  57. params: {
  58. title: 'title',
  59. text: 'text',
  60. url: 'url',
  61. },
  62. }
  63. end
  64. def shortcuts
  65. [
  66. {
  67. name: 'Compose new post',
  68. url: '/publish',
  69. },
  70. {
  71. name: 'Notifications',
  72. url: '/notifications',
  73. },
  74. ]
  75. end
  76. end