Class: Flowbite::Styles

Inherits:
Object
  • Object
show all
Defined in:
app/components/flowbite/styles.rb

Defined Under Namespace

Classes: StyleNotFoundError

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeStyles

Returns a new instance of Styles.



30
31
32
# File 'app/components/flowbite/styles.rb', line 30

def initialize
  @styles = {}
end

Class Method Details

.from_hash(styles_hash) ⇒ Object



8
9
10
11
12
13
14
# File 'app/components/flowbite/styles.rb', line 8

def from_hash(styles_hash)
  styles = Styles.new
  styles_hash.each do |style_name, states_hash|
    styles.add_style(style_name, states_hash)
  end
  styles
end

Instance Method Details

#add_style(style_name, states_hash) ⇒ Object



17
18
19
# File 'app/components/flowbite/styles.rb', line 17

def add_style(style_name, states_hash)
  @styles[style_name] = Flowbite::Style.new(states_hash)
end

#fetch(style_name) ⇒ Object

Raises:



21
22
23
24
25
26
27
28
# File 'app/components/flowbite/styles.rb', line 21

def fetch(style_name)
  return @styles[style_name] if @styles.key?(style_name)

  raise \
    StyleNotFoundError,
    "Style not found: #{style_name}. Available styles: " \
    "#{@styles.keys.sort.join(", ")}"
end