From ede8ed21f4cc82e67e1ec4bc0ba01b1a70dfa1c7 Mon Sep 17 00:00:00 2001 From: Joseph Schorr Date: Tue, 15 Apr 2014 16:35:15 -0400 Subject: [PATCH] Enable DEBUGGING mode, which loads the individual script files rather than the minimized bundles created by grunt --- endpoints/common.py | 32 +++++++++++++++---- grunt/Gruntfile.js | 3 +- .../jquery.overscroll.min.js | 0 templates/index.html | 2 +- 4 files changed, 28 insertions(+), 9 deletions(-) rename static/{lib => standalonelib}/jquery.overscroll.min.js (100%) diff --git a/endpoints/common.py b/endpoints/common.py index 1efa47637..87d8477d4 100644 --- a/endpoints/common.py +++ b/endpoints/common.py @@ -115,14 +115,34 @@ def random_string(): random = SystemRandom() return ''.join([random.choice(string.ascii_uppercase + string.digits) for _ in range(8)]) +def list_files(path, extension): + import os + def matches(f): + return os.path.splitext(f)[1] == '.' + extension + + def join_path(dp, f): + # Remove the static/ prefix. It is added in the template. + return os.path.join(dp, f)[len('static/'):] + + filepath = 'static/' + path + return [join_path(dp, f) for dp, dn, files in os.walk(filepath) for f in files if matches(f)] + def render_page_template(name, **kwargs): - library_styles = [] - main_styles = ['dist/quay-frontend.css'] + if app.config.get('DEBUGGING', False): + # If DEBUGGING is enabled, then we load the full set of individual JS and CSS files + # from the file system. + library_styles = list_files('lib', 'css') + main_styles = list_files('css', 'css') + library_scripts = list_files('lib', 'js') + main_scripts = list_files('js', 'js') + cache_buster = 'debugging' + else: + library_styles = [] + main_styles = ['dist/quay-frontend.css'] + library_scripts = [] + main_scripts = ['dist/quay-frontend.min.js'] + cache_buster = random_string() - library_scripts = [] - main_scripts = ['dist/quay-frontend.min.js'] - - cache_buster = random_string() resp = make_response(render_template(name, route_data=json.dumps(get_route_data()), main_styles=main_styles, diff --git a/grunt/Gruntfile.js b/grunt/Gruntfile.js index c18206457..218bb6a9d 100644 --- a/grunt/Gruntfile.js +++ b/grunt/Gruntfile.js @@ -25,8 +25,7 @@ module.exports = function(grunt) { }, }, build: { - src: ['../static/lib/**/*.js', '../static/js/*.js', '!../static/lib/jquery.overscroll.min.js', - '../static/dist/template-cache.js'], + src: ['../static/lib/**/*.js', '../static/js/*.js', '../static/dist/template-cache.js'], dest: '../static/dist/<%= pkg.name %>.js' } }, diff --git a/static/lib/jquery.overscroll.min.js b/static/standalonelib/jquery.overscroll.min.js similarity index 100% rename from static/lib/jquery.overscroll.min.js rename to static/standalonelib/jquery.overscroll.min.js diff --git a/templates/index.html b/templates/index.html index 66b9b84ee..56d9d086d 100644 --- a/templates/index.html +++ b/templates/index.html @@ -14,7 +14,7 @@ {% block body_content %} - +