Created
March 22, 2012 21:23
-
-
Save rvock/2164668 to your computer and use it in GitHub Desktop.
Compass Gzip stats
This file contains 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
def to_human n | |
count = 0 | |
while n >= 1024 and count < 4 | |
n /= 1024.0 | |
count += 1 | |
end | |
format("%.2f",n) + %w(B KB MB GB TB)[count] | |
end | |
require 'zlib' | |
# output size of css after compiling | |
on_stylesheet_saved do |filename| | |
defl = Zlib::Deflate.new | |
defl.deflate(File.read(filename)); | |
compressed = defl.deflate(nil) | |
print "\tSize: ", to_human(File.size(filename)), " / ", to_human(compressed.length), " (gzip)\n" | |
end |
This file contains 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
require 'css_parser' | |
# check for IE selector bug (would need bless-css or manual work) | |
# remember previous selector and property counts per file | |
previous_selector_count = Hash[] | |
previous_prop_count = Hash[] | |
on_stylesheet_saved do |filename| | |
parser = parser = CssParser::Parser.new | |
parser.load_file!(filename) | |
selector_count = 0 | |
prop_count = 0 | |
parser.each_selector do |selector, declarations, specificity| | |
sels = selector.split(/,/).size | |
props = declarations.split(/;/).size | |
selector_count += sels | |
prop_count += props | |
end | |
if not previous_selector_count.key?(filename) | |
previous_selector_count[filename] = 0 | |
end | |
psc = previous_selector_count[filename] | |
if not previous_prop_count.key?(filename) | |
previous_prop_count[filename] = 0 | |
end | |
ppc = previous_prop_count[filename] | |
selector_increase = "" | |
if psc != 0 | |
selector_diff = selector_count - psc | |
if selector_diff < 0 | |
selector_increase << " \e[32m#{selector_diff}\e[0m" | |
elsif selector_diff > 0 | |
selector_increase << " \e[33m+#{selector_diff}\e[0m" | |
end | |
end | |
previous_selector_count[filename] = selector_count | |
prop_increase = "" | |
if ppc != 0 | |
prop_diff = prop_count - ppc | |
if prop_diff < 0 | |
prop_increase << " (\e[32m#{prop_diff}\e[0m)" | |
elsif prop_diff > 0 | |
prop_increase << " (\e[33m+#{prop_diff}\e[0m)" | |
end | |
end | |
previous_prop_count[filename] = prop_count | |
print "\t", selector_count," selectors", selector_increase, ", ", prop_count, " properties", prop_increase, "\n" | |
if selector_count > 4096 | |
puts "\t\e[31mwarning \e[0mIE selector limit reached. Consider using blesscss.com\n" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment