Skip to content

Instantly share code, notes, and snippets.

@alloy-d
Created September 23, 2015 02:06
Show Gist options
  • Save alloy-d/bf8138b364b95196dbe8 to your computer and use it in GitHub Desktop.
Save alloy-d/bf8138b364b95196dbe8 to your computer and use it in GitHub Desktop.
Scans a file for unique colors (in hex) and generates a page of swatches for them.
#!/usr/bin/env ruby
require 'pp'
theme = File.read("molokai.vim")
colors = theme.scan(/(#[a-f0-9]{6})/i).to_a.flatten.uniq
pp colors
File.open("colors.html", "w") do |f|
f.write <<-EOF
<!DOCTYPE html>
<html>
<head>
<style>
body {
font-family: sans-serif;
margin: 0;
}
div {
box-sizing: border-box;
color: white;
float: left;
padding: 2em;
text-align: center;
width: 25%;
}
</style>
</head>
<body>
EOF
colors.each do |color|
f.write "<div style='background-color: #{color};'>#{color}</div>"
end
f.write <<-EOF
</body>
</html>
EOF
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment