Class: GovukPublishingComponents::Presenters::ComponentWrapperHelper
- Inherits:
-
Object
- Object
- GovukPublishingComponents::Presenters::ComponentWrapperHelper
- Defined in:
- lib/govuk_publishing_components/presenters/component_wrapper_helper.rb
Instance Method Summary collapse
- #add_aria_attribute(attributes) ⇒ Object
- #add_class(classes) ⇒ Object
- #add_data_attribute(attributes) ⇒ Object
- #add_role(role) ⇒ Object
- #all_attributes ⇒ Object
-
#initialize(options) ⇒ ComponentWrapperHelper
constructor
A new instance of ComponentWrapperHelper.
- #set_hidden(hidden_attribute) ⇒ Object
- #set_id(id) ⇒ Object
- #set_lang(lang) ⇒ Object
- #set_open(open_attribute) ⇒ Object
Constructor Details
#initialize(options) ⇒ ComponentWrapperHelper
Returns a new instance of ComponentWrapperHelper.
4 5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/govuk_publishing_components/presenters/component_wrapper_helper.rb', line 4 def initialize() = check_id_is_valid([:id]) if .include?(:id) check_data_attributes_are_valid([:data_attributes]) if .include?(:data_attributes) check_classes_are_valid([:classes]) if .include?(:classes) check_aria_is_valid([:aria]) if .include?(:aria) check_role_is_valid([:role]) if .include?(:role) check_lang_is_valid([:lang]) if .include?(:lang) check_open_is_valid([:open]) if .include?(:open) check_hidden_is_valid([:hidden]) if .include?(:hidden) end |
Instance Method Details
#add_aria_attribute(attributes) ⇒ Object
47 48 49 50 |
# File 'lib/govuk_publishing_components/presenters/component_wrapper_helper.rb', line 47 def add_aria_attribute(attributes) check_aria_is_valid(attributes) extend_object(:aria, attributes) end |
#add_class(classes) ⇒ Object
37 38 39 40 |
# File 'lib/govuk_publishing_components/presenters/component_wrapper_helper.rb', line 37 def add_class(classes) check_classes_are_valid(classes) extend_string(:classes, classes) end |
#add_data_attribute(attributes) ⇒ Object
42 43 44 45 |
# File 'lib/govuk_publishing_components/presenters/component_wrapper_helper.rb', line 42 def add_data_attribute(attributes) check_data_attributes_are_valid(attributes) extend_object(:data_attributes, attributes) end |
#add_role(role) ⇒ Object
52 53 54 55 |
# File 'lib/govuk_publishing_components/presenters/component_wrapper_helper.rb', line 52 def add_role(role) check_role_is_valid(role) extend_string(:role, role) end |
#all_attributes ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/govuk_publishing_components/presenters/component_wrapper_helper.rb', line 17 def all_attributes attributes = {} attributes[:id] = [:id] unless [:id].blank? attributes[:data] = [:data_attributes] unless [:data_attributes].blank? attributes[:aria] = [:aria] unless [:aria].blank? attributes[:class] = [:classes] unless [:classes].blank? attributes[:role] = [:role] unless [:role].blank? attributes[:lang] = [:lang] unless [:lang].blank? attributes[:open] = [:open] unless [:open].blank? attributes[:hidden] = [:hidden] unless [:hidden].nil? attributes end |
#set_hidden(hidden_attribute) ⇒ Object
67 68 69 70 |
# File 'lib/govuk_publishing_components/presenters/component_wrapper_helper.rb', line 67 def set_hidden(hidden_attribute) check_hidden_is_valid(hidden_attribute) [:hidden] = hidden_attribute end |
#set_id(id) ⇒ Object
32 33 34 35 |
# File 'lib/govuk_publishing_components/presenters/component_wrapper_helper.rb', line 32 def set_id(id) check_id_is_valid(id) [:id] = id end |
#set_lang(lang) ⇒ Object
57 58 59 60 |
# File 'lib/govuk_publishing_components/presenters/component_wrapper_helper.rb', line 57 def set_lang(lang) check_lang_is_valid(lang) [:lang] = lang end |
#set_open(open_attribute) ⇒ Object
62 63 64 65 |
# File 'lib/govuk_publishing_components/presenters/component_wrapper_helper.rb', line 62 def set_open(open_attribute) check_open_is_valid(open_attribute) [:open] = open_attribute end |