Newer
Older
John Albin Wilkins
committed
#!/bin/bash
# This script is used by the MAINTAINERS to generate the CSS files from the Sass
# files and make copies of the STARTERKIT stylesheets for the base Zen theme.
ORIG=`pwd`;
STARTERKIT=../STARTERKIT;
# Change directory to the STARTERKIT and run compass with a custom config.
cd $STARTERKIT;
compass clean;
# Create our custom init partial, while keeping the original.
mv sass/_init.scss $ORIG/;
cat $ORIG/_init.scss $ORIG/extras/sass/_init_extras.scss > sass/_init.scss;
John Albin Wilkins
committed
# Build the stylesheets for the Zen base theme.
cp $ORIG/extras/sass/styles-fixed* sass/;
compass compile --environment production --no-line-comments --output-style compressed;
rm sass/styles-fixed*;
# Copy the stylesheets from STARTERKIT to the Zen theme.
rm $ORIG/css/*.css;
rm $ORIG/images/*;
cp css/styles* $ORIG/css/;
cp images/* $ORIG/images/;
# Build the CSS versions of the stylesheets.
cp $ORIG/extras/sass/css-* sass/;
cp $ORIG/extras/sass/layouts/css-* sass/layouts/;
cp $ORIG/extras/sass/components/css-* sass/components/;
rm css/*.css css/*/*.css;
John Albin Wilkins
committed
compass clean;
compass compile --no-line-comments;
rm sass/css-* sass/*/css-*;
John Albin Wilkins
committed
# Don't use the generated styles.css.
git checkout css/styles.css css/styles-rtl.css;
# Massage the generated css-* files and rename them.
for FILENAME in css/css-*.css css/*/css-*.css; do
John Albin Wilkins
committed
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
NEWFILE=`echo $FILENAME | sed -e 's/css\-//'`;
cat $FILENAME |
# Ensure comment headings have a proceeding blank line.
sed -e '/^ \*\/$/ G' |
# Ensure section headings have a proceeding blank line.
sed -e '/^ ========================================================================== \*\/$/ G' |
# Ensure each selector is on its own line.
sed -e 's/^\(\/\*.*\), /\1FIX_THIS_COMMA /' |
sed -e 's/^\([^ ].*\), /\1,\
/' |
sed -e 's/^\([^ ].*\), /\1,\
/' |
sed -e 's/^\([^ ].*\), /\1,\
/' |
sed -e 's/^\([^ ].*\), /\1,\
/' |
sed -e 's/FIX_THIS_COMMA/,/' |
sed -e '/: /! s/^\( [^ /].*\), /\1,\
/' |
# Fix IE wireframes rules.
sed -n '1h;1!H;$ {g;s/\.lt\-ie8\n/.lt-ie8 /g;p;}' |
# Fix site name rules.
sed -n '1h;1!H;$ {g;s/ #site-name\n / #site-name /g;p;}' |
# Ensure each rule has a proceeding blank line.
sed -e '/^ *}/ G' |
# Move property-level comments back to the previous line with the property.
sed -e 's/^ \{2,4\}\(\/\*.*\*\/\)$/ MOVE_UP\1/' |
sed -n '1h;1!H;$ {g;s/\n MOVE_UP/ /g;p;}' |
# Move commented-out properties to their own line.
sed -e 's/ \(\/\* [^:/]*: [^;]*; \*\/ \/\* [^/]* \*\/\) /\
\1\
/' |
sed -e 's/\([^ ]\) \(\/\* [^:/]*: [^;]*; \*\/ \/\* [^/]* \*\/\)$/\1\
\2/' |
# Remove blank lines before closing curly brackets.
sed -n '1h;1!H;$ {g;s/\n*\(\n}\n\)/\1/g;p;}' |
# Remove blank lines before block-level end comment tags ( */ ).
sed -n '1h;1!H;$ {g;s/\n*\(\n\*\/\n\)/\1/g;p;}' |
# Add a blank line between 2 block-level comment tags.
sed -n '1h;1!H;$ {g;s/\(\n\*\/\n\)\/\*/\1\
\/\*/g;p;}' |
# Put /* End @media ... */ comments directly after their closing curly brackets.
sed -n '1h;1!H;$ {g;s/\}\n\n\(\/\* End @media \)/\} \1/g;p;}' |
# Remove any blank lines at the end of the file.
sed -n '$!p;$ {s/^\(..*\)$/\1/p;}' |
# Remove the second @file comment block in RTL layout files.
sed -n '1h;1!H;$ {g;s/\n\/\*\*\n \* \@file\n[^\/]*\/\/[^\/]*\n \*\/\n//;p;}' |
# Convert 2 or more blank lines into 1 blank line and write to the new file.
cat -s > $NEWFILE;
rm $FILENAME;
done
for FIND_FILE in $ORIG/extras/text-replacements/*--search.txt $ORIG/extras/text-replacements/*/*--search.txt; do
John Albin Wilkins
committed
REPLACE_FILE=`echo "$FIND_FILE" | sed -e 's/\-\-search\.txt/--replace.txt/'`;
CSS_PATH=`dirname $FIND_FILE`;
CSS_PATH=css/`basename $CSS_PATH`;
if [[ $CSS_PATH == 'css/text-replacements' ]]; then CSS_PATH=css; fi
CSS_FILE=$CSS_PATH/`basename $FIND_FILE | sed -e 's/\-\-.*\-\-search\.txt/.css/'`;
John Albin Wilkins
committed
# Convert search string to a sed-compatible regular expression.
FIND=`cat $FIND_FILE | perl -e 'while (<>) { $_ =~ s/\s+$//; $line = quotemeta($_) . "\\\n"; $line =~ s/\\\([\(\)\{\}])/\1/g; print $line}'`;
cat $CSS_FILE |
# Replace search string with "TEXT-REPLACEMENT" token.
sed -n -e '1h;1!H;$ {g;' -e "s/$FIND/TEXT\-REPLACEMENT/;" -e 'p;}' |
John Albin Wilkins
committed
sed -e 's/TEXT\-REPLACEMENT/TEXT\-REPLACEMENT\
/' |
# Replace "TEXT-REPLACEMENT" token with contents of replacement file.
sed -e "/^TEXT-REPLACEMENT\$/{r $REPLACE_FILE" -e 'd;}' | #-e '/^TEXT-REPLACEMENT$/! d;' |
cat > $CSS_FILE.new;
# Halt the script if no replacement has been made.
if [ -z "`diff -q $CSS_FILE $CSS_FILE.new`" ]; then
echo "FATAL ERROR: The following file contents were not found: `basename $FIND_FILE`";
# Delete all the generated CSS, except for the one that generated the error.
rm css/*.css $ORIG/css/*.css;
mv $CSS_FILE.new $CSS_FILE;
# Restore the init partial.
mv $ORIG/_init.scss sass/;
John Albin Wilkins
committed
exit;
fi
mv $CSS_FILE.new $CSS_FILE;
done
# Restore the environment.
mv $ORIG/_init.scss sass/;