Skip to content

Commit

Permalink
Add support for Sass compilation via libsass-python
Browse files Browse the repository at this point in the history
Removes a hard dependency on installing Ruby for GMusicProcurator (unless
you're developing it, in which case it's still required because of scss-lint).
  • Loading branch information
malept committed Apr 18, 2014
1 parent 5c90e4a commit fc1e169
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 3 deletions.
7 changes: 6 additions & 1 deletion INSTALL.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@ Backend
Frontend
~~~~~~~~

* Sass_
* Either libsass-python_ or the reference implementation of Sass_ (which
requires Ruby)
* Node.js + NPM
* Bower (``npm install -g bower``)
* CoffeeScript (``npm install -g coffee-script``)
* UglifyJS2 (``npm install -g uglify-js``)
* importer (``npm install -g importer``)

.. _libsass-python: http://dahlia.kr/libsass-python/
.. _Sass: http://sass-lang.com/

Browser
Expand Down Expand Up @@ -64,6 +66,9 @@ Then run the following (lines that start with ``#`` are comments, not commands):
user@host:gmusicprocurator$ virtualenv venv
user@host:gmusicprocurator$ source venv/bin/activate
(venv)user@host:gmusicprocurator$ pip install -r requirements.txt
# Only run the next line if you wish to use libsass-python instead of the
# Ruby version of Sass:
(venv)user@host:gmusicprocurator$ pip install libsass
(venv)user@host:gmusicprocurator$ python -m gmusicprocurator list_devices --no-desktop
The last command will print out a list of mobile devices that are registered
Expand Down
25 changes: 23 additions & 2 deletions gmusicprocurator/assets.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,31 @@
"""webassets-related code for GMusicProcurator."""

from flask.ext.assets import Bundle
try:
import sass
except ImportError:
sass_filter = 'scss'
else:
import os.path
from webassets.filter import Filter
sass_filter = 'libsass'
from webassets.filter import ExternalTool, register_filter

from .app import assets

if sass_filter == 'libsass':

class LibSassFilter(Filter):
name = 'libsass'

def input(self, _in, out, **kw):
source_path = kw['source_path']
include_paths = [os.path.dirname(source_path)]
out.write(sass.compile(string=_in.read(),
include_paths=include_paths))

register_filter(LibSassFilter)


class ImporterFilter(ExternalTool):

Expand Down Expand Up @@ -58,7 +79,7 @@ def bundlify(fmt, modules, **kwargs):
normalize = 'vendor/normalize-css/normalize.css'

# typography is in a separate bundle so it can be placed before pure
typography = Bundle('scss/typography.scss', filters='scss',
typography = Bundle('scss/typography.scss', filters=sass_filter,
output='scss/typography.out.css')

pure_modules = [
Expand All @@ -68,7 +89,7 @@ def bundlify(fmt, modules, **kwargs):

pure = bundlify('vendor/pure/{0}.css', pure_modules)

main_css = Bundle('scss/main.scss', filters='scss',
main_css = Bundle('scss/main.scss', filters=sass_filter,
output='scss/main.out.css')

css = Bundle(normalize, typography, pure, main_css, filters='cssmin',
Expand Down
3 changes: 3 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ def requires_from_req_txt(filename):
],
},
'install_requires': requires,
'extras_requires': {
'libsass': ['libsass'],
}
'classifiers': CLASSIFIERS,
}

Expand Down

0 comments on commit fc1e169

Please sign in to comment.