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.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #accessibility_criteria ⇒ Object
- #capture_full_width_screenshot? ⇒ Boolean
- #component_wrapper_options ⇒ Object
- #display_html? ⇒ Boolean
- #display_preview? ⇒ Boolean
- #example ⇒ Object
- #examples ⇒ Object
- #get_govuk_container_class ⇒ Object
- #github_search_url ⇒ Object
- #govuk_frontend_components ⇒ Object
- #html_accessibility_criteria ⇒ Object
- #html_body ⇒ Object
- #html_component_wrapper_options_description ⇒ Object
- #html_component_wrapper_options_intro ⇒ Object
-
#initialize(component, type) ⇒ ComponentDoc
constructor
A new instance of ComponentDoc.
- #other_examples ⇒ Object
- #partial_path ⇒ Object
- #uses_component_wrapper_helper? ⇒ Boolean
Constructor Details
#initialize(component, type) ⇒ ComponentDoc
Returns a new instance of ComponentDoc.
13 14 15 16 17 18 19 20 21 22 23 |
# File 'app/models/govuk_publishing_components/component_doc.rb', line 13 def initialize(component, type) @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] @type = type 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 |
#type ⇒ Object (readonly)
Returns the value of attribute type.
3 4 5 |
# File 'app/models/govuk_publishing_components/component_doc.rb', line 3 def type @type end |
Instance Method Details
#accessibility_criteria ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 |
# File 'app/models/govuk_publishing_components/component_doc.rb', line 25 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 |
#capture_full_width_screenshot? ⇒ Boolean
62 63 64 |
# File 'app/models/govuk_publishing_components/component_doc.rb', line 62 def capture_full_width_screenshot? component[:capture_full_width_screenshot] end |
#component_wrapper_options ⇒ Object
37 38 39 40 41 42 43 44 |
# File 'app/models/govuk_publishing_components/component_doc.rb', line 37 def if uses_component_wrapper_helper? { intro: ComponentWrapperHelperOptions.intro, description: ComponentWrapperHelperOptions.description, } end end |
#display_html? ⇒ Boolean
54 55 56 |
# File 'app/models/govuk_publishing_components/component_doc.rb', line 54 def display_html? component[:display_html] end |
#display_preview? ⇒ Boolean
58 59 60 |
# File 'app/models/govuk_publishing_components/component_doc.rb', line 58 def display_preview? component[:display_preview].nil? || component[:display_preview] end |
#example ⇒ Object
46 47 48 |
# File 'app/models/govuk_publishing_components/component_doc.rb', line 46 def example examples.first end |
#examples ⇒ Object
109 110 111 112 113 114 115 |
# File 'app/models/govuk_publishing_components/component_doc.rb', line 109 def examples @examples ||= component[:examples].map do |id, example_data| example_data ||= {} example_data["embed"] ||= ComponentExample.new(id.to_s, example_data) end end |
#get_govuk_container_class ⇒ Object
70 71 72 |
# File 'app/models/govuk_publishing_components/component_doc.rb', line 70 def get_govuk_container_class capture_full_width_screenshot? ? "govuk-full-width-container" : "govuk-width-container" end |
#github_search_url ⇒ Object
104 105 106 107 |
# File 'app/models/govuk_publishing_components/component_doc.rb', line 104 def github_search_url params = { q: "org:alphagov #{partial_path}", type: "Code" } "https://github.com/search?#{params.to_query}" end |
#govuk_frontend_components ⇒ Object
100 101 102 |
# File 'app/models/govuk_publishing_components/component_doc.rb', line 100 def govuk_frontend_components component[:govuk_frontend_components].to_a end |
#html_accessibility_criteria ⇒ Object
78 79 80 |
# File 'app/models/govuk_publishing_components/component_doc.rb', line 78 def html_accessibility_criteria markdown_to_html(accessibility_criteria) if accessibility_criteria.present? end |
#html_body ⇒ Object
74 75 76 |
# File 'app/models/govuk_publishing_components/component_doc.rb', line 74 def html_body markdown_to_html(body) if body.present? end |
#html_component_wrapper_options_description ⇒ Object
86 87 88 |
# File 'app/models/govuk_publishing_components/component_doc.rb', line 86 def markdown_to_html([:description]) if .present? end |
#html_component_wrapper_options_intro ⇒ Object
82 83 84 |
# File 'app/models/govuk_publishing_components/component_doc.rb', line 82 def markdown_to_html([:intro]) if .present? end |
#other_examples ⇒ Object
50 51 52 |
# File 'app/models/govuk_publishing_components/component_doc.rb', line 50 def other_examples examples.slice(1..-1) end |
#partial_path ⇒ Object
90 91 92 93 94 95 96 97 98 |
# File 'app/models/govuk_publishing_components/component_doc.rb', line 90 def partial_path if source == "gem" "govuk_publishing_components/components/#{id}" elsif type == "flexible section" "#{GovukPublishingComponents::Config.flexible_sections_directory_name}/#{id}" else "#{GovukPublishingComponents::Config.component_directory_name}/#{id}" end end |
#uses_component_wrapper_helper? ⇒ Boolean
66 67 68 |
# File 'app/models/govuk_publishing_components/component_doc.rb', line 66 def uses_component_wrapper_helper? component[:uses_component_wrapper_helper] end |