Automating Tapestry subthemes

MOTIVATION: For some sites, such as groups-oriented sites, large numbers of theme variations may be desirable.

Theme adjustments apply, uniformly, to every instance where a theme is used. The uniform application simplifies a common "look and feel" for site-wide layout. However, some sites utilize similar, even different layouts according to focus … coloration for mood, menu placement, and block utilizations are commonly personalized.

To accomplish swift creation of subthemes, I made a template of the Tapestry theme from the sites/all/themes subdirectory. Change to the sites/all/themes subdirectory and execute the following shell command-line sequence.

cp -a tapestry TEMPLATE
mv TEMPLATE/tapestry.info TEMPLATE/TEMPLATE.info
sed -i TEMPLATE/TEMPLATE.info -e "s/tapestry/TEMPLATE/g"
sed -i TEMPLATE/TEMPLATE.info -e "s/Tapestry/TEMPLATE/g"

sed -i TEMPLATE/TEMPLATE.info -e "s/Drupal 6 theme/Drupal 6 theme modified from Tapestry/g"
sed -i TEMPLATE/page.tpl.php -e "s/tapestry/TEMPLATE/g"
sed -i TEMPLATE/template.php -e "s/tapestry/TEMPLATE/g"
sed -i TEMPLATE/theme-settings.php -e "s/tapestry/TEMPLATE/g"
mv TEMPLATE tapestry/TEMPLATE

Now a template theme is ready for a factory procedure which generates a base tapestry clone. That procedure is created with the next shell command-line sequence.

cd tapestry
cat <<EOF> mksubtheme
#!/bin/sh

if test empty$1 = empty ; then
echo SYNTAX ERROR:
echo $0 SUBTHEME_NAME
exit 0
fi

cp -a TEMPLATE $1
mv $1/TEMPLATE.info $1/$1.info
sed -i $1/$1.info -e "s/TEMPLATE/$1/g"
sed -i $1/page.tpl.php -e "s/TEMPLATE/$1/g"
sed -i $1/template.php -e "s/TEMPLATE/$1/g"
sed -i $1/theme-settings.php -e "s/TEMPLATE/$1/g"
EOF

chmod +x mksubtheme

Now we have a command-line theme factory. A future module might extend this functionality to a Drupal module; in the interim, simply execute ./mksubtheme $NEW_SUBTHEME_NAME from a command line while the working directory is sites/all/themes/tapestry (or other procedure-enabled theme directory).