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() = 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) check_tabindex_is_valid([:tabindex]) if .include?(:tabindex) check_dir_is_valid([:dir]) if .include?(:dir) check_type_is_valid([:type]) if .include?(:type) check_draggable_is_valid([:draggable]) if .include?(:draggable) check_rel_is_valid([:rel]) if .include?(:rel) check_target_is_valid([:target]) if .include?(:target) check_margin_bottom_is_valid([:margin_bottom]) if .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] = [:id] if [:id].present? attributes[:data] = [:data_attributes] if [:data_attributes].present? attributes[:aria] = [:aria] if [:aria].present? (([:classes] ||= "") << " govuk-!-margin-bottom-#{@options[:margin_bottom]}").strip! if [:margin_bottom] attributes[:class] = [:classes] if [:classes].present? attributes[:role] = [:role] if [:role].present? attributes[:lang] = [:lang] if [:lang].present? attributes[:open] = [:open] if [:open].present? attributes[:hidden] = [:hidden] unless [:hidden].nil? attributes[:tabindex] = [:tabindex] if [:tabindex].present? attributes[:dir] = [:dir] if [:dir].present? attributes[:type] = [:type] if [:type].present? attributes[:draggable] = [:draggable] if [:draggable].present? attributes[:rel] = [:rel] if [:rel].present? attributes[:target] = [:target] if [:target].present? attributes[:title] = [:title] if [: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) [: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) [: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) [: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) [: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) [: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) [: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) [: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) [: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) [: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) [: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) [: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) [:type] = type_attribute end |