INNER CODE UNIT · Ruby

write_theme_colors

Automattic/pocket-casts-android · scripts/themes/generate_xml.rb:34

def write_theme_colors(tokens, theme_name, file_marker)
  output = ''
  tokens.each do |token_attrs|
    key = token_attrs[:key]
    next if token_attrs[:user_input]

    theme = token_attrs[:themes][theme_name.to_sym]
    color = theme[:hex]
    opacity = theme[:opacity]
    alpha = (opacity[0...-1].to_f / 100.0 * 255.0).to_i.to_s(16)
    alpha = "0#{alpha}" if alpha.size == 1
    color_with_alpha = opacity == '100%' ? color : "##{alpha}#{color[1..]}"
    output += %(        <item name="#{key}">#{color_with_alpha}</item>\n)
  end
  write_to_theme_file(output, file_marker)
end

tokens = download_themes

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…