ariadne_view_components 0.0.59 → 0.0.65
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +70 -0
- data/LICENSE.txt +661 -49
- data/README.md +52 -4
- data/app/assets/javascripts/ariadne_view_components.js +98 -7
- data/app/assets/javascripts/ariadne_view_components.js.br +0 -0
- data/app/assets/javascripts/ariadne_view_components.js.gz +0 -0
- data/app/assets/javascripts/ariadne_view_components.js.map +1 -1
- data/app/assets/stylesheets/ariadne_view_components.css +1 -7
- data/app/assets/stylesheets/ariadne_view_components.css.br +0 -0
- data/app/assets/stylesheets/ariadne_view_components.css.gz +0 -0
- data/app/components/ariadne/base_component.rb +79 -27
- data/app/components/ariadne/behaviors/tooltipable.rb +120 -0
- data/app/components/ariadne/conditional_wrapper.rb +21 -0
- data/app/components/ariadne/form/base_component.rb +74 -0
- data/app/components/ariadne/form/base_input_component.rb +60 -0
- data/app/components/ariadne/form/caption/component.html.erb +10 -0
- data/app/components/ariadne/form/caption/component.rb +29 -0
- data/app/components/ariadne/form/form_control/component.html.erb +19 -0
- data/app/components/ariadne/form/form_control/component.rb +27 -0
- data/app/components/ariadne/form/form_reference/component.html.erb +1 -0
- data/app/components/ariadne/form/form_reference/component.rb +18 -0
- data/app/components/ariadne/form/group/component.html.erb +5 -0
- data/app/components/ariadne/form/group/component.rb +27 -0
- data/app/components/ariadne/form/hidden_field/component.html.erb +1 -0
- data/app/components/ariadne/form/hidden_field/component.rb +15 -0
- data/app/components/ariadne/form/separator/component.html.erb +1 -0
- data/app/components/ariadne/form/separator/component.rb +8 -0
- data/app/components/ariadne/form/spacing_wrapper/component.html.erb +3 -0
- data/app/components/ariadne/form/spacing_wrapper/component.rb +8 -0
- data/app/components/ariadne/form/text_field/component.html.erb +25 -0
- data/app/components/ariadne/form/text_field/component.rb +132 -0
- data/app/components/ariadne/form/validation_message/component.html.erb +5 -0
- data/app/components/ariadne/form/validation_message/component.rb +14 -0
- data/app/components/ariadne/layout/narrow/component.html.erb +10 -0
- data/app/components/ariadne/layout/narrow/component.rb +24 -0
- data/app/components/ariadne/layout/nav_bar/component.css +0 -0
- data/app/components/ariadne/layout/nav_bar/component.html.erb +123 -0
- data/app/components/ariadne/layout/nav_bar/component.rb +77 -0
- data/app/components/ariadne/ui/button/component.html.erb +5 -0
- data/app/components/ariadne/ui/button/component.rb +184 -0
- data/app/components/ariadne/ui/clipboard_copy/component.html.erb +8 -0
- data/app/components/ariadne/ui/clipboard_copy/component.rb +102 -0
- data/app/components/ariadne/ui/clipboard_copy/component.ts +54 -0
- data/app/components/ariadne/ui/combobox/component.html.erb +32 -0
- data/app/components/ariadne/ui/combobox/component.rb +83 -0
- data/app/components/ariadne/ui/combobox/component.ts +119 -0
- data/app/components/ariadne/ui/combobox/menu_item/component.html.erb +9 -0
- data/app/components/ariadne/ui/combobox/menu_item/component.rb +53 -0
- data/app/components/ariadne/ui/combobox/option/component.html.erb +11 -0
- data/app/components/ariadne/ui/combobox/option/component.rb +45 -0
- data/app/components/ariadne/ui/heroicon/component.html.erb +3 -0
- data/app/components/ariadne/ui/heroicon/component.rb +141 -0
- data/app/components/ariadne/ui/image/component.rb +69 -0
- data/app/components/ariadne/ui/link/component.html.erb +3 -0
- data/app/components/ariadne/ui/link/component.rb +56 -0
- data/app/components/ariadne/ui/typography/component.html.erb +3 -0
- data/app/components/ariadne/ui/typography/component.rb +41 -0
- data/app/frontend/ariadne/index.ts +14 -0
- data/app/frontend/ariadne/stimulus_app.ts +53 -0
- data/app/frontend/ariadne/theme.ts +8 -0
- data/app/frontend/controllers/tooltip.ts +75 -0
- data/app/frontend/entrypoints/application.ts +1 -0
- data/app/frontend/stylesheets/ariadne_view_components.css +18 -0
- data/app/frontend/stylesheets/scrollbar.css +28 -0
- data/app/frontend/stylesheets/tippy.js/themes/tomato.css +4 -0
- data/app/frontend/stylesheets/typography.css +117 -0
- data/app/frontend/utils/createController.ts +95 -0
- data/app/helpers/ariadne/form_helper.rb +31 -0
- data/app/lib/ariadne/attributes_helper.rb +119 -0
- data/app/lib/ariadne/fetch_or_fallback_helper.rb +1 -1
- data/app/lib/ariadne/form.rb +16 -0
- data/app/lib/ariadne/view_helper.rb +2 -5
- data/app/lib/view_components_contrib/html_attrs.rb +64 -0
- data/app/lib/view_components_contrib/style_variants.rb +14 -0
- data/lib/ariadne/forms/acts_as_component.rb +125 -0
- data/lib/ariadne/forms/base.html.erb +8 -0
- data/lib/ariadne/forms/base.rb +132 -0
- data/lib/ariadne/forms/buffer_rewriter.rb +51 -0
- data/lib/ariadne/forms/builder.rb +88 -0
- data/lib/ariadne/forms/dsl/button_input.rb +33 -0
- data/lib/ariadne/forms/dsl/form_object.rb +26 -0
- data/lib/ariadne/forms/dsl/input.rb +322 -0
- data/lib/ariadne/forms/dsl/input_group.rb +34 -0
- data/lib/ariadne/forms/dsl/input_methods.rb +157 -0
- data/lib/ariadne/forms/dsl/submit_button_input.rb +36 -0
- data/lib/ariadne/forms/dsl/text_field_input.rb +73 -0
- data/lib/ariadne/forms/utils.rb +34 -0
- data/lib/ariadne/generate.rb +11 -0
- data/lib/ariadne/view_components/engine.rb +24 -7
- data/lib/ariadne/view_components/version.rb +1 -1
- data/lib/ariadne/view_components.rb +1 -1
- data/lib/ariadne/yard/backend.rb +24 -0
- data/lib/ariadne/yard/component_manifest.rb +148 -0
- data/lib/ariadne/yard/component_ref.rb +49 -0
- data/lib/ariadne/yard/docs_helper.rb +98 -0
- data/lib/ariadne/yard/info_arch_docs_helper.rb +31 -0
- data/lib/ariadne/yard/lookbook_docs_helper.rb +32 -0
- data/lib/ariadne/yard/lookbook_pages_backend.rb +235 -0
- data/lib/ariadne/yard/registry.rb +136 -0
- data/lib/ariadne/yard/renders_many_handler.rb +23 -0
- data/lib/ariadne/yard/renders_one_handler.rb +23 -0
- data/lib/ariadne/yard.rb +19 -0
- data/static/arguments.yml +141 -48
- data/static/audited_at.json +0 -9
- data/static/classes.yml +210 -209
- data/static/constants.json +2 -209
- data/static/statuses.json +0 -9
- metadata +140 -210
- data/app/assets/builds/ariadne_view_components.css +0 -2202
- data/app/assets/javascripts/components/ariadne/accumulator_controller/accumulator_controller.d.ts +0 -22
- data/app/assets/javascripts/components/ariadne/ariadne-form.d.ts +0 -22
- data/app/assets/javascripts/components/ariadne/ariadne.d.ts +0 -2
- data/app/assets/javascripts/components/ariadne/clipboard_copy_component/clipboard-copy-component.d.ts +0 -4
- data/app/assets/javascripts/components/ariadne/dropdown/menu_component.d.ts +0 -1
- data/app/assets/javascripts/components/ariadne/events_controller/events_controller.d.ts +0 -4
- data/app/assets/javascripts/components/ariadne/options_controller/options_controller.d.ts +0 -39
- data/app/assets/javascripts/components/ariadne/outlet_manager_controller/outlet_manager_controller.d.ts +0 -42
- data/app/assets/javascripts/components/ariadne/slideover_component/slideover-component.d.ts +0 -9
- data/app/assets/javascripts/components/ariadne/string_match_controller/string_match_controller.d.ts +0 -27
- data/app/assets/javascripts/components/ariadne/synced_boolean_attributes_controller/synced_boolean_attributes_controller.d.ts +0 -48
- data/app/assets/javascripts/components/ariadne/tab_container_component/tab-container-component.d.ts +0 -1
- data/app/assets/javascripts/components/ariadne/tab_nav_component/tab-nav-component.d.ts +0 -9
- data/app/assets/javascripts/components/ariadne/time_ago_component/time-ago-component.d.ts +0 -1
- data/app/assets/javascripts/components/ariadne/toggleable_controller/toggleable_controller.d.ts +0 -34
- data/app/assets/javascripts/components/ariadne/tooltip_component/tooltip-component.d.ts +0 -24
- data/app/assets/stylesheets/dropdown.css +0 -46
- data/app/assets/stylesheets/prosemirror.css +0 -323
- data/app/assets/stylesheets/tooltip-component.css +0 -37
- data/app/components/ariadne/accumulator_controller/accumulator_controller.d.ts +0 -22
- data/app/components/ariadne/accumulator_controller/accumulator_controller.js +0 -39
- data/app/components/ariadne/accumulator_controller/accumulator_controller.ts +0 -48
- data/app/components/ariadne/action_card_component.html.erb +0 -13
- data/app/components/ariadne/action_card_component.rb +0 -88
- data/app/components/ariadne/ariadne-form.d.ts +0 -22
- data/app/components/ariadne/ariadne-form.js +0 -85
- data/app/components/ariadne/ariadne.d.ts +0 -2
- data/app/components/ariadne/ariadne.js +0 -24
- data/app/components/ariadne/ariadne.ts +0 -29
- data/app/components/ariadne/avatar_component.rb +0 -81
- data/app/components/ariadne/avatar_stack_component/avatar_stack_component.html.erb +0 -12
- data/app/components/ariadne/avatar_stack_component.rb +0 -75
- data/app/components/ariadne/base_button.rb +0 -70
- data/app/components/ariadne/blankslate_component/blankslate_component.html.erb +0 -26
- data/app/components/ariadne/blankslate_component.rb +0 -148
- data/app/components/ariadne/body_component.rb +0 -30
- data/app/components/ariadne/bottom_tab_component.html.erb +0 -4
- data/app/components/ariadne/bottom_tab_component.rb +0 -44
- data/app/components/ariadne/bottom_tab_nav_component.html.erb +0 -5
- data/app/components/ariadne/bottom_tab_nav_component.rb +0 -33
- data/app/components/ariadne/breadcrumbs_component.html.erb +0 -13
- data/app/components/ariadne/breadcrumbs_component.rb +0 -31
- data/app/components/ariadne/button_component/button_component.html.erb +0 -4
- data/app/components/ariadne/button_component.rb +0 -165
- data/app/components/ariadne/checkbox_component.html.erb +0 -5
- data/app/components/ariadne/checkbox_component.rb +0 -43
- data/app/components/ariadne/clipboard_copy_component/clipboard-copy-component.d.ts +0 -4
- data/app/components/ariadne/clipboard_copy_component/clipboard-copy-component.js +0 -18
- data/app/components/ariadne/clipboard_copy_component/clipboard-copy-component.ts +0 -19
- data/app/components/ariadne/clipboard_copy_component/clipboard_copy_component.html.erb +0 -9
- data/app/components/ariadne/clipboard_copy_component.rb +0 -90
- data/app/components/ariadne/close_button_component.html.erb +0 -4
- data/app/components/ariadne/close_button_component.rb +0 -33
- data/app/components/ariadne/combobox_component.html.erb +0 -14
- data/app/components/ariadne/combobox_component.rb +0 -76
- data/app/components/ariadne/component.rb +0 -127
- data/app/components/ariadne/container_component/container_component.html.erb +0 -3
- data/app/components/ariadne/container_component.rb +0 -25
- data/app/components/ariadne/content.rb +0 -12
- data/app/components/ariadne/counter_component.rb +0 -100
- data/app/components/ariadne/details_component/details_component.html.erb +0 -4
- data/app/components/ariadne/details_component.rb +0 -81
- data/app/components/ariadne/dropdown/menu_component.d.ts +0 -1
- data/app/components/ariadne/dropdown/menu_component.html.erb +0 -20
- data/app/components/ariadne/dropdown/menu_component.js +0 -1
- data/app/components/ariadne/dropdown/menu_component.rb +0 -101
- data/app/components/ariadne/dropdown/menu_component.ts +0 -1
- data/app/components/ariadne/dropdown_component/dropdown_component.html.erb +0 -8
- data/app/components/ariadne/dropdown_component.rb +0 -172
- data/app/components/ariadne/events_controller/events_controller.d.ts +0 -4
- data/app/components/ariadne/events_controller/events_controller.js +0 -6
- data/app/components/ariadne/events_controller/events_controller.ts +0 -7
- data/app/components/ariadne/flash_component/flash_component.html.erb +0 -31
- data/app/components/ariadne/flash_component.rb +0 -128
- data/app/components/ariadne/flex_component/flex_component.html.erb +0 -5
- data/app/components/ariadne/flex_component.rb +0 -56
- data/app/components/ariadne/footer_component/footer_component.html.erb +0 -7
- data/app/components/ariadne/footer_component.rb +0 -23
- data/app/components/ariadne/grid_component/grid_component.html.erb +0 -26
- data/app/components/ariadne/grid_component.rb +0 -67
- data/app/components/ariadne/header_component/header_component.html.erb +0 -29
- data/app/components/ariadne/header_component.rb +0 -111
- data/app/components/ariadne/heading_component.rb +0 -49
- data/app/components/ariadne/heroicon_component/heroicon_component.html.erb +0 -4
- data/app/components/ariadne/heroicon_component.rb +0 -166
- data/app/components/ariadne/image_component.rb +0 -53
- data/app/components/ariadne/inline_flex_component/inline_flex_component.html.erb +0 -6
- data/app/components/ariadne/inline_flex_component.rb +0 -72
- data/app/components/ariadne/layout_component.html.erb +0 -21
- data/app/components/ariadne/layout_component.rb +0 -69
- data/app/components/ariadne/link_component.rb +0 -65
- data/app/components/ariadne/list_component/list_component.html.erb +0 -3
- data/app/components/ariadne/list_component.rb +0 -70
- data/app/components/ariadne/modal_component.html.erb +0 -11
- data/app/components/ariadne/modal_component.rb +0 -88
- data/app/components/ariadne/narrow_container_component/narrow_container_component.html.erb +0 -3
- data/app/components/ariadne/narrow_container_component.rb +0 -30
- data/app/components/ariadne/options_controller/options_controller.d.ts +0 -39
- data/app/components/ariadne/options_controller/options_controller.js +0 -89
- data/app/components/ariadne/options_controller/options_controller.ts +0 -122
- data/app/components/ariadne/outlet_manager_controller/outlet_manager_controller.d.ts +0 -42
- data/app/components/ariadne/outlet_manager_controller/outlet_manager_controller.js +0 -237
- data/app/components/ariadne/outlet_manager_controller/outlet_manager_controller.ts +0 -278
- data/app/components/ariadne/panel_bar_component/panel_bar_component.html.erb +0 -20
- data/app/components/ariadne/panel_bar_component.rb +0 -80
- data/app/components/ariadne/pill_component/pill_component.html.erb +0 -3
- data/app/components/ariadne/pill_component.rb +0 -44
- data/app/components/ariadne/popover_component.html.erb +0 -10
- data/app/components/ariadne/popover_component.rb +0 -81
- data/app/components/ariadne/progress_bar_component.html.erb +0 -5
- data/app/components/ariadne/progress_bar_component.rb +0 -63
- data/app/components/ariadne/relative_time_component.html.erb +0 -3
- data/app/components/ariadne/relative_time_component.rb +0 -61
- data/app/components/ariadne/show_more_button_component.html.erb +0 -11
- data/app/components/ariadne/show_more_button_component.rb +0 -47
- data/app/components/ariadne/slideover_component/slideover-component.d.ts +0 -9
- data/app/components/ariadne/slideover_component/slideover-component.js +0 -11
- data/app/components/ariadne/slideover_component/slideover-component.ts +0 -17
- data/app/components/ariadne/slideover_component/slideover_component.html.erb +0 -9
- data/app/components/ariadne/slideover_component.rb +0 -66
- data/app/components/ariadne/spinner_component.html.erb +0 -16
- data/app/components/ariadne/spinner_component.rb +0 -45
- data/app/components/ariadne/string_match_controller/string_match_controller.d.ts +0 -27
- data/app/components/ariadne/string_match_controller/string_match_controller.js +0 -51
- data/app/components/ariadne/string_match_controller/string_match_controller.ts +0 -65
- data/app/components/ariadne/subheader_component.html.erb +0 -11
- data/app/components/ariadne/subheader_component.rb +0 -65
- data/app/components/ariadne/synced_boolean_attributes_controller/synced_boolean_attributes_controller.d.ts +0 -48
- data/app/components/ariadne/synced_boolean_attributes_controller/synced_boolean_attributes_controller.js +0 -207
- data/app/components/ariadne/synced_boolean_attributes_controller/synced_boolean_attributes_controller.ts +0 -256
- data/app/components/ariadne/tab_component/tab_component.html.erb +0 -3
- data/app/components/ariadne/tab_component.rb +0 -98
- data/app/components/ariadne/tab_container_component/tab-container-component.d.ts +0 -1
- data/app/components/ariadne/tab_container_component/tab-container-component.js +0 -23
- data/app/components/ariadne/tab_container_component/tab-container-component.ts +0 -24
- data/app/components/ariadne/tab_container_component.erb +0 -10
- data/app/components/ariadne/tab_container_component.rb +0 -68
- data/app/components/ariadne/tab_nav_component/tab-nav-component.d.ts +0 -9
- data/app/components/ariadne/tab_nav_component/tab-nav-component.js +0 -33
- data/app/components/ariadne/tab_nav_component/tab-nav-component.ts +0 -34
- data/app/components/ariadne/tab_nav_component/tab_nav_component.html.erb +0 -7
- data/app/components/ariadne/tab_nav_component.rb +0 -72
- data/app/components/ariadne/table_nav_component/table_nav_component.html.erb +0 -52
- data/app/components/ariadne/table_nav_component.rb +0 -338
- data/app/components/ariadne/text.rb +0 -25
- data/app/components/ariadne/time_ago_component/time-ago-component.d.ts +0 -1
- data/app/components/ariadne/time_ago_component/time-ago-component.js +0 -1
- data/app/components/ariadne/time_ago_component/time-ago-component.ts +0 -1
- data/app/components/ariadne/time_ago_component.rb +0 -56
- data/app/components/ariadne/timeline_component/timeline_component.html.erb +0 -19
- data/app/components/ariadne/timeline_component.rb +0 -34
- data/app/components/ariadne/toggle_component/toggle_component.html.erb +0 -15
- data/app/components/ariadne/toggle_component.rb +0 -95
- data/app/components/ariadne/toggleable_controller/toggleable_controller.d.ts +0 -34
- data/app/components/ariadne/toggleable_controller/toggleable_controller.js +0 -54
- data/app/components/ariadne/toggleable_controller/toggleable_controller.ts +0 -77
- data/app/components/ariadne/tooltip_component/tooltip-component.d.ts +0 -24
- data/app/components/ariadne/tooltip_component/tooltip-component.js +0 -43
- data/app/components/ariadne/tooltip_component/tooltip-component.ts +0 -57
- data/app/components/ariadne/tooltip_component/tooltip_component.html.erb +0 -4
- data/app/components/ariadne/tooltip_component.rb +0 -108
- data/app/lib/ariadne/action_view_extensions/form_helper.rb +0 -30
- data/app/lib/ariadne/audited/dsl.rb +0 -32
- data/app/lib/ariadne/form_builder.rb +0 -80
- data/app/lib/ariadne/status/dsl.rb +0 -41
- data/config/importmap.rb +0 -3
- data/exe/tailwindcss +0 -21
- data/lib/rubocop/cop/ariadne/base_cop.rb +0 -26
- data/tailwind.config.js +0 -70
@@ -2,8 +2,6 @@
|
|
2
2
|
|
3
3
|
require "rails/engine"
|
4
4
|
|
5
|
-
require "view_component"
|
6
|
-
|
7
5
|
require "tailwind_merge"
|
8
6
|
|
9
7
|
module Ariadne
|
@@ -17,7 +15,7 @@ module Ariadne
|
|
17
15
|
isolate_namespace Ariadne::ViewComponents
|
18
16
|
|
19
17
|
config.autoload_paths = ["#{root}/lib"]
|
20
|
-
config.eager_load_paths = ["#{root}/app/components", "#{root}/app/helpers", "#{root}/app/lib"]
|
18
|
+
config.eager_load_paths = ["#{root}/app/components", "#{root}/app/forms", "#{root}/app/helpers", "#{root}/app/lib"]
|
21
19
|
|
22
20
|
config.ariadne_view_components = ActiveSupport::OrderedOptions.new
|
23
21
|
|
@@ -31,9 +29,28 @@ module Ariadne
|
|
31
29
|
app.config.assets.precompile += ["ariadne_view_components"] if app.config.respond_to?(:assets)
|
32
30
|
end
|
33
31
|
|
34
|
-
initializer "ariadne_view_components.
|
35
|
-
|
36
|
-
|
32
|
+
initializer "ariadne_view_components.eager_load_actions" do
|
33
|
+
ActiveSupport.on_load(:after_initialize) do
|
34
|
+
if Rails.application.config.eager_load
|
35
|
+
Ariadne::Forms::Base.compile!
|
36
|
+
Ariadne::Forms::Base.descendants.each(&:compile!)
|
37
|
+
Ariadne::Forms::BaseComponent.descendants.each(&:compile!)
|
38
|
+
Ariadne::Heroicon::Cache.preload!
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
initializer "ariadne.forms.helpers" do
|
44
|
+
ActiveSupport.on_load(:action_controller_base) do
|
45
|
+
begin
|
46
|
+
require "ariadne/form_helper"
|
47
|
+
rescue LoadError # rubocop:disable Lint/SuppressedException
|
48
|
+
end
|
49
|
+
|
50
|
+
helper Ariadne::FormHelper
|
51
|
+
|
52
|
+
# make ariadne_form_with available to view components also
|
53
|
+
ViewComponent::Base.prepend(Ariadne::FormHelper)
|
37
54
|
end
|
38
55
|
end
|
39
56
|
|
@@ -46,7 +63,7 @@ module Ariadne
|
|
46
63
|
end
|
47
64
|
|
48
65
|
config.after_initialize do |_app|
|
49
|
-
Ariadne::ViewComponents.tailwind_merger = TailwindMerge::Merger.new
|
66
|
+
Ariadne::ViewComponents.tailwind_merger = TailwindMerge::Merger.new(config: { prefix: "ariadne-" })
|
50
67
|
end
|
51
68
|
end
|
52
69
|
end
|
@@ -47,7 +47,7 @@ module Ariadne
|
|
47
47
|
require "json"
|
48
48
|
|
49
49
|
File.open(File.join(DEFAULT_STATIC_PATH, FILE_NAMES[stats]), "w") do |f|
|
50
|
-
f.write(JSON.pretty_generate(send("generate_#{stats}")))
|
50
|
+
f.write(JSON.pretty_generate(send(:"generate_#{stats}")))
|
51
51
|
f.write($INPUT_RECORD_SEPARATOR)
|
52
52
|
end
|
53
53
|
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# :nocov:
|
4
|
+
module Ariadne
|
5
|
+
module Yard
|
6
|
+
# Shared functionality for generating documentation from YARD comments.
|
7
|
+
class Backend
|
8
|
+
include DocsHelper
|
9
|
+
|
10
|
+
private
|
11
|
+
|
12
|
+
def view_context
|
13
|
+
@view_context ||= begin
|
14
|
+
# Rails controller for rendering arbitrary ERB
|
15
|
+
vc = ApplicationController.new.tap { |c| c.request = ActionDispatch::TestRequest.create }.view_context
|
16
|
+
vc.singleton_class.include(DocsHelper)
|
17
|
+
vc.singleton_class.include(Ariadne::ViewHelper)
|
18
|
+
vc
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
# :nocov:
|
@@ -0,0 +1,148 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# :nocov:
|
4
|
+
module Ariadne
|
5
|
+
module Yard
|
6
|
+
# The set of documented components (and associated metadata).
|
7
|
+
class ComponentManifest
|
8
|
+
COMPONENTS = {
|
9
|
+
Ariadne::Heading::Component => {},
|
10
|
+
# Primer::Beta::IconButton => {},
|
11
|
+
# Primer::Beta::Button => {},
|
12
|
+
# Primer::Alpha::SegmentedControl => {},
|
13
|
+
# Primer::Alpha::Layout => {},
|
14
|
+
# Primer::Alpha::HellipButton => {},
|
15
|
+
# Primer::Alpha::Image => {},
|
16
|
+
# Primer::Alpha::OcticonSymbols => {},
|
17
|
+
# Primer::Alpha::ImageCrop => { js: true },
|
18
|
+
# Primer::IconButton => { js: true },
|
19
|
+
# Primer::Beta::AutoComplete => { js: true },
|
20
|
+
# Primer::Beta::AutoComplete::Item => {},
|
21
|
+
# Primer::Beta::Avatar => {},
|
22
|
+
# Primer::Beta::AvatarStack => {},
|
23
|
+
# Primer::Beta::BaseButton => {},
|
24
|
+
# Primer::Alpha::Banner => { js: true },
|
25
|
+
# Primer::Beta::Blankslate => {},
|
26
|
+
# Primer::BlankslateComponent => {},
|
27
|
+
# Primer::Beta::BorderBox => {},
|
28
|
+
# Primer::Beta::BorderBox::Header => {},
|
29
|
+
# Primer::Box => {},
|
30
|
+
# Primer::Beta::Breadcrumbs => {},
|
31
|
+
# Primer::ButtonComponent => { js: true },
|
32
|
+
# Primer::Beta::ButtonGroup => {},
|
33
|
+
# Primer::Alpha::ButtonMarketing => {},
|
34
|
+
# Primer::Beta::ClipboardCopy => { js: true },
|
35
|
+
# Primer::Beta::CloseButton => {},
|
36
|
+
# Primer::Beta::Counter => {},
|
37
|
+
# Primer::Beta::Details => {},
|
38
|
+
# Primer::Alpha::Dialog => {},
|
39
|
+
# Primer::Alpha::Dropdown => { js: true },
|
40
|
+
# Primer::Beta::Flash => {},
|
41
|
+
# Primer::Beta::Heading => {},
|
42
|
+
# Primer::Alpha::HiddenTextExpander => {},
|
43
|
+
# Primer::Beta::Label => {},
|
44
|
+
# Primer::LayoutComponent => {},
|
45
|
+
# Primer::Beta::Link => { js: true },
|
46
|
+
# Primer::Beta::Markdown => {},
|
47
|
+
# Primer::Alpha::Menu => {},
|
48
|
+
# Primer::Navigation::TabComponent => {},
|
49
|
+
# Primer::Alpha::Navigation::Tab => {},
|
50
|
+
# Primer::Beta::Octicon => {},
|
51
|
+
# Primer::Beta::Popover => {},
|
52
|
+
# Primer::Beta::ProgressBar => {},
|
53
|
+
# Primer::Beta::State => {},
|
54
|
+
# Primer::Beta::Spinner => {},
|
55
|
+
# Primer::Beta::Subhead => {},
|
56
|
+
# Primer::Alpha::TabContainer => { js: true },
|
57
|
+
# Primer::Beta::Text => {},
|
58
|
+
# Primer::Beta::TimelineItem => {},
|
59
|
+
# Primer::Tooltip => {},
|
60
|
+
# Primer::Truncate => {},
|
61
|
+
# Primer::Beta::Truncate => {},
|
62
|
+
# Primer::Alpha::UnderlineNav => {},
|
63
|
+
# Primer::Alpha::UnderlinePanels => { js: true },
|
64
|
+
# Primer::Alpha::TabNav => {},
|
65
|
+
# Primer::Alpha::TabPanels => { js: true },
|
66
|
+
# Primer::Alpha::Tooltip => { js: true },
|
67
|
+
# Primer::Alpha::ToggleSwitch => { js: true },
|
68
|
+
# Primer::Alpha::Overlay => { js: true },
|
69
|
+
# Primer::Alpha::ActionMenu => { js: true },
|
70
|
+
|
71
|
+
# Examples can be seen in the NavList docs
|
72
|
+
# Primer::Alpha::NavList => { js: true },
|
73
|
+
# Primer::Alpha::NavList::Item => { js: true, examples: false },
|
74
|
+
# Primer::Alpha::NavList::Group => { js: true, examples: false },
|
75
|
+
|
76
|
+
# Primer::Beta::NavList => { js: true },
|
77
|
+
# Primer::Beta::NavList::Item => { js: true, examples: false },
|
78
|
+
# Primer::Beta::NavList::Group => { js: true, examples: false },
|
79
|
+
|
80
|
+
# ActionList is a base component that should not be used by itself, and thus
|
81
|
+
# does not have examples of its own
|
82
|
+
# Primer::Alpha::ActionList => { js: true, examples: false },
|
83
|
+
# Primer::Alpha::ActionList::Divider => { examples: false },
|
84
|
+
# Primer::Alpha::ActionList::Heading => { examples: false },
|
85
|
+
# Primer::Alpha::ActionList::Item => { examples: false },
|
86
|
+
|
87
|
+
# Forms
|
88
|
+
# Primer::Alpha::TextField => { form_component: true },
|
89
|
+
# Primer::Alpha::TextArea => { form_component: true, published: false },
|
90
|
+
# Primer::Alpha::Select => { form_component: true, published: false },
|
91
|
+
# Primer::Alpha::MultiInput => { form_component: true, js: true, published: false },
|
92
|
+
# Primer::Alpha::RadioButton => { form_component: true, published: false },
|
93
|
+
# Primer::Alpha::RadioButtonGroup => { form_component: true, published: false },
|
94
|
+
# Primer::Alpha::CheckBox => { form_component: true, published: false },
|
95
|
+
# Primer::Alpha::CheckBoxGroup => { form_component: true, published: false },
|
96
|
+
# Primer::Alpha::SubmitButton => { form_component: true, published: false },
|
97
|
+
# Primer::Alpha::FormButton => { form_component: true, published: false }
|
98
|
+
}.freeze
|
99
|
+
|
100
|
+
include Enumerable
|
101
|
+
|
102
|
+
def initialize(components)
|
103
|
+
@components = components
|
104
|
+
end
|
105
|
+
|
106
|
+
def each
|
107
|
+
return to_enum(__method__) unless block_given?
|
108
|
+
|
109
|
+
@components.each do |klass|
|
110
|
+
yield self.class.ref_for(klass)
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
def where(**attrs)
|
115
|
+
self.class.where(@components, **attrs)
|
116
|
+
end
|
117
|
+
|
118
|
+
class << self
|
119
|
+
def where(components = COMPONENTS, **desired_attrs)
|
120
|
+
new(
|
121
|
+
components.each_with_object([]) do |(klass, component_attrs), memo|
|
122
|
+
matches = desired_attrs.all? do |name, desired_value|
|
123
|
+
component_attrs.fetch(name, ComponentRef::ATTR_DEFAULTS[name]) == desired_value
|
124
|
+
end
|
125
|
+
|
126
|
+
memo << klass if matches
|
127
|
+
end,
|
128
|
+
)
|
129
|
+
end
|
130
|
+
|
131
|
+
def all
|
132
|
+
new(COMPONENTS.keys)
|
133
|
+
end
|
134
|
+
|
135
|
+
def ref_for(klass)
|
136
|
+
ref_cache[klass] ||= ComponentRef.new(klass, COMPONENTS.fetch(klass, {}))
|
137
|
+
end
|
138
|
+
|
139
|
+
private
|
140
|
+
|
141
|
+
def ref_cache
|
142
|
+
@ref_cache ||= {}
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|
148
|
+
# :nocov:
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# :nocov:
|
4
|
+
module Ariadne
|
5
|
+
module Yard
|
6
|
+
# :nodoc:
|
7
|
+
class ComponentRef
|
8
|
+
ATTR_DEFAULTS = {
|
9
|
+
js: false,
|
10
|
+
examples: true,
|
11
|
+
form_component: false,
|
12
|
+
}.freeze
|
13
|
+
|
14
|
+
attr_reader :klass, :attrs
|
15
|
+
|
16
|
+
def initialize(klass, attrs)
|
17
|
+
@klass = klass
|
18
|
+
@attrs = attrs
|
19
|
+
end
|
20
|
+
|
21
|
+
def requires_js?
|
22
|
+
@attrs.fetch(:js, ATTR_DEFAULTS[:js])
|
23
|
+
end
|
24
|
+
|
25
|
+
def should_have_examples?
|
26
|
+
@attrs.fetch(:examples, ATTR_DEFAULTS[:examples])
|
27
|
+
end
|
28
|
+
|
29
|
+
def form_component?
|
30
|
+
@attrs.fetch(:form_component, ATTR_DEFAULTS[:form_component])
|
31
|
+
end
|
32
|
+
|
33
|
+
def source_url
|
34
|
+
@source_url ||= begin
|
35
|
+
path = klass.name.split("::").map(&:underscore).join("/")
|
36
|
+
"https://github.com/primer/view_components/tree/main/app/components/#{path}.rb"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def lookbook_url
|
41
|
+
@lookbook_url ||= begin
|
42
|
+
path = klass.name.underscore.gsub("_component", "")
|
43
|
+
"https://ariadne.style/view-components/lookbook/inspect/#{path}/default/"
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
# :nocov:
|
@@ -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:
|