Browse Source

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.
Phyks (Lucas Verney) 7 years ago
parent
commit
b8de12d01b

+ 50
- 0
.hooks/pre-commit View File

@@ -0,0 +1,50 @@
1
+#!/bin/sh
2
+
3
+# This hook handle CSS and JS minification for the default templates.
4
+
5
+# ******************************************************************
6
+# You'll need to have java installed on your system to use this hook
7
+# ******************************************************************
8
+
9
+# *** Replace these two vars if need to use another YUICOMPRESSOR than provided ***
10
+YUICOMPRESSOR="../../.hooks/yuicompressor-2.4.8.jar"
11
+# ***
12
+
13
+# Templates to process
14
+TEMPLATES="tpl/default_en/ tpl/default_fr/"
15
+# =============
16
+
17
+for template in $TEMPLATES
18
+do
19
+    cd $template
20
+    if `git diff-index --cached HEAD | grep js/main.js > /dev/null 2>&1` || ! [ -e "js/main.min.js" ]
21
+    then
22
+        echo ">>> Minify hook started"
23
+        if [ -e "js/main.min.js" ]
24
+        then
25
+            rm js/main.min.js
26
+        fi
27
+
28
+        cat js/jquery-1.10.2.min.js js/main.js > js/main.tmp.js
29
+        java -jar $YUICOMPRESSOR -o "js/main.min.js" js/main.tmp.js
30
+        rm js/main.tmp.js
31
+
32
+        git add js/main.min.js
33
+        echo -e ">>> JS files minified.\n"
34
+    fi
35
+
36
+    if `git diff-index --cached HEAD | grep css/style.css > /dev/null 2>&1` || ! [ -e "css/style.min.css" ]
37
+    then 
38
+        echo ">>> Minify hook started"
39
+        if [ -e "css/style.min.css" ]
40
+        then
41
+            rm css/style.min.css
42
+        fi
43
+
44
+        java -jar $YUICOMPRESSOR css/style.css -o css/style.min.css
45
+        git add css/style.min.css
46
+        echo -e ">>> CSS files minified.\n"
47
+    fi
48
+    cd ../..
49
+done
50
+exit 0

BIN
.hooks/yuicompressor-2.4.8.jar View File


+ 1
- 0
tpl/default_en/css/style.min.css View File

@@ -0,0 +1 @@
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}

+ 1
- 2
tpl/default_en/footer.html View File

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

+ 1
- 1
tpl/default_en/header.html View File

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

+ 4
- 0
tpl/default_en/js/main.min.js
File diff suppressed because it is too large
View File


+ 1
- 0
tpl/default_fr/css/style.min.css View File

@@ -0,0 +1 @@
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}

+ 1
- 2
tpl/default_fr/footer.html View File

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

+ 1
- 1
tpl/default_fr/header.html View File

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

+ 4
- 0
tpl/default_fr/js/main.min.js
File diff suppressed because it is too large
View File