diff options
author | Samrat Man Singh <samratmansingh@gmail.com> | 2012-07-07 08:31:08 +0545 |
---|---|---|
committer | Samrat Man Singh <samratmansingh@gmail.com> | 2012-07-07 08:31:08 +0545 |
commit | 2ce26b4ed17e153d9834e6dd21ec0da92d71139e (patch) | |
tree | 9b59308831e99ed534f28aac51b5b236ac54ce87 /syte/compress.py | |
parent | 705357519b7345422a003d8970d1f396579d91b2 (diff) | |
download | pelican-themes-2ce26b4ed17e153d9834e6dd21ec0da92d71139e.tar.gz |
Move syte-pelican to syte
Diffstat (limited to 'syte/compress.py')
-rw-r--r-- | syte/compress.py | 91 |
1 files changed, 91 insertions, 0 deletions
diff --git a/syte/compress.py b/syte/compress.py new file mode 100644 index 0000000..99fec93 --- /dev/null +++ b/syte/compress.py @@ -0,0 +1,91 @@ + +import os +import sys +import subprocess +import shlex +import traceback + +path_to_here = os.path.abspath(os.path.dirname(__file__)) +path_before_site = path_to_here[0:path_to_here.rfind('syte')] +sys.path.append(path_before_site) + +#os.environ['DJANGO_SETTINGS_MODULE'] = 'syte.settings' + +#from django.conf import settings +import settings + +def compress_statics(): + try: + #This won't work on windows. + subprocess.check_call(shlex.split('mkdir -p static/css static/js/min')) + except Exception: + print 'Make sure to create "syte > static > css" and "syte > static > js > min" before compressing statics.' + + compress_styles() + compress_js() + +def compress_styles(): + less_path = 'static/less/styles.less' + css_path = 'static/css/' + + try: + subprocess.check_call(shlex.split('lessc {0} {1}styles.min.css -yui-compress'.format(less_path, css_path))) + print 'CSS Styles Generated: styles.min.css' + except Exception: + exc_type, exc_value, exc_traceback = sys.exc_info() + stack_trace = traceback.format_exception(exc_type, exc_value, exc_traceback) + print stack_trace + +def compress_js(): + js_files = [ + 'libs/jquery.url.js', + 'libs/require.js', + 'libs/handlebars.js', + 'libs/moment.min.js', + 'libs/bootstrap-modal.js', + 'libs/spin.min.js', + 'libs/prettify.js', + + 'components/base.js', + 'components/mobile.js', + 'components/blog-posts.js', + 'components/links.js', + ] + + if settings.TWITTER_INTEGRATION_ENABLED: + js_files.append('components/twitter.js') + + if settings.GITHUB_INTEGRATION_ENABLED: + js_files.append('components/github.js') + + if settings.DRIBBBLE_INTEGRATION_ENABLED: + js_files.append('components/dribbble.js') + + if settings.INSTAGRAM_INTEGRATION_ENABLED: + js_files.append('components/instagram.js') + + if settings.DISQUS_INTEGRATION_ENABLED: + js_files.append('components/disqus.js') + + combined = '' + for js in js_files: + f = open('static/js/' + js, 'r') + combined += f.read() + f.close() + + f = open('static/js/combined.js', 'w') + f.write(combined) + f.close() + + try: + subprocess.check_call(shlex.split('uglifyjs -o static/js/min/scripts.min.js static/js/combined.js')) + subprocess.check_call(shlex.split('rm -f static/js/combined.js')) + print 'JavaScript Combined and Minified: scripts.min.js' + except Exception: + exc_type, exc_value, exc_traceback = sys.exc_info() + stack_trace = traceback.format_exception(exc_type, exc_value, exc_traceback) + print stack_trace + +if __name__ == "__main__": + compress_statics() + sys.exit() |