1 # -*- coding: utf-8 -*-
2 # https://github.com/jazzband/django-pipeline/issues/295#issuecomment-152095865
3 # adjusted for older pipeline
4 from __future__ import unicode_literals
7 from django.contrib.staticfiles.storage import staticfiles_storage
8 from django.utils.safestring import mark_safe
9 from django import template
10 from pipeline.templatetags import compressed
12 register = template.Library()
15 class StylesheetNode(compressed.CompressedCSSNode):
16 def render_css(self, package, path):
17 return self.render_individual_css(package, [path])
19 def render_individual_css(self, package, paths, **kwargs):
22 with codecs.open(staticfiles_storage.path(path), 'r', 'utf-8') as f:
24 html = '<style type="text/css">' + '\n'.join(html) + '</style>'
25 return mark_safe(html)
29 def inline_stylesheet(parser, token):
30 """ Template tag that mimics pipeline's stylesheet tag, but embeds
31 the resulting CSS directly in the page.
34 tag_name, name = token.split_contents()
36 raise template.TemplateSyntaxError(
37 '%r requires exactly one argument: the name of a group in the PIPELINE_CSS setting'
38 % token.split_contents()[0])
39 return StylesheetNode(name)