Skip to content

Instantly share code, notes, and snippets.

@justinvdm
Created October 13, 2016 11:51
Show Gist options
  • Select an option

  • Save justinvdm/7f925c36858857f8cdbebc85f02e86c0 to your computer and use it in GitHub Desktop.

Select an option

Save justinvdm/7f925c36858857f8cdbebc85f02e86c0 to your computer and use it in GitHub Desktop.
diff --git a/gulpfile.js b/gulpfile.js
index cbd611f..7a87d7c 100644
--- a/gulpfile.js
+++ b/gulpfile.js
@@ -9,24 +9,46 @@ var gulp = require('gulp'),
notify = require('gulp-notify'),
sourcemaps = require('gulp-sourcemaps'),
sassdoc = require('sassdoc'),
- livereload = require('gulp-livereload'),
- scss_destination = 'iogt/static/css';
+ livereload = require('gulp-livereload');
-var sass_paths = [
+var sassPaths = [
'iogt/styles/opera-mini_single-view.scss',
'iogt/styles/style-rtl.scss',
'iogt/styles/style.scss',
'iogt/styles/state_320/state_320.scss',
];
-gulp.task('styles', function() {
- return gulp.src(sass_paths)
- .pipe(sourcemaps.init())
+var sassDest = {
+ prd: 'iogt/static/css/prd',
+ dev: 'iogt/static/css/dev'
+};
+
+
+function styles(env) {
+ var s = gulp.src(sassPaths);
+ var isDev = env === 'dev';
+
+ if (isDev) s = s
+ .pipe(sourcemaps.init());
+
+ s = s
.pipe(sass().on('error', sass.logError))
.pipe(minifycss())
- .pipe(sourcemaps.write('/maps'))
- .pipe(gulp.dest(scss_destination))
- .pipe(notify({ message: 'Styles task complete' }));
+
+ if (isDev) s = s
+ .pipe(sourcemaps.write('/maps'));
+
+ return s
+ .pipe(gulp.dest(sassDest[env]))
+ .pipe(notify({ message: `Styles task complete: ${env}` }));
+}
+
+gulp.task('styles:prd', function() {
+ return styles('prd');
+});
+
+gulp.task('styles:dev', function() {
+ return styles('dev');
});
gulp.task('sassdoc', function() {
@@ -40,4 +62,6 @@ gulp.task('watch', function() {
gulp.watch('iogt/styles/*.scss', ['styles']);
});
-gulp.task('default', ['styles']);
\ No newline at end of file
+gulp.task('styles', ['styles:dev', 'styles:prd']);
+
+gulp.task('default', ['styles']);
diff --git a/iogt/processors.py b/iogt/processors.py
new file mode 100644
index 0000000..21f4ef3
--- /dev/null
+++ b/iogt/processors.py
@@ -0,0 +1,5 @@
+from django.conf import settings
+
+
+def env(request):
+ return {'ENV': 'dev' if settings.DEBUG else 'prd'}
diff --git a/iogt/settings/base.py b/iogt/settings/base.py
index f8560c7..3c56be6 100644
--- a/iogt/settings/base.py
+++ b/iogt/settings/base.py
@@ -127,6 +127,7 @@ TEMPLATES = [
'django.contrib.messages.context_processors.messages',
'molo.core.context_processors.locale',
'wagtail.contrib.settings.context_processors.settings',
+ 'iogt.processors.env',
],
},
},
diff --git a/iogt/templates/base.html b/iogt/templates/base.html
index a5cf89f..8dc2266 100644
--- a/iogt/templates/base.html
+++ b/iogt/templates/base.html
@@ -1,7 +1,11 @@
{% load wagtailcore_tags compress static wagtailuserbar core_tags i18n persona_tags %}
{% load wagtailsettings_tags wagtailimages_tags %}
{% load google_analytics_tags %}
+{% load static %}
+{% load compress %}
+
{% get_settings %}
+{% get_static_prefix as STATIC_PREFIX %}
<!DOCTYPE html>
<html>
@@ -30,26 +34,44 @@
<link rel="shortcut icon" href="/static/favicon/favicon.ico">
<meta name="msapplication-config" content="/static/favicon/browserconfig.xml">
<meta name="theme-color" content="#ffffff">
- <link rel="stylesheet" type="text/css" href="{% static 'css/style.css' %}">
+ {% compress css %}
+ <link rel="stylesheet" type="text/css" href="{{ STATIC_PREFIX }}css/{{ ENV }}/style.css">
+ {% endcompress %}
{% block extra_css %}{% endblock %}
+
<script type="text/javascript">
- var CutsTheMustard = 'querySelector' in document && 'localStorage' in window && 'addEventListener' in window,
- LargeScreen = ((window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth) >= 200),
- smartStyles = '<link rel="stylesheet" type="text/css" href="{% static "css/state_320.css" %}">',
- operaMiniSingleView = '<link rel="stylesheet" type="text/css" media="handheld" href="{% static "css/opera-mini_single-view.css" %}">',
- latoGoogleFont = '<link href="https://fonts.googleapis.com/css?family=Lato:400,700,900" rel="stylesheet">';
- if(CutsTheMustard === true) {
- if(LargeScreen) {
- document.write(smartStyles, latoGoogleFont);
- }
- }
- if(LargeScreen === false) {
- document.write(operaMiniSingleView);
+ var CutsTheMustard = 'querySelector' in document && 'localStorage' in window && 'addEventListener' in window;
+ var LargeScreen = ((window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth) >= 200);
+
+ var operaMiniSingleView = '{% spaceless %}
+ {% compress css %}
+ <link rel="stylesheet" type="text/css" media="handheld" href="{{ STATIC_PREFIX }}css/{{ ENV }}/opera-mini_single-view.css">
+ {% endcompress %}
+ {% endspaceless %}';
+
+ var smartStyles = '{% spaceless %}
+ {% compress css %}
+ <link rel="stylesheet" type="text/css" href="{{ STATIC_PREFIX }}css/{{ ENV }}/state_320.css" %}">
+ {% endcompress %}
+ {% endspaceless %}',
+
+ var latoGoogleFont = '<link href="https://fonts.googleapis.com/css?family=Lato:400,700,900" rel="stylesheet">';
+
+ if(CutsTheMustard === true) {
+ if(LargeScreen) {
+ document.write(smartStyles, latoGoogleFont);
}
+ }
+
+ if(LargeScreen === false) {
+ document.write(operaMiniSingleView);
+ }
</script>
{% get_current_language as LANGUAGE_CODE %}
{% if LANGUAGE_CODE|language_bidi == True %}
- <link rel="stylesheet" type="text/css" href="{% static 'css/style-rtl.css' %}">
+ {% compress css %}
+ <link rel="stylesheet" type="text/css" href="{{ STATIC_PREFIX }}css/{{ ENV }}/style-rtl.css' %}">
+ {% endcompress %}
{% endif %}
</head>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment