publishing_platform_publishing_components 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (259) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +22 -0
  3. data/README.md +2 -0
  4. data/Rakefile +41 -0
  5. data/app/assets/builds/gemkeep +0 -0
  6. data/app/assets/config/publishing_platform_publishing_components_manifest.js +2 -0
  7. data/app/assets/images/publishing_platform_publishing_components/gemkeep +0 -0
  8. data/app/assets/stylesheets/publishing_platform_publishing_components/_all_components.scss +3 -0
  9. data/app/assets/stylesheets/publishing_platform_publishing_components/components/_attachment.scss +117 -0
  10. data/app/assets/stylesheets/publishing_platform_publishing_components/components/_summary-list.scss +169 -0
  11. data/app/controllers/publishing_platform_publishing_components/application_controller.rb +4 -0
  12. data/app/helpers/publishing_platform_publishing_components/application_helper.rb +4 -0
  13. data/app/models/publishing_platform_publishing_components/component_doc.rb +90 -0
  14. data/app/models/publishing_platform_publishing_components/component_docs.rb +57 -0
  15. data/app/models/publishing_platform_publishing_components/component_example.rb +104 -0
  16. data/app/models/publishing_platform_publishing_components/shared_accessibility_criteria.rb +37 -0
  17. data/app/views/publishing_platform_publishing_components/component_doc/_component_output.html.erb +15 -0
  18. data/app/views/publishing_platform_publishing_components/components/_attachment.html.erb +91 -0
  19. data/app/views/publishing_platform_publishing_components/components/_error_summary.html.erb +38 -0
  20. data/app/views/publishing_platform_publishing_components/components/_summary_list.html.erb +135 -0
  21. data/app/views/publishing_platform_publishing_components/components/attachment/_thumbnail_document.html.erb +3 -0
  22. data/app/views/publishing_platform_publishing_components/components/attachment/_thumbnail_external.html.erb +3 -0
  23. data/app/views/publishing_platform_publishing_components/components/attachment/_thumbnail_generic.html.erb +4 -0
  24. data/app/views/publishing_platform_publishing_components/components/attachment/_thumbnail_html.html.erb +3 -0
  25. data/app/views/publishing_platform_publishing_components/components/attachment/_thumbnail_pdf.html.erb +3 -0
  26. data/app/views/publishing_platform_publishing_components/components/attachment/_thumbnail_spreadsheet.html.erb +5 -0
  27. data/app/views/publishing_platform_publishing_components/components/docs/attachment.yml +104 -0
  28. data/app/views/publishing_platform_publishing_components/components/docs/error_summary.yml +51 -0
  29. data/app/views/publishing_platform_publishing_components/components/docs/summary_list.yml +137 -0
  30. data/config/initializers/assets.rb +24 -0
  31. data/config/routes.rb +2 -0
  32. data/lib/publishing_platform_publishing_components/config.rb +25 -0
  33. data/lib/publishing_platform_publishing_components/engine.rb +5 -0
  34. data/lib/publishing_platform_publishing_components/presenters/attachment_helper.rb +176 -0
  35. data/lib/publishing_platform_publishing_components/presenters/component_wrapper_helper.rb +290 -0
  36. data/lib/publishing_platform_publishing_components/presenters/shared_helper.rb +24 -0
  37. data/lib/publishing_platform_publishing_components/version.rb +3 -0
  38. data/lib/publishing_platform_publishing_components.rb +10 -0
  39. data/lib/tasks/publishing_platform_publishing_components_tasks.rake +4 -0
  40. data/node_modules/bootstrap/LICENSE +21 -0
  41. data/node_modules/bootstrap/README.md +246 -0
  42. data/node_modules/bootstrap/dist/css/bootstrap-grid.css +4085 -0
  43. data/node_modules/bootstrap/dist/css/bootstrap-grid.css.map +1 -0
  44. data/node_modules/bootstrap/dist/css/bootstrap-grid.min.css +6 -0
  45. data/node_modules/bootstrap/dist/css/bootstrap-grid.min.css.map +1 -0
  46. data/node_modules/bootstrap/dist/css/bootstrap-grid.rtl.css +4084 -0
  47. data/node_modules/bootstrap/dist/css/bootstrap-grid.rtl.css.map +1 -0
  48. data/node_modules/bootstrap/dist/css/bootstrap-grid.rtl.min.css +6 -0
  49. data/node_modules/bootstrap/dist/css/bootstrap-grid.rtl.min.css.map +1 -0
  50. data/node_modules/bootstrap/dist/css/bootstrap-reboot.css +601 -0
  51. data/node_modules/bootstrap/dist/css/bootstrap-reboot.css.map +1 -0
  52. data/node_modules/bootstrap/dist/css/bootstrap-reboot.min.css +6 -0
  53. data/node_modules/bootstrap/dist/css/bootstrap-reboot.min.css.map +1 -0
  54. data/node_modules/bootstrap/dist/css/bootstrap-reboot.rtl.css +598 -0
  55. data/node_modules/bootstrap/dist/css/bootstrap-reboot.rtl.css.map +1 -0
  56. data/node_modules/bootstrap/dist/css/bootstrap-reboot.rtl.min.css +6 -0
  57. data/node_modules/bootstrap/dist/css/bootstrap-reboot.rtl.min.css.map +1 -0
  58. data/node_modules/bootstrap/dist/css/bootstrap-utilities.css +5406 -0
  59. data/node_modules/bootstrap/dist/css/bootstrap-utilities.css.map +1 -0
  60. data/node_modules/bootstrap/dist/css/bootstrap-utilities.min.css +6 -0
  61. data/node_modules/bootstrap/dist/css/bootstrap-utilities.min.css.map +1 -0
  62. data/node_modules/bootstrap/dist/css/bootstrap-utilities.rtl.css +5397 -0
  63. data/node_modules/bootstrap/dist/css/bootstrap-utilities.rtl.css.map +1 -0
  64. data/node_modules/bootstrap/dist/css/bootstrap-utilities.rtl.min.css +6 -0
  65. data/node_modules/bootstrap/dist/css/bootstrap-utilities.rtl.min.css.map +1 -0
  66. data/node_modules/bootstrap/dist/css/bootstrap.css +12048 -0
  67. data/node_modules/bootstrap/dist/css/bootstrap.css.map +1 -0
  68. data/node_modules/bootstrap/dist/css/bootstrap.min.css +6 -0
  69. data/node_modules/bootstrap/dist/css/bootstrap.min.css.map +1 -0
  70. data/node_modules/bootstrap/dist/css/bootstrap.rtl.css +12021 -0
  71. data/node_modules/bootstrap/dist/css/bootstrap.rtl.css.map +1 -0
  72. data/node_modules/bootstrap/dist/css/bootstrap.rtl.min.css +6 -0
  73. data/node_modules/bootstrap/dist/css/bootstrap.rtl.min.css.map +1 -0
  74. data/node_modules/bootstrap/dist/js/bootstrap.bundle.js +6312 -0
  75. data/node_modules/bootstrap/dist/js/bootstrap.bundle.js.map +1 -0
  76. data/node_modules/bootstrap/dist/js/bootstrap.bundle.min.js +7 -0
  77. data/node_modules/bootstrap/dist/js/bootstrap.bundle.min.js.map +1 -0
  78. data/node_modules/bootstrap/dist/js/bootstrap.esm.js +4447 -0
  79. data/node_modules/bootstrap/dist/js/bootstrap.esm.js.map +1 -0
  80. data/node_modules/bootstrap/dist/js/bootstrap.esm.min.js +7 -0
  81. data/node_modules/bootstrap/dist/js/bootstrap.esm.min.js.map +1 -0
  82. data/node_modules/bootstrap/dist/js/bootstrap.js +4494 -0
  83. data/node_modules/bootstrap/dist/js/bootstrap.js.map +1 -0
  84. data/node_modules/bootstrap/dist/js/bootstrap.min.js +7 -0
  85. data/node_modules/bootstrap/dist/js/bootstrap.min.js.map +1 -0
  86. data/node_modules/bootstrap/js/dist/alert.js +90 -0
  87. data/node_modules/bootstrap/js/dist/alert.js.map +1 -0
  88. data/node_modules/bootstrap/js/dist/base-component.js +86 -0
  89. data/node_modules/bootstrap/js/dist/base-component.js.map +1 -0
  90. data/node_modules/bootstrap/js/dist/button.js +79 -0
  91. data/node_modules/bootstrap/js/dist/button.js.map +1 -0
  92. data/node_modules/bootstrap/js/dist/carousel.js +388 -0
  93. data/node_modules/bootstrap/js/dist/carousel.js.map +1 -0
  94. data/node_modules/bootstrap/js/dist/collapse.js +249 -0
  95. data/node_modules/bootstrap/js/dist/collapse.js.map +1 -0
  96. data/node_modules/bootstrap/js/dist/dom/data.js +63 -0
  97. data/node_modules/bootstrap/js/dist/dom/data.js.map +1 -0
  98. data/node_modules/bootstrap/js/dist/dom/event-handler.js +237 -0
  99. data/node_modules/bootstrap/js/dist/dom/event-handler.js.map +1 -0
  100. data/node_modules/bootstrap/js/dist/dom/manipulator.js +72 -0
  101. data/node_modules/bootstrap/js/dist/dom/manipulator.js.map +1 -0
  102. data/node_modules/bootstrap/js/dist/dom/selector-engine.js +104 -0
  103. data/node_modules/bootstrap/js/dist/dom/selector-engine.js.map +1 -0
  104. data/node_modules/bootstrap/js/dist/dropdown.js +402 -0
  105. data/node_modules/bootstrap/js/dist/dropdown.js.map +1 -0
  106. data/node_modules/bootstrap/js/dist/modal.js +320 -0
  107. data/node_modules/bootstrap/js/dist/modal.js.map +1 -0
  108. data/node_modules/bootstrap/js/dist/offcanvas.js +246 -0
  109. data/node_modules/bootstrap/js/dist/offcanvas.js.map +1 -0
  110. data/node_modules/bootstrap/js/dist/popover.js +96 -0
  111. data/node_modules/bootstrap/js/dist/popover.js.map +1 -0
  112. data/node_modules/bootstrap/js/dist/scrollspy.js +275 -0
  113. data/node_modules/bootstrap/js/dist/scrollspy.js.map +1 -0
  114. data/node_modules/bootstrap/js/dist/tab.js +285 -0
  115. data/node_modules/bootstrap/js/dist/tab.js.map +1 -0
  116. data/node_modules/bootstrap/js/dist/toast.js +198 -0
  117. data/node_modules/bootstrap/js/dist/toast.js.map +1 -0
  118. data/node_modules/bootstrap/js/dist/tooltip.js +546 -0
  119. data/node_modules/bootstrap/js/dist/tooltip.js.map +1 -0
  120. data/node_modules/bootstrap/js/dist/util/backdrop.js +139 -0
  121. data/node_modules/bootstrap/js/dist/util/backdrop.js.map +1 -0
  122. data/node_modules/bootstrap/js/dist/util/component-functions.js +42 -0
  123. data/node_modules/bootstrap/js/dist/util/component-functions.js.map +1 -0
  124. data/node_modules/bootstrap/js/dist/util/config.js +68 -0
  125. data/node_modules/bootstrap/js/dist/util/config.js.map +1 -0
  126. data/node_modules/bootstrap/js/dist/util/focustrap.js +113 -0
  127. data/node_modules/bootstrap/js/dist/util/focustrap.js.map +1 -0
  128. data/node_modules/bootstrap/js/dist/util/index.js +281 -0
  129. data/node_modules/bootstrap/js/dist/util/index.js.map +1 -0
  130. data/node_modules/bootstrap/js/dist/util/sanitizer.js +113 -0
  131. data/node_modules/bootstrap/js/dist/util/sanitizer.js.map +1 -0
  132. data/node_modules/bootstrap/js/dist/util/scrollbar.js +113 -0
  133. data/node_modules/bootstrap/js/dist/util/scrollbar.js.map +1 -0
  134. data/node_modules/bootstrap/js/dist/util/swipe.js +135 -0
  135. data/node_modules/bootstrap/js/dist/util/swipe.js.map +1 -0
  136. data/node_modules/bootstrap/js/dist/util/template-factory.js +151 -0
  137. data/node_modules/bootstrap/js/dist/util/template-factory.js.map +1 -0
  138. data/node_modules/bootstrap/js/index.esm.js +19 -0
  139. data/node_modules/bootstrap/js/index.umd.js +34 -0
  140. data/node_modules/bootstrap/js/src/alert.js +87 -0
  141. data/node_modules/bootstrap/js/src/base-component.js +86 -0
  142. data/node_modules/bootstrap/js/src/button.js +72 -0
  143. data/node_modules/bootstrap/js/src/carousel.js +474 -0
  144. data/node_modules/bootstrap/js/src/collapse.js +297 -0
  145. data/node_modules/bootstrap/js/src/dom/data.js +55 -0
  146. data/node_modules/bootstrap/js/src/dom/event-handler.js +317 -0
  147. data/node_modules/bootstrap/js/src/dom/manipulator.js +71 -0
  148. data/node_modules/bootstrap/js/src/dom/selector-engine.js +126 -0
  149. data/node_modules/bootstrap/js/src/dropdown.js +455 -0
  150. data/node_modules/bootstrap/js/src/modal.js +378 -0
  151. data/node_modules/bootstrap/js/src/offcanvas.js +282 -0
  152. data/node_modules/bootstrap/js/src/popover.js +97 -0
  153. data/node_modules/bootstrap/js/src/scrollspy.js +296 -0
  154. data/node_modules/bootstrap/js/src/tab.js +315 -0
  155. data/node_modules/bootstrap/js/src/toast.js +224 -0
  156. data/node_modules/bootstrap/js/src/tooltip.js +633 -0
  157. data/node_modules/bootstrap/js/src/util/backdrop.js +151 -0
  158. data/node_modules/bootstrap/js/src/util/component-functions.js +35 -0
  159. data/node_modules/bootstrap/js/src/util/config.js +65 -0
  160. data/node_modules/bootstrap/js/src/util/focustrap.js +115 -0
  161. data/node_modules/bootstrap/js/src/util/index.js +306 -0
  162. data/node_modules/bootstrap/js/src/util/sanitizer.js +116 -0
  163. data/node_modules/bootstrap/js/src/util/scrollbar.js +114 -0
  164. data/node_modules/bootstrap/js/src/util/swipe.js +146 -0
  165. data/node_modules/bootstrap/js/src/util/template-factory.js +160 -0
  166. data/node_modules/bootstrap/package.json +210 -0
  167. data/node_modules/bootstrap/scss/_accordion.scss +153 -0
  168. data/node_modules/bootstrap/scss/_alert.scss +68 -0
  169. data/node_modules/bootstrap/scss/_badge.scss +38 -0
  170. data/node_modules/bootstrap/scss/_breadcrumb.scss +40 -0
  171. data/node_modules/bootstrap/scss/_button-group.scss +147 -0
  172. data/node_modules/bootstrap/scss/_buttons.scss +216 -0
  173. data/node_modules/bootstrap/scss/_card.scss +238 -0
  174. data/node_modules/bootstrap/scss/_carousel.scss +226 -0
  175. data/node_modules/bootstrap/scss/_close.scss +66 -0
  176. data/node_modules/bootstrap/scss/_containers.scss +41 -0
  177. data/node_modules/bootstrap/scss/_dropdown.scss +250 -0
  178. data/node_modules/bootstrap/scss/_forms.scss +9 -0
  179. data/node_modules/bootstrap/scss/_functions.scss +302 -0
  180. data/node_modules/bootstrap/scss/_grid.scss +39 -0
  181. data/node_modules/bootstrap/scss/_helpers.scss +12 -0
  182. data/node_modules/bootstrap/scss/_images.scss +42 -0
  183. data/node_modules/bootstrap/scss/_list-group.scss +199 -0
  184. data/node_modules/bootstrap/scss/_maps.scss +174 -0
  185. data/node_modules/bootstrap/scss/_mixins.scss +42 -0
  186. data/node_modules/bootstrap/scss/_modal.scss +240 -0
  187. data/node_modules/bootstrap/scss/_nav.scss +197 -0
  188. data/node_modules/bootstrap/scss/_navbar.scss +289 -0
  189. data/node_modules/bootstrap/scss/_offcanvas.scss +147 -0
  190. data/node_modules/bootstrap/scss/_pagination.scss +109 -0
  191. data/node_modules/bootstrap/scss/_placeholders.scss +51 -0
  192. data/node_modules/bootstrap/scss/_popover.scss +196 -0
  193. data/node_modules/bootstrap/scss/_progress.scss +68 -0
  194. data/node_modules/bootstrap/scss/_reboot.scss +617 -0
  195. data/node_modules/bootstrap/scss/_root.scss +187 -0
  196. data/node_modules/bootstrap/scss/_spinners.scss +86 -0
  197. data/node_modules/bootstrap/scss/_tables.scss +171 -0
  198. data/node_modules/bootstrap/scss/_toasts.scss +73 -0
  199. data/node_modules/bootstrap/scss/_tooltip.scss +119 -0
  200. data/node_modules/bootstrap/scss/_transitions.scss +27 -0
  201. data/node_modules/bootstrap/scss/_type.scss +106 -0
  202. data/node_modules/bootstrap/scss/_utilities.scss +806 -0
  203. data/node_modules/bootstrap/scss/_variables-dark.scss +102 -0
  204. data/node_modules/bootstrap/scss/_variables.scss +1753 -0
  205. data/node_modules/bootstrap/scss/bootstrap-grid.scss +62 -0
  206. data/node_modules/bootstrap/scss/bootstrap-reboot.scss +10 -0
  207. data/node_modules/bootstrap/scss/bootstrap-utilities.scss +19 -0
  208. data/node_modules/bootstrap/scss/bootstrap.scss +52 -0
  209. data/node_modules/bootstrap/scss/forms/_floating-labels.scss +97 -0
  210. data/node_modules/bootstrap/scss/forms/_form-check.scss +189 -0
  211. data/node_modules/bootstrap/scss/forms/_form-control.scss +214 -0
  212. data/node_modules/bootstrap/scss/forms/_form-range.scss +91 -0
  213. data/node_modules/bootstrap/scss/forms/_form-select.scss +80 -0
  214. data/node_modules/bootstrap/scss/forms/_form-text.scss +11 -0
  215. data/node_modules/bootstrap/scss/forms/_input-group.scss +132 -0
  216. data/node_modules/bootstrap/scss/forms/_labels.scss +36 -0
  217. data/node_modules/bootstrap/scss/forms/_validation.scss +12 -0
  218. data/node_modules/bootstrap/scss/helpers/_clearfix.scss +3 -0
  219. data/node_modules/bootstrap/scss/helpers/_color-bg.scss +7 -0
  220. data/node_modules/bootstrap/scss/helpers/_colored-links.scss +30 -0
  221. data/node_modules/bootstrap/scss/helpers/_focus-ring.scss +5 -0
  222. data/node_modules/bootstrap/scss/helpers/_icon-link.scss +25 -0
  223. data/node_modules/bootstrap/scss/helpers/_position.scss +36 -0
  224. data/node_modules/bootstrap/scss/helpers/_ratio.scss +26 -0
  225. data/node_modules/bootstrap/scss/helpers/_stacks.scss +15 -0
  226. data/node_modules/bootstrap/scss/helpers/_stretched-link.scss +15 -0
  227. data/node_modules/bootstrap/scss/helpers/_text-truncation.scss +7 -0
  228. data/node_modules/bootstrap/scss/helpers/_visually-hidden.scss +8 -0
  229. data/node_modules/bootstrap/scss/helpers/_vr.scss +8 -0
  230. data/node_modules/bootstrap/scss/mixins/_alert.scss +18 -0
  231. data/node_modules/bootstrap/scss/mixins/_backdrop.scss +14 -0
  232. data/node_modules/bootstrap/scss/mixins/_banner.scss +7 -0
  233. data/node_modules/bootstrap/scss/mixins/_border-radius.scss +78 -0
  234. data/node_modules/bootstrap/scss/mixins/_box-shadow.scss +24 -0
  235. data/node_modules/bootstrap/scss/mixins/_breakpoints.scss +127 -0
  236. data/node_modules/bootstrap/scss/mixins/_buttons.scss +70 -0
  237. data/node_modules/bootstrap/scss/mixins/_caret.scss +69 -0
  238. data/node_modules/bootstrap/scss/mixins/_clearfix.scss +9 -0
  239. data/node_modules/bootstrap/scss/mixins/_color-mode.scss +21 -0
  240. data/node_modules/bootstrap/scss/mixins/_color-scheme.scss +7 -0
  241. data/node_modules/bootstrap/scss/mixins/_container.scss +11 -0
  242. data/node_modules/bootstrap/scss/mixins/_deprecate.scss +10 -0
  243. data/node_modules/bootstrap/scss/mixins/_forms.scss +163 -0
  244. data/node_modules/bootstrap/scss/mixins/_gradients.scss +47 -0
  245. data/node_modules/bootstrap/scss/mixins/_grid.scss +151 -0
  246. data/node_modules/bootstrap/scss/mixins/_image.scss +16 -0
  247. data/node_modules/bootstrap/scss/mixins/_list-group.scss +26 -0
  248. data/node_modules/bootstrap/scss/mixins/_lists.scss +7 -0
  249. data/node_modules/bootstrap/scss/mixins/_pagination.scss +10 -0
  250. data/node_modules/bootstrap/scss/mixins/_reset-text.scss +17 -0
  251. data/node_modules/bootstrap/scss/mixins/_resize.scss +6 -0
  252. data/node_modules/bootstrap/scss/mixins/_table-variants.scss +24 -0
  253. data/node_modules/bootstrap/scss/mixins/_text-truncate.scss +8 -0
  254. data/node_modules/bootstrap/scss/mixins/_transition.scss +26 -0
  255. data/node_modules/bootstrap/scss/mixins/_utilities.scss +97 -0
  256. data/node_modules/bootstrap/scss/mixins/_visually-hidden.scss +38 -0
  257. data/node_modules/bootstrap/scss/utilities/_api.scss +47 -0
  258. data/node_modules/bootstrap/scss/vendor/_rfs.scss +348 -0
  259. metadata +448 -0
@@ -0,0 +1,176 @@
1
+ module PublishingPlatformPublishingComponents
2
+ module Presenters
3
+ class AttachmentHelper
4
+ delegate :opendocument?, :document?, :spreadsheet?, :pdf?, to: :content_type
5
+
6
+ attr_reader :attachment_data
7
+
8
+ # Expects a hash of attachment data
9
+ # * title and url are required
10
+ # * content_type, filename, file_size, number of pages can be provided
11
+ def initialize(attachment_data)
12
+ @attachment_data = attachment_data.with_indifferent_access
13
+ end
14
+
15
+ def thumbnail_url
16
+ @attachment_data[:thumbnail_url]
17
+ end
18
+
19
+ def preview_url
20
+ @attachment_data[:preview_url]
21
+ end
22
+
23
+ def title
24
+ attachment_data.fetch(:title)
25
+ end
26
+
27
+ def url
28
+ attachment_data.fetch(:url)
29
+ end
30
+
31
+ def type
32
+ attachment_data.fetch(:type, "file")
33
+ end
34
+
35
+ def html?
36
+ type == "html"
37
+ end
38
+
39
+ def external?
40
+ type == "external"
41
+ end
42
+
43
+ def content_type
44
+ @content_type ||= SupportedContentType.find(
45
+ attachment_data[:content_type],
46
+ attachment_data[:filename] ? File.extname(attachment_data[:filename]) : nil,
47
+ )
48
+ end
49
+
50
+ delegate :abbr, to: :content_type, prefix: true
51
+
52
+ delegate :name, to: :content_type, prefix: true
53
+
54
+ def file_size
55
+ attachment_data[:file_size]
56
+ end
57
+
58
+ def number_of_pages
59
+ attachment_data[:number_of_pages]
60
+ end
61
+
62
+ def reference
63
+ reference = []
64
+ reference << "ISBN #{attachment_data[:isbn]}" if attachment_data[:isbn].present?
65
+ reference << attachment_data[:unique_reference] if attachment_data[:unique_reference].present?
66
+
67
+ reference.join(", ")
68
+ end
69
+
70
+ class SupportedContentType
71
+ attr_reader :content_type_data
72
+
73
+ TYPES = [
74
+ { content_type: "application/msword", name: "MS Word Document", document: true }.freeze, # doc
75
+ { content_type: "application/pdf", abbr: "PDF", name: "Portable Document Format", pdf: true }.freeze,
76
+ { content_type: "application/postscript", extension: ".ps", abbr: "PS", name: "PostScript" }.freeze,
77
+ { content_type: "application/postscript", extension: ".eps", abbr: "EPS", name: "Encapsulated PostScript" }.freeze,
78
+ { content_type: "application/rtf", abbr: "RTF", name: "Rich Text Format" }.freeze,
79
+ { content_type: "application/vnd.ms-excel", name: "MS Excel Spreadsheet", spreadsheet: true }.freeze,
80
+ { content_type: "application/vnd.ms-excel.sheet.macroenabled.12", abbr: "XLSM", name: "MS Excel Macro-Enabled Workbook" }.freeze,
81
+ { content_type: "application/vnd.ms-powerpoint", name: "MS PowerPoint Presentation" }.freeze, # ppt
82
+ { content_type: "application/vnd.oasis.opendocument.presentation", abbr: "ODP", name: "OpenDocument Presentation", opendocument: true }.freeze,
83
+ { content_type: "application/vnd.oasis.opendocument.spreadsheet", abbr: "ODS", name: "OpenDocument Spreadsheet", opendocument: true, spreadsheet: true }.freeze,
84
+ { content_type: "application/vnd.oasis.opendocument.text", abbr: "ODT", name: "OpenDocument Text document", opendocument: true, document: true }.freeze,
85
+ { content_type: "application/vnd.openxmlformats-officedocument.presentationml.presentation", name: "MS PowerPoint Presentation" }.freeze, # pptx
86
+ { content_type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", name: "MS Excel Spreadsheet", spreadsheet: true }.freeze, # xlsx
87
+ { content_type: "application/vnd.openxmlformats-officedocument.wordprocessingml.document", name: "MS Word Document", document: true }.freeze, # docx
88
+ { content_type: "application/zip", abbr: "ZIP", name: "Zip archive" }.freeze,
89
+ { content_type: "application/xml", abbr: "XML", name: "XML Document" }.freeze,
90
+ { content_type: "image/gif", abbr: "GIF", name: "Graphics Interchange Format" }.freeze,
91
+ { content_type: "image/jpeg", name: "JPEG" }.freeze,
92
+ { content_type: "image/png", abbr: "PNG", name: "Portable Network Graphic" }.freeze,
93
+ { content_type: "image/vnd.dxf", abbr: "DXF", name: "AutoCAD Drawing Exchange Format" }.freeze,
94
+ { content_type: "text/csv", abbr: "CSV", name: "Comma-separated Values", spreadsheet: true }.freeze,
95
+ { content_type: "text/plain", name: "Plain Text" }.freeze,
96
+ { content_type: "text/xml", extension: ".xml", abbr: "XML", name: "XML Document" }.freeze,
97
+ { content_type: "text/xml", extension: ".xsd", abbr: "XSD", name: "XML Schema" }.freeze,
98
+ ].freeze
99
+
100
+ def self.find(content_type, extension = nil)
101
+ matching_types = TYPES.select { |type| type[:content_type] == content_type }
102
+
103
+ return UnsupportedContentType.new(content_type:) if matching_types.empty?
104
+
105
+ extension_match = if matching_types.length > 1
106
+ matching_types.find { |type| type[:extension] == extension }
107
+ end
108
+
109
+ content_type = extension_match || matching_types.first
110
+
111
+ new(content_type)
112
+ end
113
+
114
+ def initialize(content_type_data)
115
+ @content_type_data = content_type_data
116
+ end
117
+
118
+ def content_type
119
+ content_type_data[:content_type]
120
+ end
121
+
122
+ def abbr
123
+ content_type_data[:abbr]
124
+ end
125
+
126
+ def name
127
+ content_type_data[:name]
128
+ end
129
+
130
+ def opendocument?
131
+ content_type_data[:opendocument].present?
132
+ end
133
+
134
+ def document?
135
+ content_type_data[:document].present?
136
+ end
137
+
138
+ def spreadsheet?
139
+ content_type_data[:spreadsheet].present?
140
+ end
141
+
142
+ def pdf?
143
+ content_type_data[:pdf].present?
144
+ end
145
+ end
146
+
147
+ class UnsupportedContentType
148
+ attr_reader :content_type
149
+
150
+ def initialize(content_type:)
151
+ @content_type = content_type
152
+ end
153
+
154
+ def name; end
155
+
156
+ def abbr; end
157
+
158
+ def opendocument?
159
+ false
160
+ end
161
+
162
+ def document?
163
+ false
164
+ end
165
+
166
+ def spreadsheet?
167
+ false
168
+ end
169
+
170
+ def pdf?
171
+ false
172
+ end
173
+ end
174
+ end
175
+ end
176
+ end
@@ -0,0 +1,290 @@
1
+ module PublishingPlatformPublishingComponents
2
+ module Presenters
3
+ class ComponentWrapperHelper
4
+ def initialize(options)
5
+ @options = options
6
+
7
+ check_id_is_valid(@options[:id]) if @options.include?(:id)
8
+ check_data_attributes_are_valid(@options[:data_attributes]) if @options.include?(:data_attributes)
9
+ check_classes_are_valid(@options[:classes]) if @options.include?(:classes)
10
+ check_aria_is_valid(@options[:aria]) if @options.include?(:aria)
11
+ check_role_is_valid(@options[:role]) if @options.include?(:role)
12
+ check_lang_is_valid(@options[:lang]) if @options.include?(:lang)
13
+ check_open_is_valid(@options[:open]) if @options.include?(:open)
14
+ check_hidden_is_valid(@options[:hidden]) if @options.include?(:hidden)
15
+ check_tabindex_is_valid(@options[:tabindex]) if @options.include?(:tabindex)
16
+ check_dir_is_valid(@options[:dir]) if @options.include?(:dir)
17
+ check_type_is_valid(@options[:type]) if @options.include?(:type)
18
+ check_draggable_is_valid(@options[:draggable]) if @options.include?(:draggable)
19
+ check_rel_is_valid(@options[:rel]) if @options.include?(:rel)
20
+ check_target_is_valid(@options[:target]) if @options.include?(:target)
21
+ check_margin_bottom_is_valid(@options[:margin_bottom]) if @options.include?(:margin_bottom)
22
+ end
23
+
24
+ def all_attributes
25
+ attributes = {}
26
+
27
+ attributes[:id] = @options[:id] if @options[:id].present?
28
+ attributes[:data] = @options[:data_attributes] if @options[:data_attributes].present?
29
+ attributes[:aria] = @options[:aria] if @options[:aria].present?
30
+
31
+ ((@options[:classes] ||= "") << " mb-#{@options[:margin_bottom]}").strip! if @options[:margin_bottom]
32
+ attributes[:class] = @options[:classes] if @options[:classes].present?
33
+
34
+ attributes[:role] = @options[:role] if @options[:role].present?
35
+ attributes[:lang] = @options[:lang] if @options[:lang].present?
36
+ attributes[:open] = @options[:open] if @options[:open].present?
37
+ attributes[:hidden] = @options[:hidden] unless @options[:hidden].nil?
38
+ attributes[:tabindex] = @options[:tabindex] if @options[:tabindex].present?
39
+ attributes[:dir] = @options[:dir] if @options[:dir].present?
40
+ attributes[:type] = @options[:type] if @options[:type].present?
41
+ attributes[:draggable] = @options[:draggable] if @options[:draggable].present?
42
+ attributes[:rel] = @options[:rel] if @options[:rel].present?
43
+ attributes[:target] = @options[:target] if @options[:target].present?
44
+ attributes[:title] = @options[:title] if @options[:title].present?
45
+
46
+ attributes
47
+ end
48
+
49
+ def set_id(id)
50
+ check_id_is_valid(id)
51
+ @options[:id] = id
52
+ end
53
+
54
+ def add_class(classes)
55
+ check_classes_are_valid(classes)
56
+ extend_string(:classes, classes)
57
+ end
58
+
59
+ def add_data_attribute(attributes)
60
+ check_data_attributes_are_valid(attributes)
61
+ extend_object(:data_attributes, attributes)
62
+ end
63
+
64
+ def add_aria_attribute(attributes)
65
+ check_aria_is_valid(attributes)
66
+ extend_object(:aria, attributes)
67
+ end
68
+
69
+ def add_role(role)
70
+ check_role_is_valid(role)
71
+ extend_string(:role, role)
72
+ end
73
+
74
+ def set_lang(lang)
75
+ check_lang_is_valid(lang)
76
+ @options[:lang] = lang
77
+ end
78
+
79
+ def set_open(open_attribute)
80
+ check_open_is_valid(open_attribute)
81
+ @options[:open] = open_attribute
82
+ end
83
+
84
+ def set_hidden(hidden_attribute)
85
+ check_hidden_is_valid(hidden_attribute)
86
+ @options[:hidden] = hidden_attribute
87
+ end
88
+
89
+ def set_tabindex(tabindex_attribute)
90
+ check_tabindex_is_valid(tabindex_attribute)
91
+ @options[:tabindex] = tabindex_attribute
92
+ end
93
+
94
+ def set_dir(dir_attribute)
95
+ check_dir_is_valid(dir_attribute)
96
+ @options[:dir] = dir_attribute
97
+ end
98
+
99
+ def set_type(type_attribute)
100
+ check_type_is_valid(type_attribute)
101
+ @options[:type] = type_attribute
102
+ end
103
+
104
+ def set_draggable(draggable_attribute)
105
+ check_draggable_is_valid(draggable_attribute)
106
+ @options[:draggable] = draggable_attribute
107
+ end
108
+
109
+ def add_rel(rel_attribute)
110
+ check_rel_is_valid(rel_attribute)
111
+ extend_string(:rel, rel_attribute)
112
+ end
113
+
114
+ def set_rel(rel_attribute)
115
+ check_rel_is_valid(rel_attribute)
116
+ @options[:rel] = rel_attribute
117
+ end
118
+
119
+ def set_target(target_attribute)
120
+ check_target_is_valid(target_attribute)
121
+ @options[:target] = target_attribute
122
+ end
123
+
124
+ def set_title(title_attribute)
125
+ @options[:title] = title_attribute
126
+ end
127
+
128
+ def set_margin_bottom(margin_bottom)
129
+ check_margin_bottom_is_valid(margin_bottom)
130
+ @options[:margin_bottom] = margin_bottom
131
+ end
132
+
133
+ private
134
+
135
+ def check_id_is_valid(id)
136
+ return if id.blank?
137
+
138
+ raise(ArgumentError, "Id (#{id}) cannot contain whitespace or `.` characters") if /[. \n]+/.match?(id)
139
+ end
140
+
141
+ def check_data_attributes_are_valid(attributes)
142
+ return if attributes.blank?
143
+
144
+ attributes_keys = attributes.map { |key, _| key.to_s }
145
+ invalid_attributes = attributes_keys.map { |a| a if /^(xml)/.match?(a) || /[A-Z :]+/.match?(a) }.compact
146
+
147
+ raise(ArgumentError, "Data attributes (#{invalid_attributes.join(', ')}) cannot contain capitals, spaces or colons, or start with 'xml'") if invalid_attributes.any?
148
+ end
149
+
150
+ def check_classes_are_valid(classes)
151
+ return if classes.blank?
152
+
153
+ class_array = classes.split(" ")
154
+ unless class_array.all? { |c| c.start_with?("js-", "gem-c-", "app-c-", "brand--", "brand__", "gem-print-", "alert") }
155
+ raise(ArgumentError, "Classes (#{classes}) must be prefixed with `js-`")
156
+ end
157
+ end
158
+
159
+ def check_aria_is_valid(attributes)
160
+ return if attributes.blank?
161
+
162
+ arias = %w[activedescendant atomic autocomplete busy checked colcount colindex colspan controls current describedby description details disabled dropeffect errormessage expanded flowto grabbed haspopup hidden invalid keyshortcuts label labelledby level live modal multiline multiselectable orientation owns placeholder posinset pressed readonly relevant required roledescription rowcount rowindex rowspan selected setsize sort valuemax valuemin valuenow valuetext]
163
+
164
+ # array keys are immutable so we have to do this to make a copy, in order to
165
+ # subtract valid aria attributes from invalid in the error message below
166
+ attributes_keys = attributes.map { |key, _| key.to_s }
167
+
168
+ unless attributes_keys.all? { |key| arias.include? key }
169
+ raise(ArgumentError, "Aria attribute (#{(attributes_keys - arias).join(', ')}) not recognised")
170
+ end
171
+ end
172
+
173
+ def check_role_is_valid(role)
174
+ return if role.blank?
175
+
176
+ roles = %w[alert alertdialog application article associationlist associationlistitemkey associationlistitemvalue banner blockquote caption cell code columnheader combobox complementary contentinfo definition deletion dialog directory document emphasis feed figure form group heading img insertion list listitem log main marquee math menu menubar meter navigation none note paragraph presentation region row rowgroup rowheader scrollbar search searchbox separator separator slider spinbutton status strong subscript superscript switch tab table tablist tabpanel term time timer toolbar tooltip tree treegrid treeitem]
177
+ role = role.split(" ") # can have more than one role
178
+ unless role.all? { |r| roles.include? r }
179
+ raise(ArgumentError, "Role attribute (#{(role - roles).join(', ')}) is not recognised")
180
+ end
181
+ end
182
+
183
+ def check_lang_is_valid(lang)
184
+ return if lang.blank?
185
+
186
+ langs = %w[ab aa af ak sq am ar an hy as av ae ay az bm ba eu be bn bh bi bs br bg my ca ch ce ny zh zh-Hans zh-Hant zh-hk zh-tw cv kw co cr hr cs da dv nl dz dr en eo et ee fo fj fi fr ff gl gd gv ka de el kl gn gu ht ha he hz hi ho hu is io ig id in ia ie iu ik ga it ja jv kl kn kr ks kk km ki rw rn ky kv kg ko ku kj lo la lv li ln lt lu lg lb gv mk mg ms ml mt mi mr mh mo mn na nv ng nd ne no nb nn ii oc oj cu or om os pi ps fa pl pt pa pa-pk qu rm ro ru se sm sg sa sr sh st tn sn ii sd si ss sk sl so nr es es-419 su sw ss sv tl ty tg ta tt te th bo ti to ts tr tk tw ug uk ur uz ve vi vo wa cy wo fy xh yi ji yo za zu]
187
+
188
+ lang = lang.to_s
189
+
190
+ unless langs.include? lang
191
+ raise(ArgumentError, "lang attribute (#{lang}) is not recognised")
192
+ end
193
+ end
194
+
195
+ def check_open_is_valid(open_attribute)
196
+ return if open_attribute.blank?
197
+
198
+ options = [true, false]
199
+ unless options.include? open_attribute
200
+ raise(ArgumentError, "open attribute (#{open_attribute}) is not recognised")
201
+ end
202
+ end
203
+
204
+ def check_hidden_is_valid(hidden_attribute)
205
+ return if hidden_attribute.nil?
206
+
207
+ options = ["", "hidden", "until-found"]
208
+ unless options.include? hidden_attribute
209
+ raise(ArgumentError, "hidden attribute (#{hidden_attribute}) is not recognised")
210
+ end
211
+ end
212
+
213
+ def check_tabindex_is_valid(tabindex_attribute)
214
+ return if tabindex_attribute.blank?
215
+
216
+ tabindex_attribute = tabindex_attribute.to_s
217
+
218
+ unless /^-?[0-9]+$/.match?(tabindex_attribute)
219
+ raise(ArgumentError, "tabindex_attribute attribute (#{tabindex_attribute}) is not recognised")
220
+ end
221
+ end
222
+
223
+ def check_margin_bottom_is_valid(margin_bottom)
224
+ raise(ArgumentError, "margin_bottom option (#{margin_bottom}) is not recognised") unless [*0..5].include?(margin_bottom)
225
+ end
226
+
227
+ def check_dir_is_valid(dir_attribute)
228
+ return if dir_attribute.blank?
229
+
230
+ options = %w[ltr rtl auto]
231
+ unless options.include? dir_attribute
232
+ raise(ArgumentError, "dir attribute (#{dir_attribute}) is not recognised")
233
+ end
234
+ end
235
+
236
+ def check_type_is_valid(type_attribute)
237
+ return if type_attribute.blank?
238
+
239
+ options = %w[button checkbox color date datetime-local email file hidden image month number password radio range reset search submit tel text time url week]
240
+ unless options.include? type_attribute
241
+ raise(ArgumentError, "type attribute (#{type_attribute}) is not recognised")
242
+ end
243
+ end
244
+
245
+ def check_draggable_is_valid(draggable_attribute)
246
+ return if draggable_attribute.blank?
247
+
248
+ options = %w[true false]
249
+ unless options.include? draggable_attribute
250
+ raise(ArgumentError, "draggable attribute (#{draggable_attribute}) is not recognised")
251
+ end
252
+ end
253
+
254
+ def check_rel_is_valid(rel_attribute)
255
+ return if rel_attribute.blank?
256
+
257
+ options = %w[alternate author bookmark canonical dns-prefetch external expect help icon license manifest me modulepreload next nofollow noopener noreferrer opener pingback preconnect prefetch preload prerender prev privacy-policy search stylesheet tag terms-of-service]
258
+ rel_array = rel_attribute.split(" ")
259
+ unless rel_array.all? { |r| options.include? r }
260
+ raise(ArgumentError, "rel attribute (#{rel_attribute}) is not recognised")
261
+ end
262
+ end
263
+
264
+ def check_target_is_valid(target_attribute)
265
+ return if target_attribute.blank?
266
+
267
+ options = %w[_self _blank _parent _top _unfencedTop]
268
+ unless options.include? target_attribute
269
+ raise(ArgumentError, "target attribute (#{target_attribute}) is not recognised")
270
+ end
271
+ end
272
+
273
+ def extend_string(option, string)
274
+ @options[option] = "#{@options[option]} #{string}".strip
275
+ end
276
+
277
+ def extend_object(option, object)
278
+ @options[option] ||= {}
279
+ object.each_key do |key|
280
+ @options[option][key] =
281
+ if @options[option].key?(key)
282
+ "#{@options[option][key]} #{object[key]}"
283
+ else
284
+ object[key]
285
+ end
286
+ end
287
+ end
288
+ end
289
+ end
290
+ end
@@ -0,0 +1,24 @@
1
+ module PublishingPlatformPublishingComponents
2
+ module Presenters
3
+ class SharedHelper
4
+ attr_reader :options, :margin_bottom, :heading_level, :classes
5
+
6
+ def initialize(local_assigns)
7
+ @options = local_assigns
8
+ @margin_bottom = @options[:margin_bottom] || 3
9
+ @heading_level = @options[:heading_level] || 2
10
+ @heading_size = @options[:heading_size] || 2
11
+ end
12
+
13
+ def get_heading_level
14
+ return [*1..6].include?(@heading_level) ? "h#{@heading_level}" : "h2" unless @heading_level.zero?
15
+
16
+ "span"
17
+ end
18
+
19
+ def get_heading_size
20
+ [*1..6].include?(@heading_size) ? "h#{@heading_size}" : "h2"
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,3 @@
1
+ module PublishingPlatformPublishingComponents
2
+ VERSION = "0.1.0".freeze
3
+ end
@@ -0,0 +1,10 @@
1
+ require "publishing_platform_publishing_components/config"
2
+ require "publishing_platform_publishing_components/version"
3
+ require "publishing_platform_publishing_components/engine"
4
+ require "publishing_platform_publishing_components/presenters/shared_helper"
5
+ require "publishing_platform_publishing_components/presenters/component_wrapper_helper"
6
+ require "publishing_platform_publishing_components/presenters/attachment_helper"
7
+
8
+ module PublishingPlatformPublishingComponents
9
+ # Your code goes here...
10
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :publishing_platform_publishing_components do
3
+ # # Task goes here
4
+ # end
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2011-2025 The Bootstrap Authors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.