Created
September 23, 2015 02:06
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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