Sha256: 285ff029da4bba249b23735c328a98a1707a56b4ef88b251ac2b5a1521b7c652

Contents?: true

Size: 1.95 KB

Versions: 99

Compression:

Stored size: 1.95 KB

Contents

# frozen_string_literal: true

# :nocov:

require "json"

module Primer
  module Static
    # :nodoc:
    module GeneratePreviews
      class << self
        def call
          Lookbook.previews.filter_map do |preview|
            next if preview.preview_class == Primer::FormsPreview
            next if Primer::Accessibility.ignore_preview?(preview.preview_class)

            component = preview.components.first&.component_class

            unless component
              raise "Could not determine which component `#{preview.preview_class}` is designed to preview. Please add a `@component` annotation."
            end

            _, _, class_name = Primer::Yard::DocsHelper.status_module_and_short_name(component)

            {
              name: preview.name,
              component: class_name,
              status: component.status.to_s,
              lookup_path: preview.lookup_path,
              examples: preview.scenarios.flat_map do |parent_scenario|
                scenarios = parent_scenario.type == :scenario_group ? parent_scenario.scenarios : [parent_scenario]

                scenarios.map do |scenario|
                  snapshot_tag = scenario.tags.find { |tag| tag.tag_name == "snapshot" }
                  snapshot = if snapshot_tag.nil?
                               "false"
                             elsif snapshot_tag.text.blank?
                               "true"
                             else
                               snapshot_tag.text
                             end
                  {
                    preview_path: scenario.lookup_path,
                    name: scenario.name,
                    snapshot: snapshot,
                    skip_rules: Primer::Accessibility.axe_rules_to_skip(
                      component: component,
                      scenario_name: scenario.name
                    )
                  }
                end
              end
            }
          end
        end
      end
    end
  end
end

Version data entries

99 entries across 99 versions & 2 rubygems

Version Path
primer_view_components-0.30.0 lib/primer/static/generate_previews.rb
openproject-primer_view_components-0.39.1 lib/primer/static/generate_previews.rb
openproject-primer_view_components-0.39.0 lib/primer/static/generate_previews.rb
openproject-primer_view_components-0.38.0 lib/primer/static/generate_previews.rb
primer_view_components-0.29.0 lib/primer/static/generate_previews.rb
primer_view_components-0.28.0 lib/primer/static/generate_previews.rb
openproject-primer_view_components-0.37.1 lib/primer/static/generate_previews.rb
openproject-primer_view_components-0.37.0 lib/primer/static/generate_previews.rb
openproject-primer_view_components-0.36.2 lib/primer/static/generate_previews.rb
openproject-primer_view_components-0.36.1 lib/primer/static/generate_previews.rb
openproject-primer_view_components-0.36.0 lib/primer/static/generate_previews.rb
primer_view_components-0.27.0 lib/primer/static/generate_previews.rb
openproject-primer_view_components-0.35.2 lib/primer/static/generate_previews.rb
openproject-primer_view_components-0.35.1 lib/primer/static/generate_previews.rb
primer_view_components-0.26.1 lib/primer/static/generate_previews.rb
openproject-primer_view_components-0.35.0 lib/primer/static/generate_previews.rb
primer_view_components-0.26.0 lib/primer/static/generate_previews.rb
openproject-primer_view_components-0.34.0 lib/primer/static/generate_previews.rb
openproject-primer_view_components-0.33.2 lib/primer/static/generate_previews.rb
openproject-primer_view_components-0.33.1 lib/primer/static/generate_previews.rb