Skip to content

Commit

Permalink
support serving Bootstrap CSS and icons locally
Browse files Browse the repository at this point in the history
We can imagine wanting to hack on Finetooth in a network-poor
environment but still wanting the site to look good. Now, if
SERVE_STATIC_LIBS_LOCALLY is truthy and the debug toolbar is disabled,
then all statics are served locally except for the Google Font Finetooth
logo.
  • Loading branch information
zackmdavis committed Apr 12, 2015
1 parent ad86de5 commit dfac4bb
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 4 deletions.
8 changes: 7 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,13 @@ pyvenv.cfg
# collected static files for production-like environments
collectstatic/

# local copies of JavaScript libraries
# local copies of static libraries
static/libs/jquery-2.1.1.min.js
static/libs/underscore-min.js
static/libs/underscore-min.map
static/libs/css/bootstrap.min.css
static/libs/fonts/glyphicons-halflings-regular.ttf
static/libs/fonts/glyphicons-halflings-regular.woff

# local wordlist
static/libs/words
Expand All @@ -43,3 +46,6 @@ db.sqlite3
# case that we're in a dev environment (and should use the
# corresponding Django settings)
.development

# sentinel file to disable the Django Debug Toolbar
.disable_debug_toolbar
3 changes: 3 additions & 0 deletions core/context_processors.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,11 @@ def contextual_static_serving_context_processor(request):
if settings.SERVE_STATIC_LIBS_LOCALLY:
jquery_url = "/static/libs/jquery-2.1.1.min.js"
underscore_url = "/static/libs/underscore-min.js"
bootstrap_url = "/static/libs/css/bootstrap.min.css"
else:
jquery_url = "//code.jquery.com/jquery-2.1.1.min.js"
underscore_url = ("//cdnjs.cloudflare.com/ajax/libs/underscore.js/"
"1.7.0/underscore-min.js")
bootstrap_url = ("//netdna.bootstrapcdn.com/bootstrap/3.2.0/"
"css/bootstrap.min.css")
return locals()
5 changes: 3 additions & 2 deletions settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@
'core',
)

if DEBUG and ENVIRONMENT is Environment.development:
if (DEBUG and ENVIRONMENT is Environment.development and
not os.path.exists(".disable_debug_toolbar")):
INSTALLED_APPS += ('debug_toolbar',)

MIDDLEWARE_CLASSES = (
Expand Down Expand Up @@ -122,7 +123,7 @@

STATICFILES_DIRS = ('static',)

SERVE_STATIC_LIBS_LOCALLY = (os.environ.get('SERVE_STATIC_LIBS_LOCALLY')
SERVE_STATIC_LIBS_LOCALLY = (not os.environ.get('NONLOCAL_STATIC_LIBS')
or ENVIRONMENT is Environment.development)

STATIC_URL = '/static/'
Expand Down
Empty file added static/libs/css/.gitkeep
Empty file.
Empty file added static/libs/fonts/.gitkeep
Empty file.
2 changes: 1 addition & 1 deletion templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<!DOCTYPE html>
<html lang="en">
<head>
<link href="//netdna.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" media="screen" rel="stylesheet">
<link href="{{ bootstrap_url }}" media="screen" rel="stylesheet">
<link href='http://fonts.googleapis.com/css?family=Italianno'
rel='stylesheet' type='text/css'>
<link href="/static/finetooth.css" rel="stylesheet">
Expand Down

0 comments on commit dfac4bb

Please sign in to comment.