Class: PublishingPlatformPublishingComponents::ComponentDoc

Inherits:
Object
  • Object
show all
Defined in:
app/models/publishing_platform_publishing_components/component_doc.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(component) ⇒ ComponentDoc

Returns a new instance of ComponentDoc.



12
13
14
15
16
17
18
19
20
21
# File 'app/models/publishing_platform_publishing_components/component_doc.rb', line 12

def initialize(component)
  @component = component
  @id = component[:id]
  @name = component[:name]
  @description = component[:description]
  @body = component[:body]
  @accessibility_excluded_rules = component[:accessibility_excluded_rules]
  @source = component[:source]
  @embed = component[:embed]
end

Instance Attribute Details

#accessibility_excluded_rulesObject (readonly)

Returns the value of attribute accessibility_excluded_rules.



3
4
5
# File 'app/models/publishing_platform_publishing_components/component_doc.rb', line 3

def accessibility_excluded_rules
  @accessibility_excluded_rules
end

#bodyObject (readonly)

Returns the value of attribute body.



3
4
5
# File 'app/models/publishing_platform_publishing_components/component_doc.rb', line 3

def body
  @body
end

#componentObject (readonly)

Returns the value of attribute component.



3
4
5
# File 'app/models/publishing_platform_publishing_components/component_doc.rb', line 3

def component
  @component
end

#descriptionObject (readonly)

Returns the value of attribute description.



3
4
5
# File 'app/models/publishing_platform_publishing_components/component_doc.rb', line 3

def description
  @description
end

#embedObject (readonly)

Returns the value of attribute embed.



3
4
5
# File 'app/models/publishing_platform_publishing_components/component_doc.rb', line 3

def embed
  @embed
end

#idObject (readonly)

Returns the value of attribute id.



3
4
5
# File 'app/models/publishing_platform_publishing_components/component_doc.rb', line 3

def id
  @id
end

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'app/models/publishing_platform_publishing_components/component_doc.rb', line 3

def name
  @name
end

#sourceObject (readonly)

Returns the value of attribute source.



3
4
5
# File 'app/models/publishing_platform_publishing_components/component_doc.rb', line 3

def source
  @source
end

Instance Method Details

#accessibility_criteriaObject



23
24
25
26
27
28
29
30
31
32
33
# File 'app/models/publishing_platform_publishing_components/component_doc.rb', line 23

def accessibility_criteria
  shared_accessibility_criteria = []

  if component[:shared_accessibility_criteria].present?
    component[:shared_accessibility_criteria].each do |criteria|
      shared_accessibility_criteria << SharedAccessibilityCriteria.send(criteria) if SharedAccessibilityCriteria.respond_to? criteria
    end
  end

  "#{component[:accessibility_criteria]}\n#{shared_accessibility_criteria.join("\n")}"
end

#display_html?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'app/models/publishing_platform_publishing_components/component_doc.rb', line 43

def display_html?
  component[:display_html]
end

#display_preview?Boolean

Returns:

  • (Boolean)


47
48
49
# File 'app/models/publishing_platform_publishing_components/component_doc.rb', line 47

def display_preview?
  component[:display_preview].nil? || component[:display_preview]
end

#exampleObject



35
36
37
# File 'app/models/publishing_platform_publishing_components/component_doc.rb', line 35

def example
  examples.first
end

#examplesObject



76
77
78
79
80
81
82
# File 'app/models/publishing_platform_publishing_components/component_doc.rb', line 76

def examples
  @examples ||= component[:examples].map do |id, example_data|
    example_data ||= {}
    example_data["embed"] ||= embed
    ComponentExample.new(id.to_s, example_data)
  end
end

#github_search_urlObject



71
72
73
74
# File 'app/models/publishing_platform_publishing_components/component_doc.rb', line 71

def github_search_url
  params = { q: "org:publishing-platform components/components/#{id}", type: "Code" }
  "https://github.com/search?#{params.to_query}"
end

#html_accessibility_criteriaObject



55
56
57
# File 'app/models/publishing_platform_publishing_components/component_doc.rb', line 55

def html_accessibility_criteria
  markdown_to_html(accessibility_criteria) if accessibility_criteria.present?
end

#html_bodyObject



51
52
53
# File 'app/models/publishing_platform_publishing_components/component_doc.rb', line 51

def html_body
  markdown_to_html(body) if body.present?
end

#other_examplesObject



39
40
41
# File 'app/models/publishing_platform_publishing_components/component_doc.rb', line 39

def other_examples
  examples.slice(1..-1)
end

#partial_pathObject



59
60
61
62
63
64
65
# File 'app/models/publishing_platform_publishing_components/component_doc.rb', line 59

def partial_path
  if source == "gem"
    "publishing_platform_publishing_components/components/#{id}"
  else
    "#{PublishingPlatformPublishingComponents::Config.component_directory_name}/#{id}"
  end
end

#publishing_platform_frontend_componentsObject



67
68
69
# File 'app/models/publishing_platform_publishing_components/component_doc.rb', line 67

def publishing_platform_frontend_components
  component[:publishing_platform_frontend_components].to_a
end