Class: GovukPublishingComponents::Presenters::ComponentWrapperHelper

Inherits:
Object
  • Object
show all
Defined in:
lib/govuk_publishing_components/presenters/component_wrapper_helper.rb

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ ComponentWrapperHelper

Returns a new instance of ComponentWrapperHelper.



4
5
6
7
8
9
10
11
12
13
# File 'lib/govuk_publishing_components/presenters/component_wrapper_helper.rb', line 4

def initialize(options)
  @options = 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)
end

Instance Method Details

#add_aria_attribute(attributes) ⇒ Object



43
44
45
46
# File 'lib/govuk_publishing_components/presenters/component_wrapper_helper.rb', line 43

def add_aria_attribute(attributes)
  check_aria_is_valid(attributes)
  extend_object(:aria, attributes)
end

#add_class(classes) ⇒ Object



33
34
35
36
# File 'lib/govuk_publishing_components/presenters/component_wrapper_helper.rb', line 33

def add_class(classes)
  check_classes_are_valid(classes)
  extend_string(:classes, classes)
end

#add_data_attribute(attributes) ⇒ Object



38
39
40
41
# File 'lib/govuk_publishing_components/presenters/component_wrapper_helper.rb', line 38

def add_data_attribute(attributes)
  check_data_attributes_are_valid(attributes)
  extend_object(:data_attributes, attributes)
end

#add_role(role) ⇒ Object



48
49
50
51
# File 'lib/govuk_publishing_components/presenters/component_wrapper_helper.rb', line 48

def add_role(role)
  check_role_is_valid(role)
  extend_string(:role, role)
end

#all_attributesObject



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/govuk_publishing_components/presenters/component_wrapper_helper.rb', line 15

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
end

#set_id(id) ⇒ Object



28
29
30
31
# File 'lib/govuk_publishing_components/presenters/component_wrapper_helper.rb', line 28

def set_id(id)
  check_id_is_valid(id)
  @options[:id] = id
end

#set_lang(lang) ⇒ Object



53
54
55
56
# File 'lib/govuk_publishing_components/presenters/component_wrapper_helper.rb', line 53

def set_lang(lang)
  check_lang_is_valid(lang)
  @options[:lang] = lang
end