Skip to content

Instantly share code, notes, and snippets.

@hail2u
Created April 3, 2009 00:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hail2u/89573 to your computer and use it in GitHub Desktop.
Save hail2u/89573 to your computer and use it in GitHub Desktop.
#!/usr/local/bin/perl
use strict;
use warnings;
my @properties = qw(
margin-top margin-right margin-bottom margin-left margin padding-top
padding-right padding-bottom padding-left padding border-top-width
border-right-width border-bottom-width border-left-width border-width
border-top-color border-right-color border-bottom-color border-left-color
border-color border-top-style border-right-style border-bottom-style
border-left-style border-style border-top border-bottom border-right
border-left border display position top right bottom left float clear z-index
direction unicode-bidi width min-width max-width height min-height max-height
line-height vertical-align overflow clip visibility content compact run-in
quotes marker-offset list-style-type list-style-image list-style-position
list-style size marks page-break-before page-break-after page-break-inside page
orphans widows color background-color background-image background-repeat
background-attachment background-position background font-family font-style
font-variant font-weight font-stretch font-size font-size-adjust font
text-indent text-align text-decoration text-shadow letter-spacing word-spacing
text-transform white-space table-layout empty-cells speak-header cursor outline
volume speak pause-before pause-after pause cue-before cue-after cue
play-during azimuth elevation speech-rate voice-family pitch pitch-range stress
richness speak-punctuation speak-numeral
);
my $css = do { open FH, $ARGV[0] or die $!; local $/; <FH> };
$css =~ s/{\s*(.*?)\s*}/"{\n".sort_css_properties($1).";\n}"/imgse;
print $css;
sub sort_css_properties {
my %lines = map {
(my $line = $_) =~ s/^\s*(.+?)\s*$/$1/;
my ($prop) = $line =~ /^(.+?)\s*:.+$/i;
$prop, $line;
} split /;\s*$/, shift;
my @sorted = ();
for my $property (@properties) {
last unless %lines;
for my $key (keys %lines) {
(my $unhacked = $key) =~ s/^[*_]?(.+?)/$1/;
if ($unhacked eq $property) {
push @sorted, $lines{$key};
delete $lines{$key};
last;
}
}
}
return join ";\n", @sorted;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment