cookutils rev 1102
modules/compressor: compress CSS
author | Aleksej Bobylev <al.bobylev@gmail.com> |
---|---|
date | Fri Nov 30 16:23:45 2018 +0200 (2018-11-30) |
parents | ee18cf2e2d76 |
children | 68d7bbd2b138 |
files | doc/cookopts.txt modules/compressor |
line diff
1.1 --- a/doc/cookopts.txt Fri Nov 30 01:41:14 2018 +0200 1.2 +++ b/doc/cookopts.txt Fri Nov 30 16:23:45 2018 +0200 1.3 @@ -143,6 +143,12 @@ 1.4 The presence of this option overrides the default action (all *.ui and 1.5 *.glade files will be left "as is"). 1.6 1.7 +!cssz 1.8 + Default action is to compress CSS files. Compression means the removal 1.9 + of insignificant spaces and comments. 1.10 + The presence of this option overrides the default action (all *.css files 1.11 + will be left "as is"). 1.12 + 1.13 !monorm 1.14 Default action is to normalize *.mo files. Normalization means the 1.15 unconditional conversion to UTF-8, removal of accidental duplicates and
2.1 --- a/modules/compressor Fri Nov 30 01:41:14 2018 +0200 2.2 +++ b/modules/compressor Fri Nov 30 16:23:45 2018 +0200 2.3 @@ -114,6 +114,7 @@ 2.4 mo2) find $fs/usr/share/locale -type f -name '*.mo' -exec ls -l \{\} \; ;; 2.5 gz) find $install -type f -name '*.gz' ! -path '*/share/man/*' -exec ls -l \{\} \; ;; 2.6 zip) find $install -type f -name '*.zip' -exec ls -l \{\} \; ;; 2.7 + css) find $install -type f -name '*.css' -exec ls -l \{\} \; ;; 2.8 strip) 2.9 { 2.10 find_elf EXEC 2.11 @@ -460,6 +461,32 @@ 2.12 } 2.13 2.14 2.15 +# Function used after compile_rules() to shrink all *.css files: 2.16 +# remove insignificant spaces and comments 2.17 +# Compressing can be disabled with COOKOPTS="!cssz" 2.18 + 2.19 +compress_css() { 2.20 + [ "${COOKOPTS/!cssz/}" != "$COOKOPTS" ] && return 2.21 + size0=$(sizes css); [ -z "$size0" ] && return 2.22 + 2.23 + tpi rcssmin 2.24 + 2.25 + action 'Compressing CSS files...' 2.26 + 2.27 + time0=$(get_time) 2.28 + temp_css="$(mktemp)" 2.29 + IFS=$'\n' 2.30 + for css in $(find $install -type f -name '*.css'); do 2.31 + python -mrcssmin < "$css" > "$temp_css" 2.32 + cat "$temp_css" > "$css" 2.33 + done 2.34 + unset IFS 2.35 + 2.36 + comp_summary "$time0" "$size0" "$(sizes css)" '/dev/null' 2.37 + rm "$temp_css" 2.38 +} 2.39 + 2.40 + 2.41 # Get list of supported locales... 2.42 2.43 get_supported_locales() { 2.44 @@ -840,6 +867,7 @@ 2.45 compress_svg 2.46 compress_gif 2.47 compress_ui 2.48 + compress_css 2.49 ;; 2.50 esac 2.51