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_rel(rel_attribute) ⇒ Object
- #add_role(role) ⇒ Object
- #all_attributes ⇒ Object
-
#initialize(options) ⇒ ComponentWrapperHelper
constructor
A new instance of ComponentWrapperHelper.
- #set_dir(dir_attribute) ⇒ Object
- #set_draggable(draggable_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_rel(rel_attribute) ⇒ Object
- #set_tabindex(tabindex_attribute) ⇒ Object
- #set_target(target_attribute) ⇒ Object
- #set_title(title_attribute) ⇒ Object
- #set_type(type_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 19 20 21 22 |
# 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_type_is_valid(@options[:type]) if @options.include?(:type) check_draggable_is_valid(@options[:draggable]) if @options.include?(:draggable) check_rel_is_valid(@options[:rel]) if @options.include?(:rel) check_target_is_valid(@options[:target]) if @options.include?(:target) check_margin_bottom_is_valid(@options[:margin_bottom]) if @options.include?(:margin_bottom) end |
Instance Method Details
#add_aria_attribute(attributes) ⇒ Object
64 65 66 67 |
# File 'lib/govuk_publishing_components/presenters/component_wrapper_helper.rb', line 64 def add_aria_attribute(attributes) check_aria_is_valid(attributes) extend_object(:aria, attributes) end |
#add_class(classes) ⇒ Object
54 55 56 57 |
# File 'lib/govuk_publishing_components/presenters/component_wrapper_helper.rb', line 54 def add_class(classes) check_classes_are_valid(classes) extend_string(:classes, classes) end |
#add_data_attribute(attributes) ⇒ Object
59 60 61 62 |
# File 'lib/govuk_publishing_components/presenters/component_wrapper_helper.rb', line 59 def add_data_attribute(attributes) check_data_attributes_are_valid(attributes) extend_object(:data_attributes, attributes) end |
#add_rel(rel_attribute) ⇒ Object
109 110 111 112 |
# File 'lib/govuk_publishing_components/presenters/component_wrapper_helper.rb', line 109 def add_rel(rel_attribute) check_rel_is_valid(rel_attribute) extend_string(:rel, rel_attribute) end |
#add_role(role) ⇒ Object
69 70 71 72 |
# File 'lib/govuk_publishing_components/presenters/component_wrapper_helper.rb', line 69 def add_role(role) check_role_is_valid(role) extend_string(:role, role) end |
#all_attributes ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/govuk_publishing_components/presenters/component_wrapper_helper.rb', line 24 def all_attributes attributes = {} attributes[:id] = @options[:id] if @options[:id].present? attributes[:data] = @options[:data_attributes] if @options[:data_attributes].present? attributes[:aria] = @options[:aria] if @options[:aria].present? ((@options[:classes] ||= "") << " govuk-!-margin-bottom-#{@options[:margin_bottom]}").strip! if @options[:margin_bottom] attributes[:class] = @options[:classes] if @options[:classes].present? attributes[:role] = @options[:role] if @options[:role].present? attributes[:lang] = @options[:lang] if @options[:lang].present? attributes[:open] = @options[:open] if @options[:open].present? attributes[:hidden] = @options[:hidden] unless @options[:hidden].nil? attributes[:tabindex] = @options[:tabindex] if @options[:tabindex].present? attributes[:dir] = @options[:dir] if @options[:dir].present? attributes[:type] = @options[:type] if @options[:type].present? attributes[:draggable] = @options[:draggable] if @options[:draggable].present? attributes[:rel] = @options[:rel] if @options[:rel].present? attributes[:target] = @options[:target] if @options[:target].present? attributes[:title] = @options[:title] if @options[:title].present? attributes end |
#set_dir(dir_attribute) ⇒ Object
94 95 96 97 |
# File 'lib/govuk_publishing_components/presenters/component_wrapper_helper.rb', line 94 def set_dir(dir_attribute) check_dir_is_valid(dir_attribute) @options[:dir] = dir_attribute end |
#set_draggable(draggable_attribute) ⇒ Object
104 105 106 107 |
# File 'lib/govuk_publishing_components/presenters/component_wrapper_helper.rb', line 104 def set_draggable(draggable_attribute) check_draggable_is_valid(draggable_attribute) @options[:draggable] = draggable_attribute end |
#set_hidden(hidden_attribute) ⇒ Object
84 85 86 87 |
# File 'lib/govuk_publishing_components/presenters/component_wrapper_helper.rb', line 84 def set_hidden(hidden_attribute) check_hidden_is_valid(hidden_attribute) @options[:hidden] = hidden_attribute end |
#set_id(id) ⇒ Object
49 50 51 52 |
# File 'lib/govuk_publishing_components/presenters/component_wrapper_helper.rb', line 49 def set_id(id) check_id_is_valid(id) @options[:id] = id end |
#set_lang(lang) ⇒ Object
74 75 76 77 |
# File 'lib/govuk_publishing_components/presenters/component_wrapper_helper.rb', line 74 def set_lang(lang) check_lang_is_valid(lang) @options[:lang] = lang end |
#set_margin_bottom(margin_bottom) ⇒ Object
128 129 130 131 |
# File 'lib/govuk_publishing_components/presenters/component_wrapper_helper.rb', line 128 def set_margin_bottom(margin_bottom) check_margin_bottom_is_valid(margin_bottom) @options[:margin_bottom] = margin_bottom end |
#set_open(open_attribute) ⇒ Object
79 80 81 82 |
# File 'lib/govuk_publishing_components/presenters/component_wrapper_helper.rb', line 79 def set_open(open_attribute) check_open_is_valid(open_attribute) @options[:open] = open_attribute end |
#set_rel(rel_attribute) ⇒ Object
114 115 116 117 |
# File 'lib/govuk_publishing_components/presenters/component_wrapper_helper.rb', line 114 def set_rel(rel_attribute) check_rel_is_valid(rel_attribute) @options[:rel] = rel_attribute end |
#set_tabindex(tabindex_attribute) ⇒ Object
89 90 91 92 |
# File 'lib/govuk_publishing_components/presenters/component_wrapper_helper.rb', line 89 def set_tabindex(tabindex_attribute) check_tabindex_is_valid(tabindex_attribute) @options[:tabindex] = tabindex_attribute end |
#set_target(target_attribute) ⇒ Object
119 120 121 122 |
# File 'lib/govuk_publishing_components/presenters/component_wrapper_helper.rb', line 119 def set_target(target_attribute) check_target_is_valid(target_attribute) @options[:target] = target_attribute end |
#set_title(title_attribute) ⇒ Object
124 125 126 |
# File 'lib/govuk_publishing_components/presenters/component_wrapper_helper.rb', line 124 def set_title(title_attribute) @options[:title] = title_attribute end |
#set_type(type_attribute) ⇒ Object
99 100 101 102 |
# File 'lib/govuk_publishing_components/presenters/component_wrapper_helper.rb', line 99 def set_type(type_attribute) check_type_is_valid(type_attribute) @options[:type] = type_attribute end |