Class: Showcase::Helpers::HtmlOptions

Inherits:
Object
  • Object
show all
Defined in:
lib/showcase/helpers/html_options.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ HtmlOptions

Returns a new instance of HtmlOptions.



6
7
8
# File 'lib/showcase/helpers/html_options.rb', line 6

def initialize(options = {})
  @options = (options || {}).symbolize_keys
end

Instance Method Details

#add_class!(css_class) ⇒ Object



10
11
12
# File 'lib/showcase/helpers/html_options.rb', line 10

def add_class!(css_class)
  merge_attrs!(class: css_class)
end

#merge_attrs!(options = {}) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/showcase/helpers/html_options.rb', line 14

def merge_attrs!(options = {})
  new_options = (options || {}).symbolize_keys

  if new_options[:class]
    class_attr = HtmlClassAttribute.new(@options[:class])
    class_attr << new_options[:class]
    new_options[:class] = class_attr.to_html_attribute
  end

  @options.merge!(new_options)
end

#to_hObject



26
27
28
# File 'lib/showcase/helpers/html_options.rb', line 26

def to_h
  @options.dup
end