1
|
#!/bin/bash
|
2
|
|
3
|
# This script is used by the MAINTAINERS to generate the CSS files from the Sass
|
4
|
# files and make copies of the STARTERKIT stylesheets for the base Zen theme.
|
5
|
|
6
|
|
7
|
ORIG=`pwd`;
|
8
|
STARTERKIT=../STARTERKIT;
|
9
|
|
10
|
|
11
|
# Change directory to the STARTERKIT and run compass with a custom config.
|
12
|
cd $STARTERKIT;
|
13
|
cp config.rb config.rb.orig;
|
14
|
echo "asset_cache_buster :none" >> config.rb;
|
15
|
bundle exec compass clean;
|
16
|
|
17
|
# Create our custom init partial, while keeping the original.
|
18
|
mv sass/_init.scss $ORIG/;
|
19
|
cat $ORIG/_init.scss $ORIG/extras/sass/_init_extras.scss > sass/_init.scss;
|
20
|
|
21
|
# Build the stylesheets for the Zen base theme.
|
22
|
cp $ORIG/extras/sass/styles-fixed* sass/;
|
23
|
bundle exec compass compile --environment production --no-line-comments --output-style compressed;
|
24
|
rm sass/styles-fixed*;
|
25
|
|
26
|
# Copy the stylesheets from STARTERKIT to the Zen theme.
|
27
|
rm $ORIG/css/*.css;
|
28
|
rm $ORIG/images/*;
|
29
|
cp css/styles* $ORIG/css/;
|
30
|
cp images/* $ORIG/images/;
|
31
|
|
32
|
# Build the CSS versions of the stylesheets.
|
33
|
cp $ORIG/extras/sass/css-* sass/;
|
34
|
cp $ORIG/extras/sass/layouts/css-* sass/layouts/;
|
35
|
cp $ORIG/extras/sass/components/css-* sass/components/;
|
36
|
rm css/*.css css/*/*.css;
|
37
|
bundle exec compass clean;
|
38
|
bundle exec compass compile --no-line-comments;
|
39
|
rm sass/css-* sass/*/css-*;
|
40
|
|
41
|
# Don't use the generated styles.css.
|
42
|
git checkout css/styles.css css/styles-rtl.css;
|
43
|
|
44
|
# Massage the generated css-* files and rename them.
|
45
|
for FILENAME in css/css-*.css css/*/css-*.css; do
|
46
|
NEWFILE=`echo $FILENAME | sed -e 's/css\-//'`;
|
47
|
|
48
|
cat $FILENAME |
|
49
|
# Ensure each selector is on its own line.
|
50
|
sed -e 's/^\(\@media.*\), /\1FIX_THIS_COMMA /' |
|
51
|
sed -e 's/^\(\@media.*\), /\1FIX_THIS_COMMA /' |
|
52
|
sed -e 's/^\(\@media.*\), /\1FIX_THIS_COMMA /' |
|
53
|
sed -e 's/^\(\/\*.*\), /\1FIX_THIS_COMMA /' |
|
54
|
sed -e 's/^\(\/\*.*\), /\1FIX_THIS_COMMA /' |
|
55
|
sed -e 's/^\(\/\*.*\), /\1FIX_THIS_COMMA /' |
|
56
|
sed -e 's/^\([^ ].*\), /\1,\
|
57
|
/' |
|
58
|
sed -e 's/^\([^ ].*\), /\1,\
|
59
|
/' |
|
60
|
sed -e 's/^\([^ ].*\), /\1,\
|
61
|
/' |
|
62
|
sed -e 's/^\([^ ].*\), /\1,\
|
63
|
/' |
|
64
|
sed -e 's/FIX_THIS_COMMA/,/' |
|
65
|
sed -e 's/FIX_THIS_COMMA/,/' |
|
66
|
sed -e 's/FIX_THIS_COMMA/,/' |
|
67
|
sed -e '/: /! s/^\( [^ /].*\), /\1,\
|
68
|
/' |
|
69
|
# Fix IE wireframes rules.
|
70
|
sed -n '1h;1!H;$ {g;s/\.lt\-ie8\n/.lt-ie8 /g;p;}' |
|
71
|
# Move notation comments back to the previous line with the property.
|
72
|
sed -e 's/^ \{2,4\}\(\/\* [1-9LTR]* \*\/\)$/ MOVE_UP\1/' |
|
73
|
sed -n '1h;1!H;$ {g;s/\n MOVE_UP/ /g;p;}' |
|
74
|
# Remove blank lines
|
75
|
sed -e '/^$/d' |
|
76
|
# Add a blank line between a block-level comment and another comment.
|
77
|
sed -n '1h;1!H;$ {g;s/\(\n *\*\/\n\)\( *\)\/\*/\1\
|
78
|
\2\/\*/g;p;}' |
|
79
|
# Add a blank line between a ruleset and a comment.
|
80
|
sed -n '1h;1!H;$ {g;s/\(\n *\}\n\)\( *\)\/\*/\1\
|
81
|
\2\/\*/g;p;}' |
|
82
|
# Add a blank line between the start of a media query and a comment.
|
83
|
#@media all and (min-width: 480px) and (max-width: 959px) {
|
84
|
sed -n '1h;1!H;$ {g;s/\(\n\@media .* .\n\)\( \/\**\)/\1\
|
85
|
\2/g;p;}' |
|
86
|
# Remove any blank lines at the end of the file.
|
87
|
sed -n '$!p;$ {s/^\(..*\)$/\1/p;}' |
|
88
|
# Remove the second @file comment block in RTL layout files.
|
89
|
sed -n '1h;1!H;$ {g;s/\n\/\*\*\n \* \@file\n[^\/]*\/\/[^\/]*\n \*\/\n//;p;}' |
|
90
|
# Convert 2 or more blank lines into 1 blank line and write to the new file.
|
91
|
cat -s > $NEWFILE;
|
92
|
|
93
|
rm $FILENAME;
|
94
|
done
|
95
|
|
96
|
# Update the comments in the layouts/*-rtl.css files.
|
97
|
for FILENAME in css/layouts/*-rtl.css; do
|
98
|
cat $FILENAME |
|
99
|
sed -e 's/from left\. \*\/$/FIX_THIS/' |
|
100
|
sed -e 's/from right\. \*\/$/from left. *\//' |
|
101
|
sed -e 's/FIX_THIS$/from right. *\//' |
|
102
|
sed -e 's/ the left one\.$/FIX_THIS/' |
|
103
|
sed -e 's/ the right one\.$/ the left one./' |
|
104
|
sed -e 's/FIX_THIS$/ the right one./' |
|
105
|
cat > $FILENAME.new;
|
106
|
mv $FILENAME.new $FILENAME;
|
107
|
done
|
108
|
|
109
|
for FIND_FILE in $ORIG/extras/text-replacements/*--search.txt $ORIG/extras/text-replacements/*/*--search.txt; do
|
110
|
REPLACE_FILE=`echo "$FIND_FILE" | sed -e 's/\-\-search\.txt/--replace.txt/'`;
|
111
|
CSS_PATH=`dirname $FIND_FILE`;
|
112
|
CSS_PATH=css/`basename $CSS_PATH`;
|
113
|
if [[ $CSS_PATH == 'css/text-replacements' ]]; then CSS_PATH=css; fi
|
114
|
CSS_FILE=$CSS_PATH/`basename $FIND_FILE | sed -e 's/\-\-.*\-\-search\.txt/.css/'`;
|
115
|
|
116
|
# Convert search string to a sed-compatible regular expression.
|
117
|
FIND=`cat $FIND_FILE | perl -e 'while (<>) { $_ =~ s/\s+$//; $line = quotemeta($_) . "\\\n"; $line =~ s/\\\([\(\)\{\}])/\1/g; print $line}'`;
|
118
|
|
119
|
cat $CSS_FILE |
|
120
|
# Replace search string with "TEXT-REPLACEMENT" token.
|
121
|
sed -n -e '1h;1!H;$ {g;' -e "s/$FIND/TEXT\-REPLACEMENT/;" -e 'p;}' |
|
122
|
sed -e 's/TEXT\-REPLACEMENT/TEXT\-REPLACEMENT\
|
123
|
/' |
|
124
|
# Replace "TEXT-REPLACEMENT" token with contents of replacement file.
|
125
|
sed -e "/^TEXT-REPLACEMENT\$/{r $REPLACE_FILE" -e 'd;}' | #-e '/^TEXT-REPLACEMENT$/! d;' |
|
126
|
cat > $CSS_FILE.new;
|
127
|
|
128
|
# Halt the script if no replacement has been made.
|
129
|
if [ -z "`diff -q $CSS_FILE $CSS_FILE.new`" ]; then
|
130
|
echo "FATAL ERROR: The following file contents were not found: `basename $FIND_FILE`";
|
131
|
# Delete all the generated CSS, except for the one that generated the error.
|
132
|
rm css/*.css $ORIG/css/*.css;
|
133
|
mv $CSS_FILE.new $CSS_FILE;
|
134
|
# Restore the environment.
|
135
|
mv config.rb.orig config.rb;
|
136
|
mv $ORIG/_init.scss sass/;
|
137
|
exit;
|
138
|
fi
|
139
|
|
140
|
mv $CSS_FILE.new $CSS_FILE;
|
141
|
done
|
142
|
|
143
|
# Restore the environment.
|
144
|
mv config.rb.orig config.rb;
|
145
|
mv $ORIG/_init.scss sass/;
|
146
|
cd $ORIG;
|