Module: Scarpe::WebviewBackground

Includes:
Components::Base64
Included in:
WebviewSlot
Defined in:
lib/scarpe/wv/background.rb

Instance Method Summary collapse

Instance Method Details

#styleObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/scarpe/wv/background.rb', line 9

def style
  styles = (super if defined?(super)) || {}
  return styles unless @background_color

  color = case @background_color
  when Array
    "rgba(#{@background_color.join(", ")})"
  when Range
    "linear-gradient(45deg, #{@background_color.first}, #{@background_color.last})"
  when ->(value) { File.exist?(value) }
    "url(data:image/png;base64,#{encode_file_to_base64(@background_color)})"
  else
    @background_color
  end

  styles.merge(background: color)
end