Class: Spark::Component::Base

Inherits:
ActionView::Component::Base
  • Object
show all
Includes:
Spark::Component
Defined in:
app/components/spark/component/base.rb

Instance Method Summary collapse

Instance Method Details

#selector(root, sub = nil, val: nil) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
# File 'app/components/spark/component/base.rb', line 6

def selector(root, sub = nil, val: nil)
  sub = sub.to_s.dasherize if sub
  val ||= case root
  when :data, :aria then
    tag_attrs[root][sub]
  else
    tag_attrs[root]
  end

  %([#{[root, sub].compact.join('-').dasherize}="#{val}"])
end

#to_sObject



22
23
24
# File 'app/components/spark/component/base.rb', line 22

def to_s
  self.yield
end

#unique_id(prefix = :id) ⇒ Object



18
19
20
# File 'app/components/spark/component/base.rb', line 18

def unique_id(prefix = :id)
  "#{prefix}-#{SecureRandom.hex(10)}"
end