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_margin_bottom(margin_bottom) ⇒ 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 18 |
# 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) check_margin_bottom_is_valid(@options[:margin_bottom]) if @options.include?(:margin_bottom) end |
Instance Method Details
#add_aria_attribute(attributes) ⇒ Object
55 56 57 58 |
# File 'lib/govuk_publishing_components/presenters/component_wrapper_helper.rb', line 55 def add_aria_attribute(attributes) check_aria_is_valid(attributes) extend_object(:aria, attributes) end |
#add_class(classes) ⇒ Object
45 46 47 48 |
# File 'lib/govuk_publishing_components/presenters/component_wrapper_helper.rb', line 45 def add_class(classes) check_classes_are_valid(classes) extend_string(:classes, classes) end |
#add_data_attribute(attributes) ⇒ Object
50 51 52 53 |
# File 'lib/govuk_publishing_components/presenters/component_wrapper_helper.rb', line 50 def add_data_attribute(attributes) check_data_attributes_are_valid(attributes) extend_object(:data_attributes, attributes) end |
#add_role(role) ⇒ Object
60 61 62 63 |
# File 'lib/govuk_publishing_components/presenters/component_wrapper_helper.rb', line 60 def add_role(role) check_role_is_valid(role) extend_string(:role, role) end |
#all_attributes ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/govuk_publishing_components/presenters/component_wrapper_helper.rb', line 20 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? ((@options[:classes] ||= "") << " govuk-!-margin-bottom-#{@options[:margin_bottom]}").strip! if @options[:margin_bottom] 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
85 86 87 88 |
# File 'lib/govuk_publishing_components/presenters/component_wrapper_helper.rb', line 85 def set_dir(dir_attribute) check_dir_is_valid(dir_attribute) @options[:dir] = dir_attribute end |
#set_hidden(hidden_attribute) ⇒ Object
75 76 77 78 |
# File 'lib/govuk_publishing_components/presenters/component_wrapper_helper.rb', line 75 def set_hidden(hidden_attribute) check_hidden_is_valid(hidden_attribute) @options[:hidden] = hidden_attribute end |
#set_id(id) ⇒ Object
40 41 42 43 |
# File 'lib/govuk_publishing_components/presenters/component_wrapper_helper.rb', line 40 def set_id(id) check_id_is_valid(id) @options[:id] = id end |
#set_lang(lang) ⇒ Object
65 66 67 68 |
# File 'lib/govuk_publishing_components/presenters/component_wrapper_helper.rb', line 65 def set_lang(lang) check_lang_is_valid(lang) @options[:lang] = lang end |
#set_margin_bottom(margin_bottom) ⇒ Object
90 91 92 93 |
# File 'lib/govuk_publishing_components/presenters/component_wrapper_helper.rb', line 90 def set_margin_bottom(margin_bottom) check_margin_bottom_is_valid(margin_bottom) @options[:margin_bottom] = margin_bottom end |
#set_open(open_attribute) ⇒ Object
70 71 72 73 |
# File 'lib/govuk_publishing_components/presenters/component_wrapper_helper.rb', line 70 def set_open(open_attribute) check_open_is_valid(open_attribute) @options[:open] = open_attribute end |
#set_tabindex(tabindex_attribute) ⇒ Object
80 81 82 83 |
# File 'lib/govuk_publishing_components/presenters/component_wrapper_helper.rb', line 80 def set_tabindex(tabindex_attribute) check_tabindex_is_valid(tabindex_attribute) @options[:tabindex] = tabindex_attribute end |