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_dir(dir_attribute) ⇒ Object
- #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 17 |
# 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) check_dir_is_valid(@options[:dir]) if @options.include?(:dir) end |
Instance Method Details
#add_aria_attribute(attributes) ⇒ Object
51 52 53 54 |
# File 'lib/govuk_publishing_components/presenters/component_wrapper_helper.rb', line 51 def add_aria_attribute(attributes) check_aria_is_valid(attributes) extend_object(:aria, attributes) end |
#add_class(classes) ⇒ Object
41 42 43 44 |
# File 'lib/govuk_publishing_components/presenters/component_wrapper_helper.rb', line 41 def add_class(classes) check_classes_are_valid(classes) extend_string(:classes, classes) end |
#add_data_attribute(attributes) ⇒ Object
46 47 48 49 |
# File 'lib/govuk_publishing_components/presenters/component_wrapper_helper.rb', line 46 def add_data_attribute(attributes) check_data_attributes_are_valid(attributes) extend_object(:data_attributes, attributes) end |
#add_role(role) ⇒ Object
56 57 58 59 |
# File 'lib/govuk_publishing_components/presenters/component_wrapper_helper.rb', line 56 def add_role(role) check_role_is_valid(role) extend_string(:role, role) end |
#all_attributes ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/govuk_publishing_components/presenters/component_wrapper_helper.rb', line 19 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[:dir] = @options[:dir] unless @options[:dir].blank? attributes end |
#set_dir(dir_attribute) ⇒ Object
81 82 83 84 |
# File 'lib/govuk_publishing_components/presenters/component_wrapper_helper.rb', line 81 def set_dir(dir_attribute) check_dir_is_valid(dir_attribute) @options[:dir] = dir_attribute end |
#set_hidden(hidden_attribute) ⇒ Object
71 72 73 74 |
# File 'lib/govuk_publishing_components/presenters/component_wrapper_helper.rb', line 71 def set_hidden(hidden_attribute) check_hidden_is_valid(hidden_attribute) @options[:hidden] = hidden_attribute end |
#set_id(id) ⇒ Object
36 37 38 39 |
# File 'lib/govuk_publishing_components/presenters/component_wrapper_helper.rb', line 36 def set_id(id) check_id_is_valid(id) @options[:id] = id end |
#set_lang(lang) ⇒ Object
61 62 63 64 |
# File 'lib/govuk_publishing_components/presenters/component_wrapper_helper.rb', line 61 def set_lang(lang) check_lang_is_valid(lang) @options[:lang] = lang end |
#set_open(open_attribute) ⇒ Object
66 67 68 69 |
# File 'lib/govuk_publishing_components/presenters/component_wrapper_helper.rb', line 66 def set_open(open_attribute) check_open_is_valid(open_attribute) @options[:open] = open_attribute end |
#set_tabindex(tabindex_attribute) ⇒ Object
76 77 78 79 |
# File 'lib/govuk_publishing_components/presenters/component_wrapper_helper.rb', line 76 def set_tabindex(tabindex_attribute) check_tabindex_is_valid(tabindex_attribute) @options[:tabindex] = tabindex_attribute end |