Class: GovukPublishingComponents::ComponentDoc
- Inherits:
-
Object
- Object
- GovukPublishingComponents::ComponentDoc
- Defined in:
- app/models/govuk_publishing_components/component_doc.rb
Instance Attribute Summary collapse
-
#accessibility_excluded_rules ⇒ Object
readonly
Returns the value of attribute accessibility_excluded_rules.
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#component ⇒ Object
readonly
Returns the value of attribute component.
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#embed ⇒ Object
readonly
Returns the value of attribute embed.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
Instance Method Summary collapse
- #accessibility_criteria ⇒ Object
- #component_wrapper_options ⇒ Object
- #display_html? ⇒ Boolean
- #display_preview? ⇒ Boolean
- #example ⇒ Object
- #examples ⇒ Object
- #github_search_url ⇒ Object
- #govuk_frontend_components ⇒ Object
- #html_accessibility_criteria ⇒ Object
- #html_body ⇒ Object
- #html_component_wrapper_options ⇒ Object
-
#initialize(component) ⇒ ComponentDoc
constructor
A new instance of ComponentDoc.
- #other_examples ⇒ Object
- #partial_path ⇒ Object
- #uses_component_wrapper_helper? ⇒ Boolean
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_rules ⇒ Object (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 |
#body ⇒ Object (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 |
#component ⇒ Object (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 |
#description ⇒ Object (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 |
#embed ⇒ Object (readonly)
Returns the value of attribute embed.
3 4 5 |
# File 'app/models/govuk_publishing_components/component_doc.rb', line 3 def @embed end |
#id ⇒ Object (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 |
#name ⇒ Object (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 |
#source ⇒ Object (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_criteria ⇒ Object
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_options ⇒ Object
35 36 37 38 39 |
# File 'app/models/govuk_publishing_components/component_doc.rb', line 35 def if uses_component_wrapper_helper? ComponentWrapperHelperOptions.description end end |
#display_html? ⇒ 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
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 |
#example ⇒ Object
41 42 43 |
# File 'app/models/govuk_publishing_components/component_doc.rb', line 41 def example examples.first end |
#examples ⇒ Object
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"] ||= ComponentExample.new(id.to_s, example_data) end end |
#github_search_url ⇒ Object
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_components ⇒ Object
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_criteria ⇒ Object
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_body ⇒ Object
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_options ⇒ Object
69 70 71 |
# File 'app/models/govuk_publishing_components/component_doc.rb', line 69 def markdown_to_html() if .present? end |
#other_examples ⇒ Object
45 46 47 |
# File 'app/models/govuk_publishing_components/component_doc.rb', line 45 def other_examples examples.slice(1..-1) end |
#partial_path ⇒ Object
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
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 |