Module: Primer::Static::GeneratePreviews

Defined in:
lib/primer/static/generate_previews.rb

Overview

:nodoc:

Class Method Summary collapse

Class Method Details

.callObject



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
# File 'lib/primer/static/generate_previews.rb', line 12

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