I come from a PHP-background, more specific Symfony2. Symfony2 has a feature via Assetic to autmagically convert SASS file into CSS.
Now I am working on my first python project using the bottle framework, and I am wondering if there exists a likewise way to have an on-the-fly CSS-generation of SASS files.
Is there an equivalent to Assetic filters in the python world?
Manually running compass
in the background is not an option. I want to use SASS
, but the whole ordeal should be very coy on my workflow.
Once Sass is installed, you can compile your Sass to CSS using the sass command. You'll need to tell Sass which file to build from, and where to output CSS to. For example, running sass input.scss output.css from your terminal would take a single Sass file, input.scss , and compile that file to output.css .
When you write Sass code in a . scss file, it is compiled into a regular CSS file that the browser will use to display it on the web page.
css will compile a single file. node-sass input/folder -o output/folder will compile a entire folder. With the -w option you can watch a folder: node-sass -w input/folder -o output/folder will watch a folder and compile the files to theoutput folder.
Sass lets you use features that do not exist in CSS, like variables, nested rules, mixins, imports, inheritance, built-in functions, and other stuff.
Thinking about this differently, I thought I could just have my python script run sass --watch source.sass:target.css
and so I followed up how to run bash commands in python. Hence my __init_.py
now includes:
bashCommand = "sass --watch ./css/main.sass:./css/main.css"
import subprocess
process = subprocess.Popen(bashCommand.split(), stdout=subprocess.PIPE)
This leads to the sass
file being automagically converted to css
without me having to worry about the whole sass
conversion aspect.
I recommend you use Boussole. It uses libsass-python and watchdog to watch and automatically compile any given file or directory! Just use the command boussole watch
and specify the source and target file/directory.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With