Login

SASS/SCSS include template tag.

Author:
bryanhelmig
Posted:
February 7, 2012
Language:
Python
Version:
1.3
Score:
0 (after 0 ratings)

You'll need to pip install pyScss first.

Converts on the fly, so you won't want to use this for much more than just testing.

Usage in a template:

{% load sass %}

{% include_sass "disclosures/css/base.scss" %}
{% include_sass "disclosures/css/grid.scss" %}
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
from django.template import Node
from django.template.base import Library
from django.template.loader_tags import do_include

from scss import Scss
sass = Scss()

register = Library()

class SASSNode(Node):
    def __init__(self, node):
        self.node = node

    def render(self, context):
        raw = self.node.render(context)
        return sass.compile(str(raw))

def sass_include(parser, token):
    return SASSNode(do_include(parser, token))

register.tag('include_sass', sass_include)

More like this

  1. Template tag - list punctuation for a list of items by shapiromatron 9 months ago
  2. JSONRequestMiddleware adds a .json() method to your HttpRequests by cdcarter 9 months, 1 week ago
  3. Serializer factory with Django Rest Framework by julio 1 year, 3 months ago
  4. Image compression before saving the new model / work with JPG, PNG by Schleidens 1 year, 4 months ago
  5. Help text hyperlinks by sa2812 1 year, 5 months ago

Comments

Please login first before commenting.