New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add rudimentary SASS integration. #77
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
.env | ||
*.pyc | ||
app/config/local_config.yml | ||
app/static/css | ||
*.mo | ||
.keys | ||
backups | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,3 +32,4 @@ simple-crypt==4.1.7 | |
python-slugify==1.1.3 | ||
wtforms_alchemy | ||
redis | ||
libsass==0.8.3 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
from sassutils.wsgi import SassMiddleware | ||
import sassutils.builder | ||
|
||
SASS_DIR = 'static/sass' | ||
CSS_DIR = 'static/css' | ||
|
||
def init_app(app): | ||
if app.config['DEBUG']: | ||
# If we're debugging, we want to build SASS for each | ||
# request so that we have a nice development flow: | ||
# | ||
# http://hongminhee.org/libsass-python/frameworks/flask.html | ||
# | ||
# However, because nginx intercepts everything at /static/, we can't | ||
# have the SASS middleware use that path, so instead we'll | ||
# put all compiled SASS in a different path that we have | ||
# control over. | ||
app.jinja_env.globals['COMPILED_SASS_ROOT'] = '/sass-middleware' | ||
app.wsgi_app = SassMiddleware(app.wsgi_app, { | ||
'app': (SASS_DIR, CSS_DIR, | ||
app.jinja_env.globals['COMPILED_SASS_ROOT']) | ||
}) | ||
else: | ||
app.jinja_env.globals['COMPILED_SASS_ROOT'] = '/' + CSS_DIR | ||
|
||
def build_files(): | ||
sassutils.builder.build_directory('/noi/app/' + SASS_DIR, | ||
'/noi/app/' + CSS_DIR) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// This is just a sample SASS file. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The libsass-python Flask integration docs suggest putting all SASS in |
||
|
||
body { | ||
html { | ||
color: blue; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<!DOCTYPE html> | ||
<meta charset="utf-8"> | ||
<link rel="stylesheet" href="{{ COMPILED_SASS_ROOT }}/styles.scss.css"> | ||
<title>SASS Test</title> | ||
<p>This is a SASS test.</p> | ||
<p> | ||
<code>COMPILED_SASS_ROOT</code> is <code>{{ COMPILED_SASS_ROOT }}</code>. | ||
</p> | ||
<p> | ||
See compiled SASS at | ||
<a href="{{ COMPILED_SASS_ROOT }}/styles.scss.css">{{ COMPILED_SASS_ROOT }}/styles.scss.cs</a>. | ||
<p> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from app import sass | ||
|
||
def test_sass_compiles(): | ||
''' | ||
Just build all our SASS files and make sure no errors are thrown. | ||
''' | ||
|
||
sass.build_files() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is where our generated SASS goes... It's confusing right now because we also have hand-written CSS in
app/static/styles
, but once we've fully moved over to claudio's CSS, I assume we'll get rid of that.