Sha256: 68a59cf505a817a57575feff897d1df7676c2a05210da9381c8060de52a76e76

Contents?: true

Size: 1.59 KB

Versions: 133

Compression:

Stored size: 1.59 KB

Contents

# frozen_string_literal: true

# :nocov:

require "json"

module Primer
  module Static
    # :nodoc:
    module GenerateArguments
      class << self
        def call(view_context: self.view_context)
          Primer::Component.descendants.sort_by(&:name).map do |component|
            docs = registry.find(component)
            ref = Primer::Yard::ComponentManifest.ref_for(component)

            args = docs.params.map do |tag|
              default_value = Primer::Yard::DocsHelper.pretty_default_value(tag, component)

              {
                "name" => tag.name,
                "type" => tag.types.join(", "),
                "default" => default_value,
                "description" => view_context.render(inline: tag.text.squish)
              }
            end

            {
              "component" => docs.metadata[:title],
              "status" => component.status.to_s,
              "a11y_reviewed" => docs.metadata[:a11y_reviewed] == "true",
              "short_name" => docs.short_name,
              "source" => ref.source_url,
              "lookbook" => ref.lookbook_url,
              "parameters" => args
            }
          end
        end

        private

        def view_context
          @view_context ||= ApplicationController.new.tap { |c| c.request = ActionDispatch::TestRequest.create }.view_context.tap do |vc|
            vc.singleton_class.include(Primer::Yard::DocsHelper)
            vc.singleton_class.include(Primer::ViewHelper)
          end
        end

        def registry
          @registry ||= Primer::Yard::Registry.make
        end
      end
    end
  end
end

Version data entries

133 entries across 133 versions & 2 rubygems

Version Path
openproject-primer_view_components-0.33.0 lib/primer/static/generate_arguments.rb
primer_view_components-0.25.1 lib/primer/static/generate_arguments.rb
openproject-primer_view_components-0.32.1 lib/primer/static/generate_arguments.rb
openproject-primer_view_components-0.32.0 lib/primer/static/generate_arguments.rb
openproject-primer_view_components-0.29.1 lib/primer/static/generate_arguments.rb
openproject-primer_view_components-0.29.0 lib/primer/static/generate_arguments.rb
primer_view_components-0.23.0 lib/primer/static/generate_arguments.rb
openproject-primer_view_components-0.28.1 lib/primer/static/generate_arguments.rb
openproject-primer_view_components-0.28.0 lib/primer/static/generate_arguments.rb
openproject-primer_view_components-0.27.0 lib/primer/static/generate_arguments.rb
openproject-primer_view_components-0.26.0 lib/primer/static/generate_arguments.rb
openproject-primer_view_components-0.25.1 lib/primer/static/generate_arguments.rb
primer_view_components-0.22.0 lib/primer/static/generate_arguments.rb
primer_view_components-0.21.1 lib/primer/static/generate_arguments.rb
openproject-primer_view_components-0.25.0 lib/primer/static/generate_arguments.rb
openproject-primer_view_components-0.24.0 lib/primer/static/generate_arguments.rb
primer_view_components-0.21.0 lib/primer/static/generate_arguments.rb
primer_view_components-0.20.1 lib/primer/static/generate_arguments.rb
primer_view_components-0.20.0 lib/primer/static/generate_arguments.rb
openproject-primer_view_components-0.23.0 lib/primer/static/generate_arguments.rb