Added a hook to minify CSS and JS

Pre-commit hook and yuicompressor is available in .hooks dir (and should
be copied to .git/hooks) to handle CSS and JS minification.
This commit is contained in:
Phyks 2013-10-14 16:15:55 +02:00
parent 1bf71e0f53
commit b8de12d01b
10 changed files with 64 additions and 6 deletions

50
.hooks/pre-commit Executable file
View File

@ -0,0 +1,50 @@
#!/bin/sh
# This hook handle CSS and JS minification for the default templates.
# ******************************************************************
# You'll need to have java installed on your system to use this hook
# ******************************************************************
# *** Replace these two vars if need to use another YUICOMPRESSOR than provided ***
YUICOMPRESSOR="../../.hooks/yuicompressor-2.4.8.jar"
# ***
# Templates to process
TEMPLATES="tpl/default_en/ tpl/default_fr/"
# =============
for template in $TEMPLATES
do
cd $template
if `git diff-index --cached HEAD | grep js/main.js > /dev/null 2>&1` || ! [ -e "js/main.min.js" ]
then
echo ">>> Minify hook started"
if [ -e "js/main.min.js" ]
then
rm js/main.min.js
fi
cat js/jquery-1.10.2.min.js js/main.js > js/main.tmp.js
java -jar $YUICOMPRESSOR -o "js/main.min.js" js/main.tmp.js
rm js/main.tmp.js
git add js/main.min.js
echo -e ">>> JS files minified.\n"
fi
if `git diff-index --cached HEAD | grep css/style.css > /dev/null 2>&1` || ! [ -e "css/style.min.css" ]
then
echo ">>> Minify hook started"
if [ -e "css/style.min.css" ]
then
rm css/style.min.css
fi
java -jar $YUICOMPRESSOR css/style.css -o css/style.min.css
git add css/style.min.css
echo -e ">>> CSS files minified.\n"
fi
cd ../..
done
exit 0

Binary file not shown.

1
tpl/default_en/css/style.min.css vendored Normal file
View File

@ -0,0 +1 @@
html{height:100%}body{position:relative;padding-bottom:2em;min-height:calc(100% - 2em);font-family:sans-serif;margin:0}body>p,body>ul,body>dl{margin-left:1em;margin-right:1em}fieldset{border:1px solid #999;margin-bottom:1em}form a{position:relative}form img{height:1.5em;vertical-align:middle;position:absolute;left:.5em}table{margin:auto;text-align:center;max-width:100%;border-collapse:collapse}table td,table th{padding:.75em;border:1px solid black}table th{background-color:#DDD}h2{background-color:#333;padding:.5em;text-align:right;color:white;border-top-right-radius:1em;border-bottom-right-radius:1em;display:inline-block;padding-left:3em;border:.3em solid green;border-left:0}hr{width:33%;margin-top:2em;margin-bottom:2em}input[type="checkbox"]{margin-left:2em}.red{color:red}.center{text-align:center}.label-block{display:inline-block;text-align:right;margin-right:10px;width:200px}.cell-disabled{background-color:#ddd}input[type=submit]{background-color:green;color:white;border-radius:10px}#title,#title a,#title a:visited,#install h1{background-color:#333;border-bottom:.3em solid green;color:white;padding:.5em;margin:0;text-align:center}#title a{text-decoration:none}#menu ul{text-align:center}#menu li{display:inline-block;margin-left:1em;margin-right:1em;margin-bottom:.5em}#notice{text-align:center;font-size:1.5em;background-color:green;padding:.1em}#detailed_summary{margin-top:2.5em}#connexion_form{margin:auto;width:67%;text-align:center}#connexion_form .label-block{width:150px}#edit_password_form,#edit_user_form,#invoice_form,#notice_form,#global_payback_form{width:67%;margin:auto}#global_payback_form fieldset{margin-top:2em}#edit_password_form p,#edit_user_form p,#notice_form p,#global_payback_form p{text-align:center}#edit_user_admin_rights{text-align:center}#textarea_notice{width:75%}textarea#what{width:75%}#list_expenses tr:hover,#balance_table tr:not(:first-child):hover *,#global_paybacks_table tr:not(:first-child):hover *,.highlight_td{background-color:green}#user_connected{text-align:right;margin-right:1em;position:absolute;bottom:0;height:1em;font-size:.75em;right:0;font-style:italic}#install{margin:0}#install form,#settings_form{width:67%;margin:auto}.error{font-size:1.5em;color:red;font-weight:bold;text-align:center}

View File

@ -1,7 +1,6 @@
{if condition="!$connection"} {if condition="!$connection"}
<p id="user_connected">Connected as {$current_user->getDisplayName()}.</p> <p id="user_connected">Connected as {$current_user->getDisplayName()}.</p>
{/if} {/if}
<script type="text/javascript" src="js/jquery-1.10.2.min.js"></script> <script type="text/javascript" src="js/main.min.js"></script>
<script type="text/javascript" src="js/main.js"></script>
</body> </body>
</html> </html>

View File

@ -3,7 +3,7 @@
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8">
<title>{$instance_title}</title> <title>{$instance_title}</title>
<link rel="stylesheet" media="screen" type="text/css" href="css/style.css" /> <link rel="stylesheet" media="screen" type="text/css" href="css/style.min.css" />
<meta name="viewport" content="width=device-width"/> <meta name="viewport" content="width=device-width"/>
<link rel="icon" href="favicon-32.png" sizes="32x32"> <link rel="icon" href="favicon-32.png" sizes="32x32">
<link rel="apple-touch-icon-precomposed" href="favicon-152.png"> <link rel="apple-touch-icon-precomposed" href="favicon-152.png">

4
tpl/default_en/js/main.min.js vendored Normal file

File diff suppressed because one or more lines are too long

1
tpl/default_fr/css/style.min.css vendored Normal file
View File

@ -0,0 +1 @@
html{height:100%}body{position:relative;padding-bottom:2em;min-height:calc(100% - 2em);font-family:sans-serif;margin:0}body>p,body>ul,body>dl{margin-left:1em;margin-right:1em}fieldset{border:1px solid #999;margin-bottom:1em}form a{position:relative}form img{height:1.5em;vertical-align:middle;position:absolute;left:.5em}table{margin:auto;text-align:center;max-width:100%;border-collapse:collapse}table td,table th{padding:.75em;border:1px solid black}table th{background-color:#DDD}h2{background-color:#333;padding:.5em;text-align:right;color:white;border-top-right-radius:1em;border-bottom-right-radius:1em;display:inline-block;padding-left:3em;border:.3em solid green;border-left:0}hr{width:33%;margin-top:2em;margin-bottom:2em}input[type="checkbox"]{margin-left:2em}.red{color:red}.center{text-align:center}.label-block{display:inline-block;text-align:right;margin-right:10px;width:200px}.cell-disabled{background-color:#ddd}input[type=submit]{background-color:green;color:white;border-radius:10px}#title,#title a,#title a:visited,#install h1{background-color:#333;border-bottom:.3em solid green;color:white;padding:.5em;margin:0;text-align:center}#title a{text-decoration:none}#menu ul{text-align:center}#menu li{display:inline-block;margin-left:1em;margin-right:1em;margin-bottom:.5em}#notice{text-align:center;font-size:1.5em;background-color:green;padding:.1em}#detailed_summary{margin-top:2.5em}#connexion_form{margin:auto;width:67%;text-align:center}#connexion_form .label-block{width:150px}#edit_password_form,#edit_user_form,#invoice_form,#notice_form,#global_payback_form{width:67%;margin:auto}#global_payback_form fieldset{margin-top:2em}#edit_password_form p,#edit_user_form p,#notice_form p,#global_payback_form p{text-align:center}#edit_user_admin_rights{text-align:center}#textarea_notice{width:75%}textarea#what{width:75%}#list_expenses tr:hover,#balance_table tr:not(:first-child):hover *,#global_paybacks_table tr:not(:first-child):hover *,.highlight_td{background-color:green}#user_connected{text-align:right;margin-right:1em;position:absolute;bottom:0;height:1em;font-size:.75em;right:0;font-style:italic}#install{margin:0}#install form,#settings_form{width:67%;margin:auto}.error{font-size:1.5em;color:red;font-weight:bold;text-align:center}

View File

@ -1,7 +1,6 @@
{if condition="!$connection"} {if condition="!$connection"}
<p id="user_connected">Connecté en tant que {$current_user->getDisplayName()}.</p> <p id="user_connected">Connecté en tant que {$current_user->getDisplayName()}.</p>
{/if} {/if}
<script type="text/javascript" src="js/jquery-1.10.2.min.js"></script> <script type="text/javascript" src="js/main.min.js"></script>
<script type="text/javascript" src="js/main.js"></script>
</body> </body>
</html> </html>

View File

@ -3,7 +3,7 @@
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8">
<title>{$instance_title}</title> <title>{$instance_title}</title>
<link rel="stylesheet" media="screen" type="text/css" href="css/style.css" /> <link rel="stylesheet" media="screen" type="text/css" href="css/style.min.css" />
<meta name="viewport" content="width=device-width"/> <meta name="viewport" content="width=device-width"/>
<link rel="icon" href="favicon-32.png" sizes="32x32"> <link rel="icon" href="favicon-32.png" sizes="32x32">
<link rel="apple-touch-icon-precomposed" href="favicon-152.png"> <link rel="apple-touch-icon-precomposed" href="favicon-152.png">

4
tpl/default_fr/js/main.min.js vendored Normal file

File diff suppressed because one or more lines are too long