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



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

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



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

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

#has_dom_class(value, **options) ⇒ Object



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
57
58
59
# File 'lib/has_dom_attrs.rb', line 31

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

        resolved = case value
                   when Proc then instance_exec(&value)
                   when Symbol then send(value)
                   else value
        end

        super() + [resolved]
      end
    end
  )
end

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



27
28
29
# File 'lib/has_dom_attrs.rb', line 27

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



61
62
63
# File 'lib/has_dom_attrs.rb', line 61

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