Module: HasDomAttrs::ClassMethods

Defined in:
lib/has_dom_attrs.rb

Instance Method Summary collapse

Instance Method Details

#has_dom_aria(name, value = nil, **options) ⇒ Object



20
21
22
# File 'lib/has_dom_attrs.rb', line 20

def has_dom_aria(name, value = nil, **options)
  prepend___has_dom___method(:dom_aria, name, value, **options)
end

#has_dom_attr(name, value = nil, **options) ⇒ Object



16
17
18
# File 'lib/has_dom_attrs.rb', line 16

def has_dom_attr(name, value = nil, **options)
  prepend___has_dom___method(:dom_attrs, name, value, **options)
end

#has_dom_class(value, **options) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/has_dom_attrs.rb', line 28

def has_dom_class(value, **options)
  prepend(
    Module.new do
      define_method :dom_classes do
        cond = options[:if] || options[:unless]
        cond_value = case cond
                     when Proc then instance_exec(&cond)
                     when Symbol, String then send(cond)
        end

        if cond && options.key?(:if)
          return super() unless cond_value
        end

        if cond && options.key?(:unless)
          return super() if cond_value
        end

        super().tap do |classes|
          classes << case value
                     when Proc then instance_exec(&value)
                     when Symbol then send(value)
                     else value
          end
        end
      end
    end
  )
end

#has_dom_data(name, value = nil, **options) ⇒ Object



24
25
26
# File 'lib/has_dom_attrs.rb', line 24

def has_dom_data(name, value = nil, **options)
  prepend___has_dom___method(:dom_data, name, value, **options)
end

#has_dom_style(name, value = nil, **options) ⇒ Object



58
59
60
# File 'lib/has_dom_attrs.rb', line 58

def has_dom_style(name, value = nil, **options)
  prepend___has_dom___method(:dom_style, name, value, **options)
end