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
- #set_tabindex(tabindex_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 16 |
# File 'lib/govuk_publishing_components/presenters/component_wrapper_helper.rb', line 4 def initialize() @options = check_id_is_valid(@options[:id]) if @options.include?(:id) check_data_attributes_are_valid(@options[:data_attributes]) if @options.include?(:data_attributes) check_classes_are_valid(@options[:classes]) if @options.include?(:classes) check_aria_is_valid(@options[:aria]) if @options.include?(:aria) check_role_is_valid(@options[:role]) if @options.include?(:role) check_lang_is_valid(@options[:lang]) if @options.include?(:lang) check_open_is_valid(@options[:open]) if @options.include?(:open) check_hidden_is_valid(@options[:hidden]) if @options.include?(:hidden) check_tabindex_is_valid(@options[:tabindex]) if @options.include?(:tabindex) end |
Instance Method Details
#add_aria_attribute(attributes) ⇒ Object
49 50 51 52 |
# File 'lib/govuk_publishing_components/presenters/component_wrapper_helper.rb', line 49 def add_aria_attribute(attributes) check_aria_is_valid(attributes) extend_object(:aria, attributes) end |
#add_class(classes) ⇒ Object
39 40 41 42 |
# File 'lib/govuk_publishing_components/presenters/component_wrapper_helper.rb', line 39 def add_class(classes) check_classes_are_valid(classes) extend_string(:classes, classes) end |
#add_data_attribute(attributes) ⇒ Object
44 45 46 47 |
# File 'lib/govuk_publishing_components/presenters/component_wrapper_helper.rb', line 44 def add_data_attribute(attributes) check_data_attributes_are_valid(attributes) extend_object(:data_attributes, attributes) end |
#add_role(role) ⇒ Object
54 55 56 57 |
# File 'lib/govuk_publishing_components/presenters/component_wrapper_helper.rb', line 54 def add_role(role) check_role_is_valid(role) extend_string(:role, role) end |
#all_attributes ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/govuk_publishing_components/presenters/component_wrapper_helper.rb', line 18 def all_attributes attributes = {} attributes[:id] = @options[:id] unless @options[:id].blank? attributes[:data] = @options[:data_attributes] unless @options[:data_attributes].blank? attributes[:aria] = @options[:aria] unless @options[:aria].blank? attributes[:class] = @options[:classes] unless @options[:classes].blank? attributes[:role] = @options[:role] unless @options[:role].blank? attributes[:lang] = @options[:lang] unless @options[:lang].blank? attributes[:open] = @options[:open] unless @options[:open].blank? attributes[:hidden] = @options[:hidden] unless @options[:hidden].nil? attributes[:tabindex] = @options[:tabindex] unless @options[:tabindex].blank? attributes end |
#set_hidden(hidden_attribute) ⇒ Object
69 70 71 72 |
# File 'lib/govuk_publishing_components/presenters/component_wrapper_helper.rb', line 69 def set_hidden(hidden_attribute) check_hidden_is_valid(hidden_attribute) @options[:hidden] = hidden_attribute end |
#set_id(id) ⇒ Object
34 35 36 37 |
# File 'lib/govuk_publishing_components/presenters/component_wrapper_helper.rb', line 34 def set_id(id) check_id_is_valid(id) @options[:id] = id end |
#set_lang(lang) ⇒ Object
59 60 61 62 |
# File 'lib/govuk_publishing_components/presenters/component_wrapper_helper.rb', line 59 def set_lang(lang) check_lang_is_valid(lang) @options[:lang] = lang end |
#set_open(open_attribute) ⇒ Object
64 65 66 67 |
# File 'lib/govuk_publishing_components/presenters/component_wrapper_helper.rb', line 64 def set_open(open_attribute) check_open_is_valid(open_attribute) @options[:open] = open_attribute end |
#set_tabindex(tabindex_attribute) ⇒ Object
74 75 76 77 |
# File 'lib/govuk_publishing_components/presenters/component_wrapper_helper.rb', line 74 def set_tabindex(tabindex_attribute) check_tabindex_is_valid(tabindex_attribute) @options[:tabindex] = tabindex_attribute end |