Browse Source

Cleaner prod/dev libs loading

Rafał Pitoń 10 years ago
parent
commit
eadd5bfbbb

+ 6 - 0
docs/developers/settings.rst

@@ -246,6 +246,12 @@ MISAGO_HOURL_POST_LIMIT
 Hourly limit of posts that may be posted from single account. Fail-safe for situations when forum is flooded by spam bot. Change to 0 to lift this restriction.
 Hourly limit of posts that may be posted from single account. Fail-safe for situations when forum is flooded by spam bot. Change to 0 to lift this restriction.
 
 
 
 
+MISAGO_JS_DEBUG
+---------------
+
+Switches between production and debug versions of Ember and Handlebars.
+
+
 MISAGO_MAILER_BATCH_SIZE
 MISAGO_MAILER_BATCH_SIZE
 ------------------------
 ------------------------
 
 

+ 18 - 15
misago/conf/defaults.py

@@ -31,6 +31,10 @@ import os
 MISAGO_BASE_DIR = os.path.dirname(os.path.dirname(__file__))
 MISAGO_BASE_DIR = os.path.dirname(os.path.dirname(__file__))
 
 
 
 
+# Default JS debug to false
+MISAGO_JS_DEBUG = False
+
+
 # Assets Pipeline
 # Assets Pipeline
 # See http://django-pipeline.readthedocs.org/en/latest/configuration.html
 # See http://django-pipeline.readthedocs.org/en/latest/configuration.html
 PIPELINE_CSS = {
 PIPELINE_CSS = {
@@ -51,10 +55,22 @@ PIPELINE_CSS = {
 PIPELINE_JS = {
 PIPELINE_JS = {
     'misago_lib': {
     'misago_lib': {
         'source_filenames': (
         'source_filenames': (
-            # leave this part empty, its overrided by deployment's settings.py
+            'misago/ember/jquery-1.11.1.min.js',
+            'misago/ember/handlebars.runtime-v2.0.0.js',
+            'misago/ember/ember.prod-1.9.1.js',
+            'misago/ember/ember-data.prod-1.0.0.b14.js',
         ),
         ),
         'output_filename': 'misago_lib.js',
         'output_filename': 'misago_lib.js',
     },
     },
+    'misago_lib_debug': {
+        'source_filenames': (
+            'misago/ember/jquery-1.11.1.min.js',
+            'misago/ember/handlebars-v2.0.0.js',
+            'misago/ember/ember-1.9.1.js',
+            'misago/ember/ember-data-1.0.0.b14.js',
+        ),
+        'output_filename': 'misago_lib_debug.js',
+    },
     'misago': {
     'misago': {
         'source_filenames': (
         'source_filenames': (
             'misago/js/templates/*.hbs',
             'misago/js/templates/*.hbs',
@@ -86,20 +102,6 @@ PIPELINE_JS = {
     },
     },
 }
 }
 
 
-MISAGO_JS_LIB_DEV = (
-    'misago/ember/jquery-1.11.1.min.js',
-    'misago/ember/handlebars-v2.0.0.js',
-    'misago/ember/ember-1.9.1.js',
-    'misago/ember/ember-data-1.0.0.b14.js',
-)
-
-MISAGO_JS_LIB_PROD = (
-    'misago/ember/jquery-1.11.1.min.js',
-    'misago/ember/handlebars.runtime-v2.0.0.js',
-    'misago/ember/ember.prod-1.9.1.js',
-    'misago/ember/ember-data.prod-1.0.0.b14.js',
-)
-
 PIPELINE_COMPILERS = (
 PIPELINE_COMPILERS = (
     'pipeline.compilers.less.LessCompiler',
     'pipeline.compilers.less.LessCompiler',
 )
 )
@@ -178,6 +180,7 @@ TEMPLATE_CONTEXT_PROCESSORS = (
     'django.core.context_processors.static',
     'django.core.context_processors.static',
     'django.core.context_processors.tz',
     'django.core.context_processors.tz',
     'django.contrib.messages.context_processors.messages',
     'django.contrib.messages.context_processors.messages',
+    'misago.core.context_processors.js_debug',
     'misago.core.context_processors.site_address',
     'misago.core.context_processors.site_address',
     'misago.conf.context_processors.settings',
     'misago.conf.context_processors.settings',
     'misago.users.context_processors.sites_links',
     'misago.users.context_processors.sites_links',

+ 9 - 0
misago/core/context_processors.py

@@ -1,3 +1,12 @@
+from django.conf import settings
+
+
+def js_debug(request):
+    return {
+        'MISAGO_JS_DEBUG': settings.MISAGO_JS_DEBUG
+    }
+
+
 def site_address(request):
 def site_address(request):
     if request.is_secure():
     if request.is_secure():
         site_protocol = 'https'
         site_protocol = 'https'

+ 5 - 9
misago/project_template/project_name/settings.py

@@ -23,7 +23,11 @@ BASE_DIR = os.path.dirname(os.path.dirname(__file__))
 # SECURITY WARNING: don't run with debug turned on in production!
 # SECURITY WARNING: don't run with debug turned on in production!
 DEBUG = True
 DEBUG = True
 
 
-TEMPLATE_DEBUG = True
+TEMPLATE_DEBUG = DEBUG
+
+MISAGO_JS_DEBUG = DEBUG
+
+# Hosts allowed to reach your site
 
 
 ALLOWED_HOSTS = []
 ALLOWED_HOSTS = []
 
 
@@ -107,14 +111,6 @@ MISAGO_SENDFILE_HEADER = ''
 MISAGO_SENDFILE_LOCATIONS_PATH = ''
 MISAGO_SENDFILE_LOCATIONS_PATH = ''
 
 
 
 
-# JS Application library definition
-# Don't edit this unless you really have to change Ember/Handlebars/jQuery
-if TEMPLATE_DEBUG:
-    PIPELINE_JS['misago_lib']['source_filenames'] = MISAGO_JS_LIB_DEV
-else:
-    PIPELINE_JS['misago_lib']['source_filenames'] = MISAGO_JS_LIB_PROD
-
-
 # Application definition
 # Application definition
 # Don't edit those settings unless you know what you are doing
 # Don't edit those settings unless you know what you are doing
 ROOT_URLCONF = '{{ project_name }}.urls'
 ROOT_URLCONF = '{{ project_name }}.urls'

+ 5 - 2
misago/templates/misago/base.html

@@ -12,7 +12,6 @@
       <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
       <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
       <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
       <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
     <![endif]-->
     <![endif]-->
-    {% stylesheet 'misago_lib' %}
     {% stylesheet 'misago' %}
     {% stylesheet 'misago' %}
     <link rel="apple-touch-icon-precomposed" sizes="144x144" href="{% static 'apple-touch-icon-144-precomposed.png' %}">
     <link rel="apple-touch-icon-precomposed" sizes="144x144" href="{% static 'apple-touch-icon-144-precomposed.png' %}">
     <link rel="apple-touch-icon-precomposed" sizes="114x114" href="{% static 'apple-touch-icon-114-precomposed.png' %}">
     <link rel="apple-touch-icon-precomposed" sizes="114x114" href="{% static 'apple-touch-icon-114-precomposed.png' %}">
@@ -32,7 +31,11 @@
 
 
     <section id="main"></section>
     <section id="main"></section>
 
 
-    {% javascript "misago_lib" %}
+    {% if MISAGO_JS_DEBUG %}
+      {% javascript "misago_lib_debug" %}
+    {% else %}
+      {% javascript "misago_lib" %}
+    {% endif %}
     {% javascript "misago" %}
     {% javascript "misago" %}
 
 
   </body>
   </body>