Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Convert SASS on the fly to CSS in Python?

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.

like image 434
k0pernikus Avatar asked Jan 21 '13 00:01

k0pernikus


People also ask

How do I convert Sass to CSS?

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 .

Can Sass be written in 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.

How do I compile SCSS to CSS in Windows?

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.

What does Sass to CSS?

Sass lets you use features that do not exist in CSS, like variables, nested rules, mixins, imports, inheritance, built-in functions, and other stuff.


2 Answers

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.

like image 99
k0pernikus Avatar answered Sep 22 '22 00:09

k0pernikus


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.

like image 37
Jacob Philpott Avatar answered Sep 25 '22 00:09

Jacob Philpott