Class: GovukPublishingComponents::ComponentDoc

Inherits:
Object
  • Object
show all
Defined in:
app/models/govuk_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/govuk_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/govuk_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/govuk_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/govuk_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/govuk_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/govuk_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/govuk_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/govuk_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/govuk_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/govuk_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

#component_wrapper_optionsObject



35
36
37
38
39
# File 'app/models/govuk_publishing_components/component_doc.rb', line 35

def component_wrapper_options
  if uses_component_wrapper_helper?
    ComponentWrapperHelperOptions.description
  end
end

#display_html?Boolean

Returns:

  • (Boolean)


49
50
51
# File 'app/models/govuk_publishing_components/component_doc.rb', line 49

def display_html?
  component[:display_html]
end

#display_preview?Boolean

Returns:

  • (Boolean)


53
54
55
# File 'app/models/govuk_publishing_components/component_doc.rb', line 53

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

#exampleObject



41
42
43
# File 'app/models/govuk_publishing_components/component_doc.rb', line 41

def example
  examples.first
end

#examplesObject



90
91
92
93
94
95
96
# File 'app/models/govuk_publishing_components/component_doc.rb', line 90

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



85
86
87
88
# File 'app/models/govuk_publishing_components/component_doc.rb', line 85

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

#govuk_frontend_componentsObject



81
82
83
# File 'app/models/govuk_publishing_components/component_doc.rb', line 81

def govuk_frontend_components
  component[:govuk_frontend_components].to_a
end

#html_accessibility_criteriaObject



65
66
67
# File 'app/models/govuk_publishing_components/component_doc.rb', line 65

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

#html_bodyObject



61
62
63
# File 'app/models/govuk_publishing_components/component_doc.rb', line 61

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

#html_component_wrapper_optionsObject



69
70
71
# File 'app/models/govuk_publishing_components/component_doc.rb', line 69

def html_component_wrapper_options
  markdown_to_html(component_wrapper_options) if component_wrapper_options.present?
end

#other_examplesObject



45
46
47
# File 'app/models/govuk_publishing_components/component_doc.rb', line 45

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

#partial_pathObject



73
74
75
76
77
78
79
# File 'app/models/govuk_publishing_components/component_doc.rb', line 73

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

#uses_component_wrapper_helper?Boolean

Returns:

  • (Boolean)


57
58
59
# File 'app/models/govuk_publishing_components/component_doc.rb', line 57

def uses_component_wrapper_helper?
  component[:uses_component_wrapper_helper]
end