1
0
mirror of https://github.com/Tygs/0bin.git synced 2023-08-10 21:13:00 +03:00

Static files can now be compressed

This commit is contained in:
sam 2012-05-17 11:13:40 +02:00
parent 12a6df1f18
commit 0d81a35a47
7 changed files with 221 additions and 13 deletions

51
compress.sh Executable file
View File

@ -0,0 +1,51 @@
#! /bin/bash
COMMAND="yui-compressor";
command -v $COMMAND >/dev/null 2>&1 || { echo >&2 "Error: this script requires the command '$COMMAND' to be available"; exit 1; }
CURDIR=$(dirname $(readlink -f $0));
STATICDIR=$CURDIR'/zerobin/static/'
CSSDIR=$STATICDIR'css/'
JSDIR=$STATICDIR'js/'
MAIN_JS_OUTPUT=$JSDIR"main.min.js";
ADDITIONAL_JS_OUTPUT=$JSDIR"additional.min.js";
CSS_OUTPUT=$CSSDIR"style.min.css"
cat /dev/null > $CSS_OUTPUT;
echo "Compressing CSS..."
echo $'\n''/* Bootstrap */' >> $CSS_OUTPUT;
$COMMAND $CSSDIR'bootstrap.min.css' >> $CSS_OUTPUT;
echo $'\n''/* Prettify */' >> $CSS_OUTPUT;
cat $CSSDIR'prettify.css' >> $CSS_OUTPUT;
echo $'\n''/* Custom */' >> $CSS_OUTPUT;
$COMMAND $CSSDIR'style.css' >> $CSS_OUTPUT;
echo "Compressing JS..."
cat /dev/null > $MAIN_JS_OUTPUT;
echo $'\n''/* jQuery */' >> $MAIN_JS_OUTPUT;
cat $JSDIR'jquery-1.7.2.min.js' >> $MAIN_JS_OUTPUT;
# strip the "use strict" statement because it will apply to all the files
# TODO: file a bug report to SJCL to invite them to use the function syntax
echo $'\n''/* SJCL */' >> $MAIN_JS_OUTPUT;
cat $JSDIR'sjcl.js' | sed 's/"use strict";//' >> $MAIN_JS_OUTPUT;
echo $'\n''/* custom */' >> $MAIN_JS_OUTPUT;
$COMMAND $JSDIR'behavior.js' >> $MAIN_JS_OUTPUT;
cat /dev/null > $ADDITIONAL_JS_OUTPUT;
echo $'\n''/* jQuery Elastic */' >> $ADDITIONAL_JS_OUTPUT;
$COMMAND $JSDIR'jquery.elastic.source.js' >> $ADDITIONAL_JS_OUTPUT;
echo $'\n''/* lzw */' >> $ADDITIONAL_JS_OUTPUT;
$COMMAND $JSDIR'lzw.js' >> $ADDITIONAL_JS_OUTPUT;
echo $'\n''/* prettify */' >> $ADDITIONAL_JS_OUTPUT;
cat $JSDIR'prettify.min.js' >> $ADDITIONAL_JS_OUTPUT;
echo $'\n''/* ZeroClipboard */' >> $ADDITIONAL_JS_OUTPUT;
$COMMAND $JSDIR'ZeroClipboard.js' >> $ADDITIONAL_JS_OUTPUT;
echo "Done"

View File

@ -23,6 +23,10 @@ DEBUG = False
# to serve it, but it's OK for small traffic to set it to True in prod too.
STATIC_FILES_ROOT = os.path.join(ROOT_DIR, 'static')
# If True, will link the compressed verion of the js and css files,
# otherwise, will use the ordinary files
COMPRESSED_STATIC_FILES = not DEBUG
# absolute path where the paste files should be store
# default in projectdirectory/static/content/
# use "/" even under Windows

View File

@ -104,9 +104,9 @@ def error404(code):
return GLOBAL_CONTEXT
@clize.clize
@clize.clize(coerce={'debug': bool, 'compressed_static': bool})
def runserver(host='', port='', debug=None, serve_static='', user='',
group='', settings_file=''):
group='', settings_file='', compressed_static=None):
# merge the settings
if settings_file:
@ -114,11 +114,16 @@ def runserver(host='', port='', debug=None, serve_static='', user='',
settings.HOST = host or settings.HOST
settings.PORT = port or settings.PORT
settings.DEBUG = debug if debug is not None else settings.DEBUG
settings.STATIC_FILES_ROOT = serve_static or settings.STATIC_FILES_ROOT
settings.USER = user or settings.USER
settings.GROUP = group or settings.GROUP
if compressed_static is not None:
settings.COMPRESSED_STATIC_FILES = compressed_static
if debug is not None:
settings.DEBUG = debug
# make sure the templates can be loaded
for d in reversed(settings.TEMPLATE_DIRS):
bottle.TEMPLATE_PATH.insert(0, d)

7
zerobin/static/css/style.min.css vendored Normal file

File diff suppressed because one or more lines are too long

77
zerobin/static/js/additional.min.js vendored Normal file

File diff suppressed because one or more lines are too long

51
zerobin/static/js/main.min.js vendored Normal file

File diff suppressed because one or more lines are too long

View File

@ -10,18 +10,27 @@
a clipboard">
<link rel="shortcut icon" href="/favicon.ico">
<link href="/static/css/prettify.css" rel="stylesheet" />
<link href="/static/css/bootstrap.css" rel="stylesheet">
<link href="/static/css/style.css" rel="stylesheet">
%if settings.COMPRESSED_STATIC_FILES:
<link href="/static/css/style.min.css" rel="stylesheet" />
%else:
<link href="/static/css/prettify.css" rel="stylesheet" />
<link href="/static/css/bootstrap.css" rel="stylesheet">
<link href="/static/css/style.css" rel="stylesheet">
%end
<!-- Le HTML5 shim, for IE7-8 support of HTML5 elements -->
<!--[if lt IE 9]>
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<script src="/static/js/jquery-1.7.2.min.js"></script>
<script src="/static/js/sjcl.js"></script>
<script src="/static/js/behavior.js"></script>
%if settings.COMPRESSED_STATIC_FILES:
<script src="/static/js/main.min.js"></script>
%else:
<script src="/static/js/jquery-1.7.2.min.js"></script>
<script src="/static/js/sjcl.js"></script>
<script src="/static/js/behavior.js"></script>
%end
<script type="text/javascript">
zerobin.max_size = {{ settings.MAX_SIZE }};
@ -127,10 +136,14 @@
</p>
</footer>
<script src="/static/js/jquery.elastic.source.js"></script>
<script src="/static/js/lzw.js"></script>
<script src="/static/js/prettify.min.js"></script>
<script src="/static/js/ZeroClipboard.js"></script>
%if settings.COMPRESSED_STATIC_FILES:
<script src="/static/js/additional.min.js"></script>
%else:
<script src="/static/js/jquery.elastic.source.js"></script>
<script src="/static/js/lzw.js"></script>
<script src="/static/js/prettify.min.js"></script>
<script src="/static/js/ZeroClipboard.js"></script>
%end
<p id="alert-template">
<a class="close" data-dismiss="alert" href="#">×</a>