ariadne_view_components 0.0.93.1 → 0.0.94
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +9 -0
- data/README.md +13 -4
- data/app/assets/javascripts/ariadne_view_components.js +14 -14
- 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 -1
- 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 +25 -22
- data/app/components/ariadne/behaviors/tooltipable.rb +12 -12
- data/app/components/ariadne/form/checkbox/component.rb +2 -2
- data/app/components/ariadne/form/group/component.rb +1 -1
- data/app/components/ariadne/form/radio_button/component.rb +2 -2
- data/app/components/ariadne/form/select/component.rb +1 -1
- data/app/components/ariadne/form/text_field/component.html.erb +2 -2
- data/app/components/ariadne/form/text_field/component.rb +14 -7
- data/app/components/ariadne/form/toggle/component.rb +2 -2
- data/app/components/ariadne/form/toggle_group/component.rb +1 -1
- data/app/components/ariadne/form/toggle_group/option/component.rb +1 -1
- data/app/components/ariadne/layout/grid/component.rb +1 -1
- data/app/components/ariadne/layout/grid/item/component.rb +2 -2
- data/app/components/ariadne/layout/label_block/component.rb +1 -1
- data/app/components/ariadne/layout/narrow/component.rb +1 -1
- data/app/components/ariadne/ui/accordion/component.rb +3 -1
- data/app/components/ariadne/ui/accordion/item/component.html.erb +10 -10
- data/app/components/ariadne/ui/accordion/item/component.rb +12 -3
- data/app/components/ariadne/ui/avatar/component.html.erb +9 -7
- data/app/components/ariadne/ui/avatar/component.rb +55 -7
- data/app/components/ariadne/ui/badge/component.rb +35 -16
- data/app/components/ariadne/ui/banner/component.html.erb +23 -0
- data/app/components/ariadne/ui/banner/component.rb +226 -0
- data/app/components/ariadne/ui/banner/component.ts +46 -0
- data/app/components/ariadne/ui/blankslate/component.html.erb +2 -2
- data/app/components/ariadne/ui/blankslate/component.rb +12 -1
- data/app/components/ariadne/ui/button/component.rb +35 -24
- data/app/components/ariadne/ui/card/body/component.rb +1 -1
- data/app/components/ariadne/ui/card/component.rb +11 -7
- data/app/components/ariadne/ui/card/footer/component.rb +1 -1
- data/app/components/ariadne/ui/card/header/component.html.erb +2 -2
- data/app/components/ariadne/ui/card/header/component.rb +25 -16
- data/app/components/ariadne/ui/clipboard_copy/component.html.erb +1 -0
- data/app/components/ariadne/ui/clipboard_copy/component.rb +17 -21
- data/app/components/ariadne/ui/clipboard_copy/component.ts +15 -0
- data/app/components/ariadne/ui/color_dot/component.html.erb +5 -5
- data/app/components/ariadne/ui/color_dot/component.rb +19 -4
- data/app/components/ariadne/ui/combobox/component.html.erb +1 -1
- data/app/components/ariadne/ui/combobox/component.rb +54 -23
- data/app/components/ariadne/ui/combobox/component.ts +2 -0
- data/app/components/ariadne/ui/dialog/body/component.html.erb +3 -0
- data/app/components/ariadne/ui/dialog/body/component.rb +28 -0
- data/app/components/ariadne/ui/dialog/component.html.erb +25 -24
- data/app/components/ariadne/ui/dialog/component.rb +87 -18
- data/app/components/ariadne/ui/dialog/component.ts +5 -1
- data/app/components/ariadne/ui/dialog/footer/component.html.erb +3 -0
- data/app/components/ariadne/ui/dialog/footer/component.rb +34 -0
- data/app/components/ariadne/ui/heroicon/component.rb +21 -21
- data/app/components/ariadne/ui/image/component.rb +11 -23
- data/app/components/ariadne/ui/link/component.html.erb +1 -3
- data/app/components/ariadne/ui/link/component.rb +17 -4
- data/app/components/ariadne/ui/list/component.html.erb +5 -9
- data/app/components/ariadne/ui/list/component.rb +31 -7
- data/app/components/ariadne/ui/list/item/component.rb +6 -5
- data/app/components/ariadne/ui/pagination/component.rb +1 -2
- data/app/components/ariadne/ui/popover/component.html.erb +1 -1
- data/app/components/ariadne/ui/popover/component.rb +31 -26
- data/app/components/ariadne/ui/relative_time/component.html.erb +1 -0
- data/app/components/ariadne/ui/{time_ago → relative_time}/component.rb +15 -15
- data/app/components/ariadne/ui/{time_ago → relative_time}/component.ts +1 -1
- data/app/components/ariadne/ui/shortcut/component.html.erb +0 -1
- data/app/components/ariadne/ui/shortcut/component.rb +31 -5
- data/app/components/ariadne/ui/shortcut/component.ts +1 -1
- data/app/components/ariadne/ui/skeleton/component.rb +2 -8
- data/app/components/ariadne/ui/stats_panel/component.html.erb +3 -3
- data/app/components/ariadne/ui/stats_panel/component.rb +25 -1
- data/app/components/ariadne/ui/stats_panel/item/component.html.erb +3 -3
- data/app/components/ariadne/ui/stats_panel/item/component.rb +6 -6
- data/app/components/ariadne/ui/table/cell/component.rb +1 -1
- data/app/components/ariadne/ui/table/row/component.rb +1 -1
- data/app/components/ariadne/ui/typography/component.rb +3 -1
- data/app/frontend/controllers/tooltip_controller.ts +8 -3
- data/app/frontend/stylesheets/ariadne_view_components.css +1 -0
- data/app/frontend/stylesheets/theme.css +88 -0
- data/app/frontend/utils/createController.ts +9 -0
- data/app/helpers/ariadne/color_helper.rb +158 -0
- data/app/helpers/ariadne/form_helper.rb +1 -0
- data/app/helpers/ariadne/size_helper.rb +7 -0
- data/app/lib/ariadne/attributes_helper.rb +4 -4
- data/app/lib/ariadne/view_component/style_variants.rb +1 -1
- data/app/lib/ariadne/view_helper.rb +0 -6
- data/lib/ariadne/accessibility.rb +64 -0
- data/lib/ariadne/forms/dsl/form_object.rb +5 -1
- data/lib/ariadne/forms/dsl/input.rb +1 -1
- data/lib/ariadne/static/generate_arguments.rb +54 -0
- data/lib/ariadne/static/generate_audited_at.rb +17 -0
- data/lib/ariadne/static/generate_constants.rb +19 -0
- data/lib/ariadne/static/generate_previews.rb +53 -0
- data/lib/ariadne/static/generate_statuses.rb +17 -0
- data/lib/ariadne/static/generate_structure.rb +279 -0
- data/lib/ariadne/static.rb +68 -0
- data/lib/ariadne/view_components/constants.rb +2 -2
- data/lib/ariadne/view_components/version.rb +1 -1
- data/lib/ariadne/view_components.rb +0 -51
- data/lib/ariadne/yard/component_manifest.rb +81 -81
- data/lib/ariadne/yard/component_ref.rb +1 -1
- data/lib/ariadne/yard/docs_helper.rb +24 -16
- data/lib/ariadne/yard/dry_initializer/common_handler.rb +103 -0
- data/lib/ariadne/yard/dry_initializer/option_handler.rb +38 -0
- data/lib/ariadne/yard/dry_initializer/param_handler.rb +57 -0
- data/lib/ariadne/yard/registry.rb +2 -5
- data/lib/ariadne/yard/{info_arch_docs_helper.rb → structure_docs_helper.rb} +5 -5
- data/lib/ariadne/yard.rb +20 -8
- data/lib/rubocop/config/default.yml +0 -3
- metadata +34 -37
- data/app/components/ariadne/behaviors/captionable.rb +0 -55
- data/app/components/ariadne/turbo/frame/component.html.erb +0 -3
- data/app/components/ariadne/turbo/frame/component.rb +0 -16
- data/app/components/ariadne/turbo/stream_action/component.html.erb +0 -4
- data/app/components/ariadne/turbo/stream_action/component.rb +0 -25
- data/app/components/ariadne/ui/data_table/component.html.erb +0 -1
- data/app/components/ariadne/ui/data_table/component.rb +0 -11
- data/app/components/ariadne/ui/flash/component.html.erb +0 -18
- data/app/components/ariadne/ui/flash/component.rb +0 -151
- data/app/components/ariadne/ui/flash/component.ts +0 -56
- data/app/components/ariadne/ui/overlay/component.html.erb +0 -12
- data/app/components/ariadne/ui/overlay/component.rb +0 -54
- data/app/components/ariadne/ui/overlay/component.ts +0 -92
- data/app/components/ariadne/ui/time_ago/component.html.erb +0 -1
- data/lib/ariadne/view_components/commands.rb +0 -90
- data/lib/ariadne/view_components/statuses.rb +0 -14
- data/lib/ariadne/view_components/upstream.rb +0 -19
- data/lib/ariadne/yard/lookbook_pages_backend.rb +0 -235
- data/lib/rubocop/cop/ariadne/no_tag_memoize.rb +0 -44
- data/static/arguments.yml +0 -879
- data/static/assets/view-components.svg +0 -18
- data/static/classes.yml +0 -211
- data/static/constants.json +0 -743
- data/static/statuses.json +0 -58
- data/static/tailwindcss.yml +0 -727
- /data/app/components/ariadne/ui/{time_ago → relative_time}/en.yml +0 -0
| @@ -0,0 +1,279 @@ | |
| 1 | 
            +
            # frozen_string_literal: true
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            # :nocov:
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            require "json"
         | 
| 6 | 
            +
             | 
| 7 | 
            +
            module Ariadne
         | 
| 8 | 
            +
              module Static
         | 
| 9 | 
            +
                # :nodoc:
         | 
| 10 | 
            +
                module GenerateStructure
         | 
| 11 | 
            +
                  SKIP_METHODS = [:call, :before_render].freeze
         | 
| 12 | 
            +
             | 
| 13 | 
            +
                  # This class generates the JSON structure for the Ariadne documentation.
         | 
| 14 | 
            +
                  class << self
         | 
| 15 | 
            +
                    def call
         | 
| 16 | 
            +
                      components = Ariadne::BaseComponent.descendants.sort_by(&:name) - [Ariadne::BaseComponent]
         | 
| 17 | 
            +
             | 
| 18 | 
            +
                      component_docs = components.each_with_object({}) do |component, memo|
         | 
| 19 | 
            +
                        docs = registry.find(component)
         | 
| 20 | 
            +
             | 
| 21 | 
            +
                        preview_data = previews.find do |preview|
         | 
| 22 | 
            +
                          preview["component"] == docs.metadata[:title]
         | 
| 23 | 
            +
                        end
         | 
| 24 | 
            +
             | 
| 25 | 
            +
                        arg_data = args.find do |component_args|
         | 
| 26 | 
            +
                          component_args["component"] == docs.metadata[:title]
         | 
| 27 | 
            +
                        end
         | 
| 28 | 
            +
             | 
| 29 | 
            +
                        slot_docs = docs.slot_methods.map do |slot_method|
         | 
| 30 | 
            +
                          param_tags = slot_method.tags(:param)
         | 
| 31 | 
            +
             | 
| 32 | 
            +
                          description = if slot_method.base_docstring.to_s.present?
         | 
| 33 | 
            +
                            render_erb_ignoring_markdown_code_fences(slot_method.base_docstring).force_encoding("UTF-8")
         | 
| 34 | 
            +
                          else
         | 
| 35 | 
            +
                            ""
         | 
| 36 | 
            +
                          end
         | 
| 37 | 
            +
             | 
| 38 | 
            +
                          {
         | 
| 39 | 
            +
                            "name" => slot_method.name,
         | 
| 40 | 
            +
                            "description" => description,
         | 
| 41 | 
            +
                            "parameters" => serialize_params(param_tags, component),
         | 
| 42 | 
            +
                          }
         | 
| 43 | 
            +
                        end
         | 
| 44 | 
            +
             | 
| 45 | 
            +
                        mtds = docs.non_slot_methods.select do |mtd|
         | 
| 46 | 
            +
                          next false if mtd.base_docstring.to_s.blank?
         | 
| 47 | 
            +
                          next false if SKIP_METHODS.include?(mtd.name)
         | 
| 48 | 
            +
             | 
| 49 | 
            +
                          method_location, = mtd.files.first
         | 
| 50 | 
            +
                          class_location, = docs.docs.files.first
         | 
| 51 | 
            +
             | 
| 52 | 
            +
                          method_location == class_location
         | 
| 53 | 
            +
                        end
         | 
| 54 | 
            +
             | 
| 55 | 
            +
                        method_docs = mtds.map do |mtd|
         | 
| 56 | 
            +
                          param_tags = mtd.tags(:param)
         | 
| 57 | 
            +
             | 
| 58 | 
            +
                          {
         | 
| 59 | 
            +
                            "name" => mtd.name,
         | 
| 60 | 
            +
                            "description" => render_erb_ignoring_markdown_code_fences(mtd.base_docstring),
         | 
| 61 | 
            +
                            "parameters" => serialize_params(param_tags, component),
         | 
| 62 | 
            +
                          }
         | 
| 63 | 
            +
                        end
         | 
| 64 | 
            +
             | 
| 65 | 
            +
                        description =
         | 
| 66 | 
            +
                          if component == Ariadne::BaseComponent
         | 
| 67 | 
            +
                            docs.base_docstring
         | 
| 68 | 
            +
                          else
         | 
| 69 | 
            +
                            render_erb_ignoring_markdown_code_fences(docs.base_docstring)
         | 
| 70 | 
            +
                          end
         | 
| 71 | 
            +
             | 
| 72 | 
            +
                        accessibility_docs =
         | 
| 73 | 
            +
                          if (accessibility_tag_text = docs.tags(:accessibility)&.first&.text)
         | 
| 74 | 
            +
                            render_erb_ignoring_markdown_code_fences(accessibility_tag_text)
         | 
| 75 | 
            +
                          end
         | 
| 76 | 
            +
             | 
| 77 | 
            +
                        behavior_docs =
         | 
| 78 | 
            +
                          if (behavior_tag_text = docs.tags(:behaviors)&.first&.text)
         | 
| 79 | 
            +
                            render_erb_ignoring_markdown_code_fences(behavior_tag_text)
         | 
| 80 | 
            +
                          end
         | 
| 81 | 
            +
             | 
| 82 | 
            +
                        memo[component.name] = {
         | 
| 83 | 
            +
                          "fully_qualified_name" => component.name,
         | 
| 84 | 
            +
                          "description" => description,
         | 
| 85 | 
            +
                          "accessibility_docs" => accessibility_docs,
         | 
| 86 | 
            +
                          "behavior_docs" => behavior_docs,
         | 
| 87 | 
            +
                          "is_form_component" => docs.manifest_entry.form_component?,
         | 
| 88 | 
            +
                          "requires_js" => docs.manifest_entry.requires_js?,
         | 
| 89 | 
            +
                          **arg_data,
         | 
| 90 | 
            +
                          "slots" => slot_docs,
         | 
| 91 | 
            +
                          "methods" => method_docs,
         | 
| 92 | 
            +
                          "previews" => (preview_data || {}).fetch("examples", []),
         | 
| 93 | 
            +
                          "subcomponents" => [],
         | 
| 94 | 
            +
                        }
         | 
| 95 | 
            +
                      end
         | 
| 96 | 
            +
             | 
| 97 | 
            +
                      Ariadne::BaseComponent.descendants.sort_by(&:name).each do |component|
         | 
| 98 | 
            +
                        fq_class = component.name.to_s.split("::")
         | 
| 99 | 
            +
                        fq_class.shift # remove Ariadne::
         | 
| 100 | 
            +
                        type = fq_class.shift # remove {UI,Form,*}::
         | 
| 101 | 
            +
             | 
| 102 | 
            +
                        parent, *child = *fq_class
         | 
| 103 | 
            +
             | 
| 104 | 
            +
                        next if child.empty? || child.length < 2
         | 
| 105 | 
            +
             | 
| 106 | 
            +
                        parent_class = "Ariadne::#{type}".constantize
         | 
| 107 | 
            +
                        parent_class = parent_class.const_get(parent)
         | 
| 108 | 
            +
             | 
| 109 | 
            +
                        parent_docs = component_docs["#{parent_class}::Component"]
         | 
| 110 | 
            +
                        next unless parent_docs
         | 
| 111 | 
            +
             | 
| 112 | 
            +
                        if (child_docs = component_docs.delete(component.name))
         | 
| 113 | 
            +
                          parent_docs["subcomponents"] << child_docs
         | 
| 114 | 
            +
                        end
         | 
| 115 | 
            +
                      end
         | 
| 116 | 
            +
             | 
| 117 | 
            +
                      toc_categories = {
         | 
| 118 | 
            +
                        "UI" => [],
         | 
| 119 | 
            +
                        "Form" => [],
         | 
| 120 | 
            +
                        "Layout" => [],
         | 
| 121 | 
            +
                        "Behaviors" => [],
         | 
| 122 | 
            +
                      }
         | 
| 123 | 
            +
             | 
| 124 | 
            +
                      component_docs.values.each do |component|
         | 
| 125 | 
            +
                        type, name = component["short_name"].split("::", 2)
         | 
| 126 | 
            +
                        next unless toc_categories[type] # not a required category
         | 
| 127 | 
            +
             | 
| 128 | 
            +
                        # removes children from toc, like `Ariadne::UI::Accordion::Item`,
         | 
| 129 | 
            +
                        # by not adding the component to the TOC if it has more than one level of nesting
         | 
| 130 | 
            +
                        next if name.include?("::")
         | 
| 131 | 
            +
             | 
| 132 | 
            +
                        slug = component["short_name"].gsub("::", "/").downcase
         | 
| 133 | 
            +
             | 
| 134 | 
            +
                        toc_categories[type] << {
         | 
| 135 | 
            +
                          "name" => name,
         | 
| 136 | 
            +
                          "slug" => slug,
         | 
| 137 | 
            +
                        }
         | 
| 138 | 
            +
             | 
| 139 | 
            +
                        File.open(File.join(DEFAULT_STATIC_PATH, FILE_NAMES[:toc]), "w") do |f|
         | 
| 140 | 
            +
                          f.write(JSON.pretty_generate(toc_categories))
         | 
| 141 | 
            +
                          f.write($INPUT_RECORD_SEPARATOR)
         | 
| 142 | 
            +
                        end
         | 
| 143 | 
            +
                      end
         | 
| 144 | 
            +
                      component_docs.values
         | 
| 145 | 
            +
                    end
         | 
| 146 | 
            +
             | 
| 147 | 
            +
                    def serialize_params(param_tags, component)
         | 
| 148 | 
            +
                      param_tags.map do |tag|
         | 
| 149 | 
            +
                        default_value = Ariadne::Yard::DocsHelper.pretty_default_value(tag, component)
         | 
| 150 | 
            +
             | 
| 151 | 
            +
                        {
         | 
| 152 | 
            +
                          "name" => tag.name,
         | 
| 153 | 
            +
                          "type" => tag.types&.join(", ") || "",
         | 
| 154 | 
            +
                          "default" => default_value,
         | 
| 155 | 
            +
                          "description" => render_erb_ignoring_markdown_code_fences(tag.text.squish),
         | 
| 156 | 
            +
                        }
         | 
| 157 | 
            +
                      end
         | 
| 158 | 
            +
                    end
         | 
| 159 | 
            +
             | 
| 160 | 
            +
                    def previews
         | 
| 161 | 
            +
                      @previews ||= JSON.parse(Static.read(:previews))
         | 
| 162 | 
            +
                    end
         | 
| 163 | 
            +
             | 
| 164 | 
            +
                    def args
         | 
| 165 | 
            +
                      @args ||= Ariadne::Static::GenerateArguments.call(view_context: view_context)
         | 
| 166 | 
            +
                    end
         | 
| 167 | 
            +
             | 
| 168 | 
            +
                    def view_context
         | 
| 169 | 
            +
                      @view_context ||= ApplicationController.new.tap { |c| c.request = ActionDispatch::TestRequest.create }.view_context.tap do |vc|
         | 
| 170 | 
            +
                        vc.singleton_class.include(Ariadne::Yard::StructureDocsHelper)
         | 
| 171 | 
            +
                        vc.singleton_class.include(Ariadne::ViewHelper)
         | 
| 172 | 
            +
                      end
         | 
| 173 | 
            +
                    end
         | 
| 174 | 
            +
             | 
| 175 | 
            +
                    def generate_args_table(args)
         | 
| 176 | 
            +
                      rows = args.map do |arg|
         | 
| 177 | 
            +
                        parts = [
         | 
| 178 | 
            +
                          "`#{arg.name}`",
         | 
| 179 | 
            +
                          arg.type,
         | 
| 180 | 
            +
                          arg.description.squish,
         | 
| 181 | 
            +
                        ]
         | 
| 182 | 
            +
             | 
| 183 | 
            +
                        "| #{parts.join(" | ")} |"
         | 
| 184 | 
            +
                      end
         | 
| 185 | 
            +
             | 
| 186 | 
            +
                      <<~MARKDOWN
         | 
| 187 | 
            +
                        | Name | Type | Description |
         | 
| 188 | 
            +
                        | :- | :- | :- |
         | 
| 189 | 
            +
                        #{rows.join("\n")}
         | 
| 190 | 
            +
                      MARKDOWN
         | 
| 191 | 
            +
                    end
         | 
| 192 | 
            +
             | 
| 193 | 
            +
                    # Renders ERB code to a string, ignoring markdown code fences. For example, consider the
         | 
| 194 | 
            +
                    # following ERB code inside a markdown document:
         | 
| 195 | 
            +
                    #
         | 
| 196 | 
            +
                    # ### Heading
         | 
| 197 | 
            +
                    # ```erb
         | 
| 198 | 
            +
                    # <%= render(SomeComponent.new) %>
         | 
| 199 | 
            +
                    # ```
         | 
| 200 | 
            +
                    #
         | 
| 201 | 
            +
                    # <%= some_func(a, b) %>
         | 
| 202 | 
            +
                    #
         | 
| 203 | 
            +
                    # The ERB renderer does not understand that the fenced code, i.e. the part inside the triple
         | 
| 204 | 
            +
                    # backticks, should not be rendered. It sees the ERB tags both inside and outside the fence
         | 
| 205 | 
            +
                    # and renders them both.
         | 
| 206 | 
            +
                    #
         | 
| 207 | 
            +
                    # This method renders ERB tags in a markdown string, ignoring any fenced code blocks, so as
         | 
| 208 | 
            +
                    # to prevent rendering fenced ERB code.
         | 
| 209 | 
            +
                    #
         | 
| 210 | 
            +
                    def render_erb_ignoring_markdown_code_fences(markdown_str)
         | 
| 211 | 
            +
                      return view_context.render(inline: markdown_str) if markdown_str.exclude?("```")
         | 
| 212 | 
            +
             | 
| 213 | 
            +
                      # identify all fenced code blocks in markdown string
         | 
| 214 | 
            +
                      code_ranges = find_fenced_code_ranges_in(markdown_str)
         | 
| 215 | 
            +
             | 
| 216 | 
            +
                      # replace code fences with placeholders
         | 
| 217 | 
            +
                      de_fenced_markdown_str = markdown_str.dup.tap do |memo|
         | 
| 218 | 
            +
                        code_ranges.reverse_each.with_index do |code_range, idx|
         | 
| 219 | 
            +
                          memo[code_range] = "<!--codefence#{idx}-->"
         | 
| 220 | 
            +
                        end
         | 
| 221 | 
            +
                      end
         | 
| 222 | 
            +
             | 
| 223 | 
            +
                      # Render ERB tags. The only ones left will explicitly exist _outside_ markdown code fences.
         | 
| 224 | 
            +
                      rendered_str = view_context.render(inline: de_fenced_markdown_str)
         | 
| 225 | 
            +
             | 
| 226 | 
            +
                      # replace placeholders with original code fences
         | 
| 227 | 
            +
                      code_ranges.reverse_each.with_index do |code_range, idx|
         | 
| 228 | 
            +
                        rendered_str.sub!("<!--codefence#{idx}-->", markdown_str[code_range])
         | 
| 229 | 
            +
                      end
         | 
| 230 | 
            +
             | 
| 231 | 
            +
                      rendered_str
         | 
| 232 | 
            +
                    end
         | 
| 233 | 
            +
             | 
| 234 | 
            +
                    def find_fenced_code_ranges_in(str)
         | 
| 235 | 
            +
                      doc = Kramdown::Document.new(str)
         | 
| 236 | 
            +
                      line_starts = find_line_starts_in(str)
         | 
| 237 | 
            +
             | 
| 238 | 
            +
                      [].tap do |code_ranges|
         | 
| 239 | 
            +
                        each_codespan_in(doc.root) do |node|
         | 
| 240 | 
            +
                          options = node.options
         | 
| 241 | 
            +
                          delimiter = options[:codespan_delimiter]
         | 
| 242 | 
            +
                          next unless delimiter.start_with?("```")
         | 
| 243 | 
            +
             | 
| 244 | 
            +
                          start_pos = line_starts[options[:location]]
         | 
| 245 | 
            +
                          end_pos = start_pos + node.value.size + delimiter.size
         | 
| 246 | 
            +
                          end_pos = str.index("```", end_pos) + 3
         | 
| 247 | 
            +
             | 
| 248 | 
            +
                          code_ranges << (start_pos...end_pos)
         | 
| 249 | 
            +
                        end
         | 
| 250 | 
            +
                      end
         | 
| 251 | 
            +
                    end
         | 
| 252 | 
            +
             | 
| 253 | 
            +
                    def find_line_starts_in(str)
         | 
| 254 | 
            +
                      line_counter = 2
         | 
| 255 | 
            +
             | 
| 256 | 
            +
                      { 1 => 0 }.tap do |memo|
         | 
| 257 | 
            +
                        str.scan(/\r?\n/) do
         | 
| 258 | 
            +
                          memo[line_counter] = Regexp.last_match.end(0)
         | 
| 259 | 
            +
                          line_counter += 1
         | 
| 260 | 
            +
                        end
         | 
| 261 | 
            +
                      end
         | 
| 262 | 
            +
                    end
         | 
| 263 | 
            +
             | 
| 264 | 
            +
                    def each_codespan_in(node, &block)
         | 
| 265 | 
            +
                      return unless node.respond_to?(:children)
         | 
| 266 | 
            +
             | 
| 267 | 
            +
                      node.children.each do |child|
         | 
| 268 | 
            +
                        yield child if child.type == :codespan
         | 
| 269 | 
            +
                        each_codespan_in(child, &block)
         | 
| 270 | 
            +
                      end
         | 
| 271 | 
            +
                    end
         | 
| 272 | 
            +
             | 
| 273 | 
            +
                    def registry
         | 
| 274 | 
            +
                      @registry ||= Ariadne::Yard::Registry.make
         | 
| 275 | 
            +
                    end
         | 
| 276 | 
            +
                  end
         | 
| 277 | 
            +
                end
         | 
| 278 | 
            +
              end
         | 
| 279 | 
            +
            end
         | 
| @@ -0,0 +1,68 @@ | |
| 1 | 
            +
            # frozen_string_literal: true
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            # :nocov:
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            require "json"
         | 
| 6 | 
            +
             | 
| 7 | 
            +
            module Ariadne
         | 
| 8 | 
            +
              # :nodoc:
         | 
| 9 | 
            +
              module Static
         | 
| 10 | 
            +
                DEFAULT_STATIC_PATH = File.join("docs", "src", "_data", "ariadne_view_components").freeze
         | 
| 11 | 
            +
             | 
| 12 | 
            +
                FILE_NAMES = {
         | 
| 13 | 
            +
                  constants: "constants.json",
         | 
| 14 | 
            +
                  audited_at: "audited_at.json",
         | 
| 15 | 
            +
                  arguments: "arguments.json",
         | 
| 16 | 
            +
                  previews: "previews.json",
         | 
| 17 | 
            +
                  structure: "structure.json",
         | 
| 18 | 
            +
                  toc: "toc.json",
         | 
| 19 | 
            +
                }.freeze
         | 
| 20 | 
            +
             | 
| 21 | 
            +
                class << self
         | 
| 22 | 
            +
                  # Returns a hash mapping component names to an array of the constants defined inside
         | 
| 23 | 
            +
                  # the component's class.
         | 
| 24 | 
            +
                  def generate_constants
         | 
| 25 | 
            +
                    Static::GenerateConstants.call
         | 
| 26 | 
            +
                  end
         | 
| 27 | 
            +
             | 
| 28 | 
            +
                  # Returns a hash mapping component names to the date on which the component passed
         | 
| 29 | 
            +
                  # an accessibility audit.
         | 
| 30 | 
            +
                  def generate_audited_at
         | 
| 31 | 
            +
                    Static::GenerateAuditedAt.call
         | 
| 32 | 
            +
                  end
         | 
| 33 | 
            +
             | 
| 34 | 
            +
                  # Returns an array of hashes, one per Ariadne component, that contains some metadata and
         | 
| 35 | 
            +
                  # a list of the arguments accepted by the component's constructor. Arguments are enumerated
         | 
| 36 | 
            +
                  # with their value, data type, and docstring.
         | 
| 37 | 
            +
                  def generate_arguments
         | 
| 38 | 
            +
                    Static::GenerateArguments.call
         | 
| 39 | 
            +
                  end
         | 
| 40 | 
            +
             | 
| 41 | 
            +
                  # Returns an array of hashes, one per Ariadne component, that contains some metadata and
         | 
| 42 | 
            +
                  # an array of all the component's previews. The preview data contains the Lookbook URL
         | 
| 43 | 
            +
                  # to each preview and its name.
         | 
| 44 | 
            +
                  def generate_previews
         | 
| 45 | 
            +
                    Static::GeneratePreviews.call
         | 
| 46 | 
            +
                  end
         | 
| 47 | 
            +
             | 
| 48 | 
            +
                  # Returns an array of hashes, one per Ariadne component, that contains all the data needed
         | 
| 49 | 
            +
                  # for the new primer.style docsite.
         | 
| 50 | 
            +
                  def generate_structure
         | 
| 51 | 
            +
                    Static::GenerateStructure.call
         | 
| 52 | 
            +
                  end
         | 
| 53 | 
            +
             | 
| 54 | 
            +
                  # Generates the requested stat hash and outputs it to a file.
         | 
| 55 | 
            +
                  def dump(stats)
         | 
| 56 | 
            +
                    File.open(File.join(DEFAULT_STATIC_PATH, FILE_NAMES[stats]), "w") do |f|
         | 
| 57 | 
            +
                      f.write(JSON.pretty_generate(send(:"generate_#{stats}")))
         | 
| 58 | 
            +
                      f.write($INPUT_RECORD_SEPARATOR)
         | 
| 59 | 
            +
                    end
         | 
| 60 | 
            +
                  end
         | 
| 61 | 
            +
             | 
| 62 | 
            +
                  # Returns the contents of the stat file.
         | 
| 63 | 
            +
                  def read(stats)
         | 
| 64 | 
            +
                    File.read(File.join(DEFAULT_STATIC_PATH, FILE_NAMES[stats]))
         | 
| 65 | 
            +
                  end
         | 
| 66 | 
            +
                end
         | 
| 67 | 
            +
              end
         | 
| 68 | 
            +
            end
         | 
| @@ -8,7 +8,7 @@ module Ariadne | |
| 8 8 | 
             
                class Constants
         | 
| 9 9 | 
             
                  CONSTANTS = JSON.parse(
         | 
| 10 10 | 
             
                    File.read(
         | 
| 11 | 
            -
                      File.join(File.dirname(__FILE__), "../../../ | 
| 11 | 
            +
                      File.join(File.dirname(__FILE__), "../../../docs/src/_data/ariadne_view_components/constants.json"),
         | 
| 12 12 | 
             
                    ),
         | 
| 13 13 | 
             
                  ).freeze
         | 
| 14 14 |  | 
| @@ -37,7 +37,7 @@ module Ariadne | |
| 37 37 | 
             
                    end
         | 
| 38 38 |  | 
| 39 39 | 
             
                    private def format_array(values, symbolize)
         | 
| 40 | 
            -
                      val = values. | 
| 40 | 
            +
                      val = values.compact_blank
         | 
| 41 41 |  | 
| 42 42 | 
             
                      return val.map { |v| symbolize_value(v) } if symbolize
         | 
| 43 43 |  | 
| @@ -2,60 +2,9 @@ | |
| 2 2 |  | 
| 3 3 | 
             
            require "ariadne/view_components/version"
         | 
| 4 4 | 
             
            require "ariadne/view_components/engine"
         | 
| 5 | 
            -
            require "ariadne/view_components/constants"
         | 
| 6 | 
            -
            require "ariadne/view_components/commands"
         | 
| 7 5 |  | 
| 8 6 | 
             
            module Ariadne
         | 
| 9 7 | 
             
              # :nodoc:
         | 
| 10 8 | 
             
              module ViewComponents
         | 
| 11 | 
            -
                DEFAULT_STATIC_PATH = File.expand_path("static")
         | 
| 12 | 
            -
                FILE_NAMES = {
         | 
| 13 | 
            -
                  statuses: "statuses.json",
         | 
| 14 | 
            -
                  constants: "constants.json",
         | 
| 15 | 
            -
                  audited_at: "audited_at.json",
         | 
| 16 | 
            -
                }.freeze
         | 
| 17 | 
            -
             | 
| 18 | 
            -
                class << self
         | 
| 19 | 
            -
                  # generate_statuses returns a hash mapping component name to
         | 
| 20 | 
            -
                  # the component's status sorted alphabetically by the component name.
         | 
| 21 | 
            -
                  def generate_statuses
         | 
| 22 | 
            -
                    Ariadne::Component.descendants.sort_by(&:name).each_with_object({}) do |component, mem|
         | 
| 23 | 
            -
                      mem[component.to_s] = component.status.to_s
         | 
| 24 | 
            -
                    end
         | 
| 25 | 
            -
                  end
         | 
| 26 | 
            -
             | 
| 27 | 
            -
                  # generate_audited_at returns a hash mapping component name to
         | 
| 28 | 
            -
                  # the day the component has passed an accessibility audit.
         | 
| 29 | 
            -
                  def generate_audited_at
         | 
| 30 | 
            -
                    Ariadne::Component.descendants.sort_by(&:name).each_with_object({}) do |component, mem|
         | 
| 31 | 
            -
                      mem[component.to_s] = component.audited_at.to_s
         | 
| 32 | 
            -
                    end
         | 
| 33 | 
            -
                  end
         | 
| 34 | 
            -
             | 
| 35 | 
            -
                  # generate_constants returns a hash mapping component name to
         | 
| 36 | 
            -
                  # all of its constants.
         | 
| 37 | 
            -
                  def generate_constants
         | 
| 38 | 
            -
                    Ariadne::Component.descendants.sort_by(&:name).each_with_object({}) do |component, mem|
         | 
| 39 | 
            -
                      mem[component.to_s] = component.constants(false).sort.index_with do |constant|
         | 
| 40 | 
            -
                        component.const_get(constant)
         | 
| 41 | 
            -
                      end
         | 
| 42 | 
            -
                    end
         | 
| 43 | 
            -
                  end
         | 
| 44 | 
            -
             | 
| 45 | 
            -
                  # dump generates the requested stat hash and outputs it to a file.
         | 
| 46 | 
            -
                  def dump(stats)
         | 
| 47 | 
            -
                    require "json"
         | 
| 48 | 
            -
             | 
| 49 | 
            -
                    File.open(File.join(DEFAULT_STATIC_PATH, FILE_NAMES[stats]), "w") do |f|
         | 
| 50 | 
            -
                      f.write(JSON.pretty_generate(send(:"generate_#{stats}")))
         | 
| 51 | 
            -
                      f.write($INPUT_RECORD_SEPARATOR)
         | 
| 52 | 
            -
                    end
         | 
| 53 | 
            -
                  end
         | 
| 54 | 
            -
             | 
| 55 | 
            -
                  # read returns a JSON string matching the output of the corresponding stat.
         | 
| 56 | 
            -
                  def read(stats)
         | 
| 57 | 
            -
                    File.read(File.join(DEFAULT_STATIC_PATH, FILE_NAMES[stats]))
         | 
| 58 | 
            -
                  end
         | 
| 59 | 
            -
                end
         | 
| 60 9 | 
             
              end
         | 
| 61 10 | 
             
            end
         | 
| @@ -6,95 +6,95 @@ module Ariadne | |
| 6 6 | 
             
                # The set of documented components (and associated metadata).
         | 
| 7 7 | 
             
                class ComponentManifest
         | 
| 8 8 | 
             
                  COMPONENTS = {
         | 
| 9 | 
            -
                    Ariadne:: | 
| 10 | 
            -
                    #  | 
| 11 | 
            -
                    #  | 
| 12 | 
            -
                    #  | 
| 13 | 
            -
                    #  | 
| 14 | 
            -
                    #  | 
| 15 | 
            -
                    #  | 
| 16 | 
            -
                    #  | 
| 17 | 
            -
                    #  | 
| 18 | 
            -
                    #  | 
| 19 | 
            -
                    #  | 
| 20 | 
            -
                    #  | 
| 21 | 
            -
                    #  | 
| 22 | 
            -
                    #  | 
| 23 | 
            -
                    #  | 
| 24 | 
            -
                    #  | 
| 25 | 
            -
                    #  | 
| 26 | 
            -
                    #  | 
| 27 | 
            -
                    #  | 
| 28 | 
            -
                    #  | 
| 29 | 
            -
                    #  | 
| 30 | 
            -
                    #  | 
| 31 | 
            -
                    #  | 
| 32 | 
            -
                    #  | 
| 33 | 
            -
                    #  | 
| 34 | 
            -
                     | 
| 35 | 
            -
                    #  | 
| 36 | 
            -
                    #  | 
| 37 | 
            -
                    #  | 
| 38 | 
            -
                    #  | 
| 39 | 
            -
                    #  | 
| 40 | 
            -
                    #  | 
| 41 | 
            -
                    #  | 
| 42 | 
            -
                    #  | 
| 43 | 
            -
                    #  | 
| 44 | 
            -
                    #  | 
| 45 | 
            -
                    #  | 
| 46 | 
            -
                    #  | 
| 47 | 
            -
                    #  | 
| 48 | 
            -
                    #  | 
| 49 | 
            -
                    #  | 
| 50 | 
            -
                    #  | 
| 51 | 
            -
                    #  | 
| 52 | 
            -
                    #  | 
| 53 | 
            -
                    #  | 
| 54 | 
            -
                    #  | 
| 55 | 
            -
                    #  | 
| 56 | 
            -
                    #  | 
| 57 | 
            -
                    #  | 
| 58 | 
            -
                    #  | 
| 59 | 
            -
                    #  | 
| 60 | 
            -
                    #  | 
| 61 | 
            -
                    #  | 
| 62 | 
            -
                    #  | 
| 63 | 
            -
                    #  | 
| 64 | 
            -
                    #  | 
| 65 | 
            -
                    #  | 
| 66 | 
            -
                    #  | 
| 67 | 
            -
                    #  | 
| 68 | 
            -
                    #  | 
| 69 | 
            -
                    #  | 
| 9 | 
            +
                    Ariadne::UI::Typography::Component => {},
         | 
| 10 | 
            +
                    # Ariadne::Beta::IconButton => {},
         | 
| 11 | 
            +
                    # Ariadne::Beta::Button => {},
         | 
| 12 | 
            +
                    # Ariadne::Alpha::SegmentedControl => {},
         | 
| 13 | 
            +
                    # Ariadne::Alpha::Layout => {},
         | 
| 14 | 
            +
                    # Ariadne::Alpha::HellipButton => {},
         | 
| 15 | 
            +
                    # Ariadne::Alpha::Image => {},
         | 
| 16 | 
            +
                    # Ariadne::Alpha::OcticonSymbols => {},
         | 
| 17 | 
            +
                    # Ariadne::Alpha::ImageCrop => { js: true },
         | 
| 18 | 
            +
                    # Ariadne::IconButton => { js: true },
         | 
| 19 | 
            +
                    # Ariadne::Beta::AutoComplete => { js: true },
         | 
| 20 | 
            +
                    # Ariadne::Beta::AutoComplete::Item => {},
         | 
| 21 | 
            +
                    # Ariadne::Beta::Avatar => {},
         | 
| 22 | 
            +
                    # Ariadne::Beta::AvatarStack => {},
         | 
| 23 | 
            +
                    # Ariadne::Beta::BaseButton => {},
         | 
| 24 | 
            +
                    # Ariadne::Alpha::Banner => { js: true },
         | 
| 25 | 
            +
                    # Ariadne::Beta::Blankslate => {},
         | 
| 26 | 
            +
                    # Ariadne::BlankslateComponent => {},
         | 
| 27 | 
            +
                    # Ariadne::Beta::BorderBox => {},
         | 
| 28 | 
            +
                    # Ariadne::Beta::BorderBox::Header => {},
         | 
| 29 | 
            +
                    # Ariadne::Box => {},
         | 
| 30 | 
            +
                    # Ariadne::Beta::Breadcrumbs => {},
         | 
| 31 | 
            +
                    # Ariadne::ButtonComponent => { js: true },
         | 
| 32 | 
            +
                    # Ariadne::Beta::ButtonGroup => {},
         | 
| 33 | 
            +
                    # Ariadne::Alpha::ButtonMarketing => {},
         | 
| 34 | 
            +
                    Ariadne::UI::ClipboardCopy::Component => { js: true },
         | 
| 35 | 
            +
                    # Ariadne::Beta::CloseButton => {},
         | 
| 36 | 
            +
                    # Ariadne::Beta::Counter => {},
         | 
| 37 | 
            +
                    # Ariadne::Beta::Details => {},
         | 
| 38 | 
            +
                    # Ariadne::Alpha::Dialog => {},
         | 
| 39 | 
            +
                    # Ariadne::Alpha::Dropdown => { js: true },
         | 
| 40 | 
            +
                    # Ariadne::Beta::Flash => {},
         | 
| 41 | 
            +
                    # Ariadne::Beta::Heading => {},
         | 
| 42 | 
            +
                    # Ariadne::Alpha::HiddenTextExpander => {},
         | 
| 43 | 
            +
                    # Ariadne::Beta::Label => {},
         | 
| 44 | 
            +
                    # Ariadne::LayoutComponent => {},
         | 
| 45 | 
            +
                    # Ariadne::Beta::Link => { js: true },
         | 
| 46 | 
            +
                    # Ariadne::Beta::Markdown => {},
         | 
| 47 | 
            +
                    # Ariadne::Alpha::Menu => {},
         | 
| 48 | 
            +
                    # Ariadne::Navigation::TabComponent => {},
         | 
| 49 | 
            +
                    # Ariadne::Alpha::Navigation::Tab => {},
         | 
| 50 | 
            +
                    # Ariadne::Beta::Octicon => {},
         | 
| 51 | 
            +
                    # Ariadne::Beta::Popover => {},
         | 
| 52 | 
            +
                    # Ariadne::Beta::ProgressBar => {},
         | 
| 53 | 
            +
                    # Ariadne::Beta::State => {},
         | 
| 54 | 
            +
                    # Ariadne::Beta::Spinner => {},
         | 
| 55 | 
            +
                    # Ariadne::Beta::Subhead => {},
         | 
| 56 | 
            +
                    # Ariadne::Alpha::TabContainer => { js: true },
         | 
| 57 | 
            +
                    # Ariadne::Beta::Text => {},
         | 
| 58 | 
            +
                    # Ariadne::Beta::TimelineItem => {},
         | 
| 59 | 
            +
                    # Ariadne::Tooltip => {},
         | 
| 60 | 
            +
                    # Ariadne::Truncate => {},
         | 
| 61 | 
            +
                    # Ariadne::Beta::Truncate => {},
         | 
| 62 | 
            +
                    # Ariadne::Alpha::UnderlineNav => {},
         | 
| 63 | 
            +
                    # Ariadne::Alpha::UnderlinePanels => { js: true },
         | 
| 64 | 
            +
                    # Ariadne::Alpha::TabNav => {},
         | 
| 65 | 
            +
                    # Ariadne::Alpha::TabPanels => { js: true },
         | 
| 66 | 
            +
                    # Ariadne::Alpha::Tooltip => { js: true },
         | 
| 67 | 
            +
                    # Ariadne::Alpha::ToggleSwitch => { js: true },
         | 
| 68 | 
            +
                    # Ariadne::Alpha::Overlay => { js: true },
         | 
| 69 | 
            +
                    # Ariadne::Alpha::ActionMenu => { js: true },
         | 
| 70 70 |  | 
| 71 71 | 
             
                    # Examples can be seen in the NavList docs
         | 
| 72 | 
            -
                    #  | 
| 73 | 
            -
                    #  | 
| 74 | 
            -
                    #  | 
| 72 | 
            +
                    # Ariadne::Alpha::NavList => { js: true },
         | 
| 73 | 
            +
                    # Ariadne::Alpha::NavList::Item => { js: true, examples: false },
         | 
| 74 | 
            +
                    # Ariadne::Alpha::NavList::Group => { js: true, examples: false },
         | 
| 75 75 |  | 
| 76 | 
            -
                    #  | 
| 77 | 
            -
                    #  | 
| 78 | 
            -
                    #  | 
| 76 | 
            +
                    # Ariadne::Beta::NavList => { js: true },
         | 
| 77 | 
            +
                    # Ariadne::Beta::NavList::Item => { js: true, examples: false },
         | 
| 78 | 
            +
                    # Ariadne::Beta::NavList::Group => { js: true, examples: false },
         | 
| 79 79 |  | 
| 80 80 | 
             
                    # ActionList is a base component that should not be used by itself, and thus
         | 
| 81 81 | 
             
                    # does not have examples of its own
         | 
| 82 | 
            -
                    #  | 
| 83 | 
            -
                    #  | 
| 84 | 
            -
                    #  | 
| 85 | 
            -
                    #  | 
| 82 | 
            +
                    # Ariadne::Alpha::ActionList => { js: true, examples: false },
         | 
| 83 | 
            +
                    # Ariadne::Alpha::ActionList::Divider => { examples: false },
         | 
| 84 | 
            +
                    # Ariadne::Alpha::ActionList::Heading => { examples: false },
         | 
| 85 | 
            +
                    # Ariadne::Alpha::ActionList::Item => { examples: false },
         | 
| 86 86 |  | 
| 87 87 | 
             
                    # Forms
         | 
| 88 | 
            -
                     | 
| 89 | 
            -
                    #  | 
| 90 | 
            -
                    #  | 
| 91 | 
            -
                    #  | 
| 92 | 
            -
                    #  | 
| 93 | 
            -
                    #  | 
| 94 | 
            -
                    #  | 
| 95 | 
            -
                    #  | 
| 96 | 
            -
                    #  | 
| 97 | 
            -
                    #  | 
| 88 | 
            +
                    Ariadne::Form::TextField::Component => { form_component: true },
         | 
| 89 | 
            +
                    # Ariadne::Alpha::TextArea => { form_component: true, published: false },
         | 
| 90 | 
            +
                    # Ariadne::Alpha::Select => { form_component: true, published: false },
         | 
| 91 | 
            +
                    # Ariadne::Alpha::MultiInput => { form_component: true, js: true, published: false },
         | 
| 92 | 
            +
                    # Ariadne::Alpha::RadioButton => { form_component: true, published: false },
         | 
| 93 | 
            +
                    # Ariadne::Alpha::RadioButtonGroup => { form_component: true, published: false },
         | 
| 94 | 
            +
                    # Ariadne::Alpha::CheckBox => { form_component: true, published: false },
         | 
| 95 | 
            +
                    # Ariadne::Alpha::CheckBoxGroup => { form_component: true, published: false },
         | 
| 96 | 
            +
                    # Ariadne::Alpha::SubmitButton => { form_component: true, published: false },
         | 
| 97 | 
            +
                    # Ariadne::Alpha::FormButton => { form_component: true, published: false }
         | 
| 98 98 | 
             
                  }.freeze
         | 
| 99 99 |  | 
| 100 100 | 
             
                  include Enumerable
         | 
| @@ -33,7 +33,7 @@ module Ariadne | |
| 33 33 | 
             
                  def source_url
         | 
| 34 34 | 
             
                    @source_url ||= begin
         | 
| 35 35 | 
             
                      path = klass.name.split("::").map(&:underscore).join("/")
         | 
| 36 | 
            -
                      "https://github.com/ | 
| 36 | 
            +
                      "https://github.com/yettoapp/ariadne/tree/main/app/components/#{path}.rb"
         | 
| 37 37 | 
             
                    end
         | 
| 38 38 | 
             
                  end
         | 
| 39 39 |  |