Пример #1
0
class SassSrcNode(Node):
    def __init__(self, path):
        self.sass_processor = SassProcessor(path)

    @classmethod
    def handle_token(cls, parser, token):
        bits = token.split_contents()
        if len(bits) != 2:
            raise TemplateSyntaxError("'{0}' takes a URL to a CSS file as its only argument".format(*bits))
        path = parser.compile_filter(bits[1])
        return cls(path)

    @property
    def path(self):
        return self.sass_processor.resolve_path()

    @property
    def is_sass(self):
        return self.sass_processor.is_sass()

    def render(self, context):
        try:
            path = self.sass_processor(self.sass_processor.resolve_path(context))
        except AttributeError as e:
            msg = "No sass/scss file specified while rendering tag 'sass_src' in template {} ({})"
            raise TemplateSyntaxError(msg.format(context.template_name, e))
        except FileNotFoundError as e:
            msg = str(e) + " while rendering tag 'sass_src' in template {}"
            raise TemplateSyntaxError(msg.format(context.template_name))
        return SassProcessor.handle_simple(path)
class SassSrcNode(Node):
    def __init__(self, path):
        self.sass_processor = SassProcessor(path)

    @classmethod
    def handle_token(cls, parser, token):
        bits = token.split_contents()
        if len(bits) != 2:
            raise TemplateSyntaxError("'{0}' takes a URL to a CSS file as its only argument".format(*bits))
        path = parser.compile_filter(bits[1])
        return cls(path)

    @property
    def path(self):
        return self.sass_processor.resolve_path()

    @property
    def is_sass(self):
        return self.sass_processor.is_sass()

    def render(self, context):
        try:
            path = self.sass_processor.resolve_path(context)
            url = self.sass_processor(path)
        except AttributeError as e:
            msg = "No sass/scss file specified while rendering tag 'sass_src' in template {} ({})"
            raise TemplateSyntaxError(msg.format(context.template_name, e))
        except FileNotFoundError as e:
            msg = str(e) + " while rendering tag 'sass_src' in template {}"
            raise TemplateSyntaxError(msg.format(context.template_name))
        return url
Пример #3
0
def inline_scss(path):
    """ Template tag that compiles a scss and then inlines it.
    """
    processor = SassProcessor()
    path = processor(path)
    with processor.storage.open(path) as f:
        return mark_safe(f.read().decode('utf-8'))
Пример #4
0
 def test_scss(self, scss_file, check_css):
     """
     Tests the css files.
     """
     s = SassProcessor()
     check_css(
         os.path.join(settings.SASS_PROCESSOR_ROOT,
                      s(os.path.join('scss', scss_file))))
Пример #5
0
    def add_css(self):
        self.stylesheets = []

        # compile scss and add the file
        processor = SassProcessor()
        processor.processor_enabled = True
        path = processor('stylesheets/epub.scss')
        with processor.storage.open(path) as f:
            css = f.read()
        self.book.add_item(epub.EpubItem(file_name=path, media_type="text/css", content=css))
        self.stylesheets.append(path)

        # now ensure all html items link to the stylesheets
        for item in self.book.items:
            if isinstance(item, (epub.EpubHtml, epub.EpubNav)):
                for stylesheet in self.stylesheets:
                    # relativise path
                    href = '/'.join(['..'] * item.file_name.count('/') + [stylesheet])
                    item.add_link(href=href, rel='stylesheet', type='text/css')
Пример #6
0
 def render(self, context):
     try:
         path = self.sass_processor(self.sass_processor.resolve_path(context))
     except AttributeError as e:
         msg = "No sass/scss file specified while rendering tag 'sass_src' in template {} ({})"
         raise TemplateSyntaxError(msg.format(context.template_name, e))
     except FileNotFoundError as e:
         msg = str(e) + " while rendering tag 'sass_src' in template {}"
         raise TemplateSyntaxError(msg.format(context.template_name))
     return SassProcessor.handle_simple(path)
Пример #7
0
 def _sass_src_support(self, path, source_file):
     sass_processor = SassProcessor(source_file)
     return sass_processor(path)
Пример #8
0
 def _sass_src_support(self, path, source_file):
     sass_processor = SassProcessor(source_file)
     return SassProcessor.handle_simple(sass_processor(path))
Пример #9
0
 def __init__(self, path):
     self.sass_processor = SassProcessor(path)
 def __init__(self, path):
     self.sass_processor = SassProcessor(path)