ariadne_view_components 0.0.58 → 0.0.64

Sign up to get free protection for your applications and to get access to all the features.
Files changed (264) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +70 -0
  3. data/LICENSE.txt +661 -49
  4. data/README.md +52 -4
  5. data/app/assets/javascripts/ariadne_view_components.js +98 -7
  6. data/app/assets/javascripts/ariadne_view_components.js.map +1 -1
  7. data/app/assets/stylesheets/ariadne_view_components.css +1 -7
  8. data/app/components/ariadne/base_component.rb +79 -27
  9. data/app/components/ariadne/behaviors/tooltipable.rb +120 -0
  10. data/app/components/ariadne/conditional_wrapper.rb +21 -0
  11. data/app/components/ariadne/form/base_component.rb +74 -0
  12. data/app/components/ariadne/form/base_input_component.rb +60 -0
  13. data/app/components/ariadne/form/caption/component.html.erb +10 -0
  14. data/app/components/ariadne/form/caption/component.rb +29 -0
  15. data/app/components/ariadne/form/form_control/component.html.erb +19 -0
  16. data/app/components/ariadne/form/form_control/component.rb +27 -0
  17. data/app/components/ariadne/form/form_reference/component.html.erb +1 -0
  18. data/app/components/ariadne/form/form_reference/component.rb +18 -0
  19. data/app/components/ariadne/form/group/component.html.erb +5 -0
  20. data/app/components/ariadne/form/group/component.rb +27 -0
  21. data/app/components/ariadne/form/hidden_field/component.html.erb +1 -0
  22. data/app/components/ariadne/form/hidden_field/component.rb +15 -0
  23. data/app/components/ariadne/form/separator/component.html.erb +1 -0
  24. data/app/components/ariadne/form/separator/component.rb +8 -0
  25. data/app/components/ariadne/form/spacing_wrapper/component.html.erb +3 -0
  26. data/app/components/ariadne/form/spacing_wrapper/component.rb +8 -0
  27. data/app/components/ariadne/form/text_field/component.html.erb +25 -0
  28. data/app/components/ariadne/form/text_field/component.rb +132 -0
  29. data/app/components/ariadne/form/validation_message/component.html.erb +5 -0
  30. data/app/components/ariadne/form/validation_message/component.rb +14 -0
  31. data/app/components/ariadne/layout/narrow/component.html.erb +10 -0
  32. data/app/components/ariadne/layout/narrow/component.rb +24 -0
  33. data/app/components/ariadne/layout/nav_bar/component.css +0 -0
  34. data/app/components/ariadne/layout/nav_bar/component.html.erb +123 -0
  35. data/app/components/ariadne/layout/nav_bar/component.rb +77 -0
  36. data/app/components/ariadne/ui/button/component.html.erb +5 -0
  37. data/app/components/ariadne/ui/button/component.rb +184 -0
  38. data/app/components/ariadne/ui/clipboard_copy/component.html.erb +8 -0
  39. data/app/components/ariadne/ui/clipboard_copy/component.rb +102 -0
  40. data/app/components/ariadne/ui/clipboard_copy/component.ts +54 -0
  41. data/app/components/ariadne/ui/combobox/component.html.erb +32 -0
  42. data/app/components/ariadne/ui/combobox/component.rb +83 -0
  43. data/app/components/ariadne/ui/combobox/component.ts +119 -0
  44. data/app/components/ariadne/ui/combobox/menu_item/component.html.erb +9 -0
  45. data/app/components/ariadne/ui/combobox/menu_item/component.rb +53 -0
  46. data/app/components/ariadne/ui/combobox/option/component.html.erb +11 -0
  47. data/app/components/ariadne/ui/combobox/option/component.rb +45 -0
  48. data/app/components/ariadne/ui/heroicon/component.html.erb +3 -0
  49. data/app/components/ariadne/ui/heroicon/component.rb +141 -0
  50. data/app/components/ariadne/ui/image/component.rb +69 -0
  51. data/app/components/ariadne/ui/link/component.html.erb +3 -0
  52. data/app/components/ariadne/ui/link/component.rb +56 -0
  53. data/app/components/ariadne/ui/typography/component.html.erb +3 -0
  54. data/app/components/ariadne/ui/typography/component.rb +41 -0
  55. data/app/lib/ariadne/attributes_helper.rb +119 -0
  56. data/app/lib/ariadne/fetch_or_fallback_helper.rb +1 -1
  57. data/app/lib/ariadne/form.rb +16 -0
  58. data/app/lib/ariadne/view_helper.rb +2 -5
  59. data/app/lib/view_components_contrib/html_attrs.rb +64 -0
  60. data/app/lib/view_components_contrib/style_variants.rb +14 -0
  61. data/lib/ariadne/forms/acts_as_component.rb +125 -0
  62. data/lib/ariadne/forms/base.html.erb +8 -0
  63. data/lib/ariadne/forms/base.rb +132 -0
  64. data/lib/ariadne/forms/buffer_rewriter.rb +51 -0
  65. data/lib/ariadne/forms/builder.rb +88 -0
  66. data/lib/ariadne/forms/dsl/button_input.rb +33 -0
  67. data/lib/ariadne/forms/dsl/form_object.rb +26 -0
  68. data/lib/ariadne/forms/dsl/input.rb +322 -0
  69. data/lib/ariadne/forms/dsl/input_group.rb +34 -0
  70. data/lib/ariadne/forms/dsl/input_methods.rb +157 -0
  71. data/lib/ariadne/forms/dsl/submit_button_input.rb +36 -0
  72. data/lib/ariadne/forms/dsl/text_field_input.rb +73 -0
  73. data/lib/ariadne/forms/utils.rb +34 -0
  74. data/lib/ariadne/generate.rb +11 -0
  75. data/lib/ariadne/view_components/engine.rb +24 -7
  76. data/lib/ariadne/view_components/version.rb +1 -1
  77. data/lib/ariadne/view_components.rb +1 -1
  78. data/lib/ariadne/yard/backend.rb +24 -0
  79. data/lib/ariadne/yard/component_manifest.rb +148 -0
  80. data/lib/ariadne/yard/component_ref.rb +49 -0
  81. data/lib/ariadne/yard/docs_helper.rb +98 -0
  82. data/lib/ariadne/yard/info_arch_docs_helper.rb +31 -0
  83. data/lib/ariadne/yard/lookbook_docs_helper.rb +32 -0
  84. data/lib/ariadne/yard/lookbook_pages_backend.rb +235 -0
  85. data/lib/ariadne/yard/registry.rb +136 -0
  86. data/lib/ariadne/yard/renders_many_handler.rb +23 -0
  87. data/lib/ariadne/yard/renders_one_handler.rb +23 -0
  88. data/lib/ariadne/yard.rb +19 -0
  89. data/static/arguments.yml +141 -48
  90. data/static/audited_at.json +0 -9
  91. data/static/classes.yml +210 -209
  92. data/static/constants.json +2 -209
  93. data/static/statuses.json +0 -9
  94. metadata +125 -210
  95. data/app/assets/builds/ariadne_view_components.css +0 -2202
  96. data/app/assets/javascripts/components/ariadne/accumulator_controller/accumulator_controller.d.ts +0 -22
  97. data/app/assets/javascripts/components/ariadne/ariadne-form.d.ts +0 -22
  98. data/app/assets/javascripts/components/ariadne/ariadne.d.ts +0 -2
  99. data/app/assets/javascripts/components/ariadne/clipboard_copy_component/clipboard-copy-component.d.ts +0 -4
  100. data/app/assets/javascripts/components/ariadne/dropdown/menu_component.d.ts +0 -1
  101. data/app/assets/javascripts/components/ariadne/events_controller/events_controller.d.ts +0 -4
  102. data/app/assets/javascripts/components/ariadne/options_controller/options_controller.d.ts +0 -39
  103. data/app/assets/javascripts/components/ariadne/outlet_manager_controller/outlet_manager_controller.d.ts +0 -42
  104. data/app/assets/javascripts/components/ariadne/slideover_component/slideover-component.d.ts +0 -9
  105. data/app/assets/javascripts/components/ariadne/string_match_controller/string_match_controller.d.ts +0 -27
  106. data/app/assets/javascripts/components/ariadne/synced_boolean_attributes_controller/synced_boolean_attributes_controller.d.ts +0 -48
  107. data/app/assets/javascripts/components/ariadne/tab_container_component/tab-container-component.d.ts +0 -1
  108. data/app/assets/javascripts/components/ariadne/tab_nav_component/tab-nav-component.d.ts +0 -9
  109. data/app/assets/javascripts/components/ariadne/time_ago_component/time-ago-component.d.ts +0 -1
  110. data/app/assets/javascripts/components/ariadne/toggleable_controller/toggleable_controller.d.ts +0 -34
  111. data/app/assets/javascripts/components/ariadne/tooltip_component/tooltip-component.d.ts +0 -24
  112. data/app/assets/stylesheets/dropdown.css +0 -46
  113. data/app/assets/stylesheets/prosemirror.css +0 -323
  114. data/app/assets/stylesheets/tooltip-component.css +0 -37
  115. data/app/components/ariadne/accumulator_controller/accumulator_controller.d.ts +0 -22
  116. data/app/components/ariadne/accumulator_controller/accumulator_controller.js +0 -39
  117. data/app/components/ariadne/accumulator_controller/accumulator_controller.ts +0 -48
  118. data/app/components/ariadne/action_card_component.html.erb +0 -13
  119. data/app/components/ariadne/action_card_component.rb +0 -88
  120. data/app/components/ariadne/ariadne-form.d.ts +0 -22
  121. data/app/components/ariadne/ariadne-form.js +0 -85
  122. data/app/components/ariadne/ariadne.d.ts +0 -2
  123. data/app/components/ariadne/ariadne.js +0 -24
  124. data/app/components/ariadne/ariadne.ts +0 -29
  125. data/app/components/ariadne/avatar_component.rb +0 -81
  126. data/app/components/ariadne/avatar_stack_component/avatar_stack_component.html.erb +0 -12
  127. data/app/components/ariadne/avatar_stack_component.rb +0 -75
  128. data/app/components/ariadne/base_button.rb +0 -70
  129. data/app/components/ariadne/blankslate_component/blankslate_component.html.erb +0 -26
  130. data/app/components/ariadne/blankslate_component.rb +0 -148
  131. data/app/components/ariadne/body_component.rb +0 -30
  132. data/app/components/ariadne/bottom_tab_component.html.erb +0 -4
  133. data/app/components/ariadne/bottom_tab_component.rb +0 -44
  134. data/app/components/ariadne/bottom_tab_nav_component.html.erb +0 -5
  135. data/app/components/ariadne/bottom_tab_nav_component.rb +0 -33
  136. data/app/components/ariadne/breadcrumbs_component.html.erb +0 -13
  137. data/app/components/ariadne/breadcrumbs_component.rb +0 -31
  138. data/app/components/ariadne/button_component/button_component.html.erb +0 -4
  139. data/app/components/ariadne/button_component.rb +0 -165
  140. data/app/components/ariadne/checkbox_component.html.erb +0 -5
  141. data/app/components/ariadne/checkbox_component.rb +0 -43
  142. data/app/components/ariadne/clipboard_copy_component/clipboard-copy-component.d.ts +0 -4
  143. data/app/components/ariadne/clipboard_copy_component/clipboard-copy-component.js +0 -18
  144. data/app/components/ariadne/clipboard_copy_component/clipboard-copy-component.ts +0 -19
  145. data/app/components/ariadne/clipboard_copy_component/clipboard_copy_component.html.erb +0 -9
  146. data/app/components/ariadne/clipboard_copy_component.rb +0 -90
  147. data/app/components/ariadne/close_button_component.html.erb +0 -4
  148. data/app/components/ariadne/close_button_component.rb +0 -33
  149. data/app/components/ariadne/combobox_component.html.erb +0 -14
  150. data/app/components/ariadne/combobox_component.rb +0 -76
  151. data/app/components/ariadne/component.rb +0 -127
  152. data/app/components/ariadne/container_component/container_component.html.erb +0 -3
  153. data/app/components/ariadne/container_component.rb +0 -25
  154. data/app/components/ariadne/content.rb +0 -12
  155. data/app/components/ariadne/counter_component.rb +0 -100
  156. data/app/components/ariadne/details_component/details_component.html.erb +0 -4
  157. data/app/components/ariadne/details_component.rb +0 -81
  158. data/app/components/ariadne/dropdown/menu_component.d.ts +0 -1
  159. data/app/components/ariadne/dropdown/menu_component.html.erb +0 -20
  160. data/app/components/ariadne/dropdown/menu_component.js +0 -1
  161. data/app/components/ariadne/dropdown/menu_component.rb +0 -101
  162. data/app/components/ariadne/dropdown/menu_component.ts +0 -1
  163. data/app/components/ariadne/dropdown_component/dropdown_component.html.erb +0 -8
  164. data/app/components/ariadne/dropdown_component.rb +0 -172
  165. data/app/components/ariadne/events_controller/events_controller.d.ts +0 -4
  166. data/app/components/ariadne/events_controller/events_controller.js +0 -6
  167. data/app/components/ariadne/events_controller/events_controller.ts +0 -7
  168. data/app/components/ariadne/flash_component/flash_component.html.erb +0 -31
  169. data/app/components/ariadne/flash_component.rb +0 -128
  170. data/app/components/ariadne/flex_component/flex_component.html.erb +0 -5
  171. data/app/components/ariadne/flex_component.rb +0 -56
  172. data/app/components/ariadne/footer_component/footer_component.html.erb +0 -7
  173. data/app/components/ariadne/footer_component.rb +0 -23
  174. data/app/components/ariadne/grid_component/grid_component.html.erb +0 -26
  175. data/app/components/ariadne/grid_component.rb +0 -67
  176. data/app/components/ariadne/header_component/header_component.html.erb +0 -29
  177. data/app/components/ariadne/header_component.rb +0 -111
  178. data/app/components/ariadne/heading_component.rb +0 -49
  179. data/app/components/ariadne/heroicon_component/heroicon_component.html.erb +0 -4
  180. data/app/components/ariadne/heroicon_component.rb +0 -166
  181. data/app/components/ariadne/image_component.rb +0 -53
  182. data/app/components/ariadne/inline_flex_component/inline_flex_component.html.erb +0 -6
  183. data/app/components/ariadne/inline_flex_component.rb +0 -72
  184. data/app/components/ariadne/layout_component.html.erb +0 -21
  185. data/app/components/ariadne/layout_component.rb +0 -69
  186. data/app/components/ariadne/link_component.rb +0 -65
  187. data/app/components/ariadne/list_component/list_component.html.erb +0 -3
  188. data/app/components/ariadne/list_component.rb +0 -70
  189. data/app/components/ariadne/modal_component.html.erb +0 -11
  190. data/app/components/ariadne/modal_component.rb +0 -88
  191. data/app/components/ariadne/narrow_container_component/narrow_container_component.html.erb +0 -3
  192. data/app/components/ariadne/narrow_container_component.rb +0 -30
  193. data/app/components/ariadne/options_controller/options_controller.d.ts +0 -39
  194. data/app/components/ariadne/options_controller/options_controller.js +0 -89
  195. data/app/components/ariadne/options_controller/options_controller.ts +0 -122
  196. data/app/components/ariadne/outlet_manager_controller/outlet_manager_controller.d.ts +0 -42
  197. data/app/components/ariadne/outlet_manager_controller/outlet_manager_controller.js +0 -237
  198. data/app/components/ariadne/outlet_manager_controller/outlet_manager_controller.ts +0 -278
  199. data/app/components/ariadne/panel_bar_component/panel_bar_component.html.erb +0 -20
  200. data/app/components/ariadne/panel_bar_component.rb +0 -80
  201. data/app/components/ariadne/pill_component/pill_component.html.erb +0 -3
  202. data/app/components/ariadne/pill_component.rb +0 -44
  203. data/app/components/ariadne/popover_component.html.erb +0 -10
  204. data/app/components/ariadne/popover_component.rb +0 -81
  205. data/app/components/ariadne/progress_bar_component.html.erb +0 -5
  206. data/app/components/ariadne/progress_bar_component.rb +0 -63
  207. data/app/components/ariadne/relative_time_component.html.erb +0 -3
  208. data/app/components/ariadne/relative_time_component.rb +0 -61
  209. data/app/components/ariadne/show_more_button_component.html.erb +0 -11
  210. data/app/components/ariadne/show_more_button_component.rb +0 -47
  211. data/app/components/ariadne/slideover_component/slideover-component.d.ts +0 -9
  212. data/app/components/ariadne/slideover_component/slideover-component.js +0 -11
  213. data/app/components/ariadne/slideover_component/slideover-component.ts +0 -17
  214. data/app/components/ariadne/slideover_component/slideover_component.html.erb +0 -9
  215. data/app/components/ariadne/slideover_component.rb +0 -66
  216. data/app/components/ariadne/spinner_component.html.erb +0 -16
  217. data/app/components/ariadne/spinner_component.rb +0 -45
  218. data/app/components/ariadne/string_match_controller/string_match_controller.d.ts +0 -27
  219. data/app/components/ariadne/string_match_controller/string_match_controller.js +0 -51
  220. data/app/components/ariadne/string_match_controller/string_match_controller.ts +0 -65
  221. data/app/components/ariadne/subheader_component.html.erb +0 -11
  222. data/app/components/ariadne/subheader_component.rb +0 -65
  223. data/app/components/ariadne/synced_boolean_attributes_controller/synced_boolean_attributes_controller.d.ts +0 -48
  224. data/app/components/ariadne/synced_boolean_attributes_controller/synced_boolean_attributes_controller.js +0 -207
  225. data/app/components/ariadne/synced_boolean_attributes_controller/synced_boolean_attributes_controller.ts +0 -256
  226. data/app/components/ariadne/tab_component/tab_component.html.erb +0 -3
  227. data/app/components/ariadne/tab_component.rb +0 -98
  228. data/app/components/ariadne/tab_container_component/tab-container-component.d.ts +0 -1
  229. data/app/components/ariadne/tab_container_component/tab-container-component.js +0 -23
  230. data/app/components/ariadne/tab_container_component/tab-container-component.ts +0 -24
  231. data/app/components/ariadne/tab_container_component.erb +0 -10
  232. data/app/components/ariadne/tab_container_component.rb +0 -68
  233. data/app/components/ariadne/tab_nav_component/tab-nav-component.d.ts +0 -9
  234. data/app/components/ariadne/tab_nav_component/tab-nav-component.js +0 -33
  235. data/app/components/ariadne/tab_nav_component/tab-nav-component.ts +0 -34
  236. data/app/components/ariadne/tab_nav_component/tab_nav_component.html.erb +0 -7
  237. data/app/components/ariadne/tab_nav_component.rb +0 -72
  238. data/app/components/ariadne/table_nav_component/table_nav_component.html.erb +0 -52
  239. data/app/components/ariadne/table_nav_component.rb +0 -338
  240. data/app/components/ariadne/text.rb +0 -25
  241. data/app/components/ariadne/time_ago_component/time-ago-component.d.ts +0 -1
  242. data/app/components/ariadne/time_ago_component/time-ago-component.js +0 -1
  243. data/app/components/ariadne/time_ago_component/time-ago-component.ts +0 -1
  244. data/app/components/ariadne/time_ago_component.rb +0 -56
  245. data/app/components/ariadne/timeline_component/timeline_component.html.erb +0 -19
  246. data/app/components/ariadne/timeline_component.rb +0 -34
  247. data/app/components/ariadne/toggle_component/toggle_component.html.erb +0 -15
  248. data/app/components/ariadne/toggle_component.rb +0 -95
  249. data/app/components/ariadne/toggleable_controller/toggleable_controller.d.ts +0 -34
  250. data/app/components/ariadne/toggleable_controller/toggleable_controller.js +0 -54
  251. data/app/components/ariadne/toggleable_controller/toggleable_controller.ts +0 -77
  252. data/app/components/ariadne/tooltip_component/tooltip-component.d.ts +0 -24
  253. data/app/components/ariadne/tooltip_component/tooltip-component.js +0 -43
  254. data/app/components/ariadne/tooltip_component/tooltip-component.ts +0 -57
  255. data/app/components/ariadne/tooltip_component/tooltip_component.html.erb +0 -4
  256. data/app/components/ariadne/tooltip_component.rb +0 -108
  257. data/app/lib/ariadne/action_view_extensions/form_helper.rb +0 -30
  258. data/app/lib/ariadne/audited/dsl.rb +0 -32
  259. data/app/lib/ariadne/form_builder.rb +0 -80
  260. data/app/lib/ariadne/status/dsl.rb +0 -41
  261. data/config/importmap.rb +0 -3
  262. data/exe/tailwindcss +0 -21
  263. data/lib/rubocop/cop/ariadne/base_cop.rb +0 -26
  264. data/tailwind.config.js +0 -70
@@ -0,0 +1,98 @@
1
+ # frozen_string_literal: true
2
+
3
+ # :nocov:
4
+ module Ariadne
5
+ # :nodoc:
6
+ module Yard
7
+ # Helper methods to use for yard documentation
8
+ module DocsHelper
9
+ def one_of(enumerable, lower: false, sort: true)
10
+ # Sort the array if requested
11
+ if sort && !enumerable.nil?
12
+ enumerable = enumerable.sort do |a, b|
13
+ a.instance_of?(b.class) ? a <=> b : a.class.to_s <=> b.class.to_s
14
+ end
15
+ end
16
+
17
+ values =
18
+ case enumerable
19
+ when Hash
20
+ enumerable.map do |key, value|
21
+ "#{pretty_value(key)} (#{pretty_value(value)})"
22
+ end
23
+ else
24
+ enumerable.map do |key|
25
+ pretty_value(key)
26
+ end
27
+ end
28
+
29
+ prefix = "One of"
30
+ prefix = prefix.downcase if lower
31
+
32
+ "#{prefix} #{values.to_sentence(two_words_connector: " or ", last_word_connector: ", or ")}."
33
+ end
34
+
35
+ def link_to_accessibility
36
+ "[Accessibility](#accessibility)"
37
+ end
38
+
39
+ def link_to_system_arguments_docs
40
+ "[System arguments](/system-arguments)"
41
+ end
42
+
43
+ def link_to_typography_docs
44
+ "[Typography](/system-arguments#typography)"
45
+ end
46
+
47
+ def link_to_component(component)
48
+ status_module, short_name, class_name = status_module_and_short_name(component)
49
+ status_path = status_module.nil? ? "" : "#{status_module}/"
50
+
51
+ "[#{class_name}](/components/#{status_path}#{short_name.downcase})"
52
+ end
53
+
54
+ def link_to_octicons
55
+ "[Octicon](https://primer.style/octicons/)"
56
+ end
57
+
58
+ def link_to_heading_practices
59
+ "[Learn more about best heading practices (WAI Headings)](https://www.w3.org/WAI/tutorials/page-structure/headings/)"
60
+ end
61
+
62
+ def status_module_and_short_name(component)
63
+ name_with_status = component.name.gsub(/Ariadne::|Component/, "")
64
+
65
+ m = name_with_status.match(/(?<status>Beta|Alpha|Deprecated)?(?<_colons>::)?(?<name>.*)/)
66
+ [m[:status]&.downcase, m[:name].gsub("::", ""), m[:name]]
67
+ end
68
+
69
+ def pretty_default_value(tag, component)
70
+ params = tag.object.parameters.find { |param| [tag.name.to_s, "#{tag.name}:"].include?(param[0]) }
71
+ default = tag.defaults&.first || params&.second
72
+
73
+ return "N/A" unless default
74
+
75
+ constant_name = "#{component.name}::#{default}"
76
+ constant_value = default.safe_constantize || constant_name.safe_constantize
77
+
78
+ return pretty_value(default) if constant_value.nil?
79
+
80
+ pretty_value(constant_value)
81
+ end
82
+
83
+ def pretty_value(val)
84
+ case val
85
+ when nil
86
+ "`nil`"
87
+ when Symbol
88
+ "`:#{val}`"
89
+ else
90
+ "`#{val}`"
91
+ end
92
+ end
93
+ end
94
+
95
+ DocsHelper.extend(DocsHelper)
96
+ end
97
+ end
98
+ # :nocov:
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ # :nocov:
4
+ module Ariadne
5
+ module Yard
6
+ # Helper methods to use for info arch yard documentation
7
+ module InfoArchDocsHelper
8
+ include DocsHelper
9
+
10
+ def link_to_component(component)
11
+ "{{#link_to_component}}#{component}{{/link_to_component}}"
12
+ end
13
+
14
+ def link_to_system_arguments_docs
15
+ "{{link_to_system_arguments_docs}}"
16
+ end
17
+
18
+ def link_to_typography_docs
19
+ "{{link_to_typography_docs}}"
20
+ end
21
+
22
+ def link_to_accessibility
23
+ "{{link_to_accessibility}}"
24
+ end
25
+
26
+ def link_to_octicons
27
+ "{{link_to_octicons}}"
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ # :nocov:
4
+ module Ariadne
5
+ module Yard
6
+ # Helper methods for documentation generated in Lookbook pages.
7
+ module LookbookDocsHelper
8
+ # Adheres to the same signature as Ariadne::Yard::DocsHelper#link_to_component so link_to_component
9
+ # may be used in a Gatsby or Lookbook context and produce the correct link for each platform.
10
+ #
11
+ # @param component [Class] The component class to link to.
12
+ # @return [String] The link, either in HTML or markdown format.
13
+ def link_to_component(component)
14
+ backend = Ariadne::Yard::LookbookPagesBackend.new(Ariadne::Yard::Registry.make, nil)
15
+ component_ref = Ariadne::Yard::ComponentManifest.ref_for(component)
16
+ page = backend.page_for(component_ref)
17
+
18
+ # If the page_path method is available, we're being rendered into HTML by Lookbook
19
+ # and should emit an HTML <a> tag. No page_path means we're being rendered into
20
+ # markdown by LookbookPagesBackend and should emit a markdown + ERB link that
21
+ # Lookbook will eventually render on page load.
22
+ if respond_to?(:page_path)
23
+ link_to(page.docs.short_name, page_path(page.page_id.to_sym.inspect))
24
+ else
25
+ # rubocop:disable Rails/OutputSafety
26
+ "[#{page.docs.short_name}](<%= page_path(#{page.page_id.to_sym.inspect}) %>)".html_safe
27
+ # rubocop:enable Rails/OutputSafety
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,235 @@
1
+ # frozen_string_literal: true
2
+
3
+ # :nocov:
4
+ module Ariadne
5
+ module Yard
6
+ # A single Lookbook page.
7
+ class LookbookPage
8
+ include DocsHelper
9
+
10
+ PREVIEW_MAP = {
11
+ Ariadne::Alpha::TextField => [:single_text_field_form, :multi_text_field_form],
12
+ Ariadne::Alpha::TextArea => [],
13
+ Ariadne::Alpha::Select => [:select_form],
14
+ Ariadne::Alpha::MultiInput => [:multi_input_form],
15
+ Ariadne::Alpha::RadioButton => [:radio_button_with_nested_form],
16
+ Ariadne::Alpha::RadioButtonGroup => [:radio_button_group_form],
17
+ Ariadne::Alpha::CheckBox => [:check_box_with_nested_form],
18
+ Ariadne::Alpha::CheckBoxGroup => [:check_box_group_form],
19
+ Ariadne::Alpha::SubmitButton => [:submit_button_form],
20
+ Ariadne::Alpha::FormButton => [:submit_button_form],
21
+ }.freeze
22
+
23
+ attr_reader :component_ref, :backend, :docs
24
+
25
+ def initialize(component_ref, backend, docs)
26
+ @component_ref = component_ref
27
+ @backend = backend
28
+ @docs = docs
29
+ end
30
+
31
+ def page_id
32
+ @page_id ||= docs.short_name.dasherize.underscore.tap do |page_id|
33
+ page_id << "_input" unless page_id.end_with?("_input")
34
+ end
35
+ end
36
+
37
+ def generate
38
+ path = File.expand_path(
39
+ File.join(
40
+ "..",
41
+ "..",
42
+ "..",
43
+ "previews",
44
+ "pages",
45
+ "forms",
46
+ "inputs",
47
+ "#{docs.short_name.dasherize.underscore}.md.erb",
48
+ ),
49
+ __dir__,
50
+ )
51
+
52
+ docs.non_slot_methods.select do |mtd|
53
+ [component.name, "Ariadne::Forms::Dsl::InputMethods"].include?(mtd.parent.title)
54
+ end
55
+
56
+ preview_methods = PREVIEW_MAP[component]
57
+ preview_methods.map do |preview_method|
58
+ if Ariadne::FormsPreview.instance_methods.exclude?(preview_method)
59
+ raise "Preview '#{preview_method}' does not exist in Ariadne::FormsPreview"
60
+ end
61
+ # rubocop:enable Style/IfUnlessModifier
62
+
63
+ "<%= embed Ariadne::FormsPreview, #{preview_method.inspect} %>"
64
+ end
65
+ # rubocop:disable Security/Eval
66
+ File.open(path, "w") do |f|
67
+ f.write(eval(Erubi::Engine.new(<<~ERB, trim: true).src))
68
+ ---
69
+ title: <%= docs.title.underscore.titleize %>
70
+ id: <%= page_id %>
71
+ ---
72
+
73
+ <%= docs.base_docstring %>
74
+
75
+ ## Usage
76
+
77
+ ```ruby
78
+ <%= docs.tags(:form_usage).first.text %>
79
+ ```
80
+
81
+ <% specific_args = specific_args_from(docs.params) %>
82
+ <% unless specific_args.empty? %>
83
+ ## Arguments
84
+
85
+ <%= generate_args_table(specific_args) %>
86
+ <% end %>
87
+
88
+ ## Common arguments
89
+
90
+ <%= generate_args_table(common_args_from(docs.params)) %>
91
+
92
+ <% unless documented_methods.empty? %>
93
+ ## Methods
94
+
95
+ <% documented_methods.each do |method_docs| %>
96
+ ### `#<%= method_docs.signature.sub(/def /, "") %>`
97
+
98
+ <%= method_docs.base_docstring %>
99
+
100
+ <% param_tags = method_docs.tags(:param) %>
101
+
102
+ <% if param_tags.any? %>
103
+
104
+ <%= generate_args_table(param_tags) %>
105
+ <% end %>
106
+ <% end %>
107
+ <% end %>
108
+
109
+ <% unless preview_methods.empty? %>
110
+ ## Examples
111
+
112
+ <%= preview_erbs.join("\n") %>
113
+ <% end %>
114
+ ERB
115
+ end
116
+ # rubocop:enable Security/Eval
117
+ end
118
+
119
+ private
120
+
121
+ def registry
122
+ backend.registry
123
+ end
124
+
125
+ def generate_args_table(params)
126
+ rows = params.map do |tag|
127
+ description = backend.view_context.render(inline: tag.text.squish)
128
+ parts = [
129
+ "`#{tag.name}`",
130
+ tag.types.join(", "),
131
+ description,
132
+ ]
133
+
134
+ "| #{parts.join(" | ")} |"
135
+ end
136
+
137
+ <<~MARKDOWN
138
+ | Name | Type | Description |
139
+ | :- | :- | :- |
140
+ #{rows.join("\n")}
141
+ MARKDOWN
142
+ end
143
+
144
+ def common_args_from(params)
145
+ params.select { |param| common_form_input_argument_names.include?(param.name) }
146
+ end
147
+
148
+ def specific_args_from(params)
149
+ params.reject { |param| common_form_input_argument_names.include?(param.name) }
150
+ end
151
+
152
+ def common_form_input_argument_names
153
+ @common_form_input_argument_names ||= begin
154
+ macro = registry.yard_registry[".macro.form_input_arguments"]
155
+ parser = ::YARD::Docstring.parser
156
+ parser.parse(macro.macro_data)
157
+ parser
158
+ .tags
159
+ .select { |tag| tag.tag_name == "param" }
160
+ .map(&:name)
161
+ end
162
+ end
163
+
164
+ def component
165
+ component_ref.klass
166
+ end
167
+ end
168
+
169
+ # Backend that generates Lookbook pages.
170
+ class LookbookPagesBackend < Backend
171
+ attr_reader :registry, :manifest
172
+
173
+ def initialize(registry, manifest)
174
+ @registry = registry
175
+ @manifest = manifest
176
+ end
177
+
178
+ def generate
179
+ each_component do |component_ref|
180
+ page_for(component_ref).generate
181
+ end
182
+ generate_system_args_docs
183
+ end
184
+
185
+ def page_for(component_ref)
186
+ docs = registry.find(component_ref.klass)
187
+ LookbookPage.new(component_ref, self, docs)
188
+ end
189
+
190
+ def view_context
191
+ @view_context ||= super.tap do |vc|
192
+ vc.singleton_class.include(LookbookDocsHelper)
193
+ end
194
+ end
195
+
196
+ private
197
+
198
+ def each_component(&block)
199
+ manifest.each(&block)
200
+ end
201
+
202
+ def generate_system_args_docs
203
+ docs = registry.find(Ariadne::BaseComponent)
204
+
205
+ path = File.expand_path(
206
+ File.join(
207
+ "..", "..", "..", "previews", "pages", "system-arguments.md.erb"
208
+ ),
209
+ __dir__,
210
+ )
211
+
212
+ data = {
213
+ "description_md" => docs.base_docstring.to_s,
214
+ "args_md" => view_context.render(inline: docs.constructor.base_docstring),
215
+ }
216
+
217
+ frontmatter = {
218
+ "title" => "System arguments",
219
+ "id" => "system_arguments",
220
+ "data" => data,
221
+ }
222
+
223
+ File.write(
224
+ path, <<~ERB
225
+ #{YAML.dump(frontmatter)}
226
+ ---
227
+ <%= @page.data[:description_md].html_safe %>
228
+ <%= @page.data[:args_md].html_safe %>
229
+ ERB
230
+ )
231
+ end
232
+ end
233
+ end
234
+ end
235
+ # :nocov:
@@ -0,0 +1,136 @@
1
+ # frozen_string_literal: true
2
+
3
+ # :nocov:
4
+
5
+ require "view_component/test_helpers"
6
+
7
+ module Ariadne
8
+ module Yard
9
+ # A wrapper around a YARD class reference that provides convenience methods
10
+ # for extracting component parameters, accessibility status, etc.
11
+ class RegistryEntry
12
+ include DocsHelper
13
+
14
+ attr_reader :component, :docs
15
+
16
+ delegate_missing_to :docs
17
+
18
+ def initialize(component, docs)
19
+ @component = component
20
+ @docs = docs
21
+ end
22
+
23
+ def metadata
24
+ @metadata ||= begin
25
+ status_module, short_name, class_name = status_module_and_short_name(component)
26
+ status = component.status.to_s
27
+ a11y_reviewed = component.audited_at.nil? ? "false" : "true"
28
+
29
+ {
30
+ title: class_name,
31
+ class_name: class_name,
32
+ component_id: short_name.underscore,
33
+ status: status.capitalize,
34
+ status_module: status_module,
35
+ short_name: short_name,
36
+ a11y_reviewed: a11y_reviewed,
37
+ }
38
+ end
39
+ end
40
+
41
+ def constructor
42
+ docs.meths.find(&:constructor?)
43
+ end
44
+
45
+ def params
46
+ constructor&.tags(:param) || []
47
+ end
48
+
49
+ def slot_methods
50
+ public_methods.select { |mtd| slot_method?(mtd) }
51
+ end
52
+
53
+ def non_slot_methods
54
+ public_methods.reject { |mtd| slot_method?(mtd) }
55
+ end
56
+
57
+ def slot_method?(mtd)
58
+ mtd[:renders_one] || mtd[:renders_many]
59
+ end
60
+
61
+ def public_methods
62
+ # Returns: only public methods that belong to this class (i.e. no inherited methods)
63
+ # excluding the constructor
64
+ @public_methods ||= docs.meths.reject do |mtd|
65
+ mtd.tag(:private) || mtd.name == :initialize
66
+ end
67
+ end
68
+
69
+ def title
70
+ metadata[:title]
71
+ end
72
+
73
+ def component_id
74
+ metadata[:component_id]
75
+ end
76
+
77
+ def status
78
+ metadata[:status]
79
+ end
80
+
81
+ def status_module
82
+ metadata[:status_module]
83
+ end
84
+
85
+ def short_name
86
+ metadata[:short_name]
87
+ end
88
+
89
+ def a11y_reviewed?
90
+ metadata[:a11y_reviewed]
91
+ end
92
+
93
+ def manifest_entry
94
+ @manifest_entry ||= ComponentManifest.ref_for(component)
95
+ end
96
+ end
97
+
98
+ # Wrapper around an instance of YARD::Registry that provides easy access to component
99
+ # documentation.
100
+ class Registry
101
+ class << self
102
+ include ViewComponent::TestHelpers
103
+ include Ariadne::ViewHelper
104
+ include Ariadne::Yard::DocsHelper
105
+
106
+ def make
107
+ registry = ::YARD::RegistryStore.new
108
+ registry.load!(File.expand_path(File.join("..", "..", "..", ".yardoc"), __dir__))
109
+
110
+ new(registry)
111
+ end
112
+ end
113
+
114
+ attr_reader :yard_registry
115
+
116
+ def initialize(yard_registry)
117
+ @yard_registry = yard_registry
118
+ end
119
+
120
+ def find(component)
121
+ return entries[component] if entries.include?(component)
122
+
123
+ return unless (docs = yard_registry.get(component.name))
124
+
125
+ entries[component] = RegistryEntry.new(component, docs)
126
+ end
127
+
128
+ private
129
+
130
+ def entries
131
+ @entries ||= {}
132
+ end
133
+ end
134
+ end
135
+ end
136
+ # :nocov:
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ # :nocov:
4
+ module Ariadne
5
+ module Yard
6
+ # YARD Handler to parse `renders_many` calls.
7
+ class RendersManyHandler < ::YARD::Handlers::Ruby::Base
8
+ handles method_call(:renders_many)
9
+ namespace_only
10
+
11
+ process do
12
+ name = statement.parameters.first.jump(:tstring_content, :ident).source
13
+ object = ::YARD::CodeObjects::MethodObject.new(namespace, name)
14
+ register(object)
15
+ parse_block(statement.last, owner: object)
16
+
17
+ object.dynamic = true
18
+ object[:renders_many] = true
19
+ end
20
+ end
21
+ end
22
+ end
23
+ # :nocov:
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ # :nocov:
4
+ module Ariadne
5
+ module Yard
6
+ # YARD Handler to parse `renders_one` calls.
7
+ class RendersOneHandler < ::YARD::Handlers::Ruby::Base
8
+ handles method_call(:renders_one)
9
+ namespace_only
10
+
11
+ process do
12
+ name = statement.parameters.first.jump(:tstring_content, :ident).source
13
+ object = ::YARD::CodeObjects::MethodObject.new(namespace, name)
14
+ register(object)
15
+ parse_block(statement.last, owner: object)
16
+
17
+ object.dynamic = true
18
+ object[:renders_one] = true
19
+ end
20
+ end
21
+ end
22
+ end
23
+ # :nocov:
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "yard"
4
+
5
+ module Ariadne
6
+ # :nodoc:
7
+ module Yard
8
+ autoload :Backend, "primer/yard/backend"
9
+ autoload :ComponentManifest, "primer/yard/component_manifest"
10
+ autoload :ComponentRef, "primer/yard/component_ref"
11
+ autoload :DocsHelper, "primer/yard/docs_helper"
12
+ autoload :InfoArchDocsHelper, "primer/yard/info_arch_docs_helper"
13
+ autoload :Registry, "primer/yard/registry"
14
+ autoload :RendersManyHandler, "primer/yard/renders_many_handler"
15
+ autoload :RendersOneHandler, "primer/yard/renders_one_handler"
16
+
17
+ ::YARD::Tags::Library.define_tag("Snapshot preview", :snapshot)
18
+ end
19
+ end