def parse_template(self, template_name):
     try:
         template = self.parser.parse(template_name)
     except IOError:  # unreadable file -> ignore
         if self.verbosity > 0:
             self.stderr.write("\nUnreadable template at: {}".format(template_name))
         return
     except TemplateSyntaxError as e:  # broken template -> ignore
         if self.verbosity > 0:
             self.stderr.write("\nInvalid template {}: {}".format(template_name, e))
         return
     except TemplateDoesNotExist:  # non existent template -> ignore
         if self.verbosity > 0:
             self.stderr.write("\nNon-existent template at: {}".format(template_name))
         return
     except UnicodeDecodeError:
         if self.verbosity > 0:
             self.stderr.write(
                 "\nUnicodeDecodeError while trying to read template {}".format(template_name))
     try:
         nodes = list(self.walk_nodes(template, original=template))
     except Exception as e:
         # Could be an error in some base template
         if self.verbosity > 0:
             self.stderr.write("\nError parsing template {}: {}".format(template_name, e))
     else:
         for node in nodes:
             sass_filename = find_file(node.path)
             if not sass_filename or sass_filename in self.processed_files:
                 continue
             if self.delete_files:
                 self.delete_file(sass_filename, node.path)
             else:
                 self.compile_sass(sass_filename, node.path)
Exemplo n.º 2
0
 def parse_template(self, template_name):
     try:
         template = self.parser.parse(template_name)
     except IOError:  # unreadable file -> ignore
         if self.verbosity > 0:
             self.stderr.write("\nUnreadable template at: {}".format(template_name))
         return
     except TemplateSyntaxError as e:  # broken template -> ignore
         if self.verbosity > 0:
             self.stderr.write("\nInvalid template {}: {}".format(template_name, e))
         return
     except TemplateDoesNotExist:  # non existent template -> ignore
         if self.verbosity > 0:
             self.stderr.write("\nNon-existent template at: {}".format(template_name))
         return
     except UnicodeDecodeError:
         if self.verbosity > 0:
             self.stderr.write("\nUnicodeDecodeError while trying to read template {}".format(template_name))
     try:
         nodes = list(self.walk_nodes(template, original=template))
     except Exception as e:
         # Could be an error in some base template
         if self.verbosity > 0:
             self.stderr.write("\nError parsing template {}: {}".format(template_name, e))
     else:
         for node in nodes:
             sass_filename = find_file(node.path)
             if not sass_filename or sass_filename in self.processed_files:
                 continue
             if self.delete_files:
                 self.delete_file(sass_filename)
             else:
                 self.compile_sass(sass_filename)
 def compile(self, node):
     sass_filename = find_file(node.path)
     if not sass_filename or sass_filename in self.compiled_files:
         return
     content = sass.compile(include_paths=node.include_paths, filename=sass_filename, output_style=self.output_style)
     basename, _ = os.path.splitext(sass_filename)
     destpath = basename + '.css'
     with open(destpath, 'w') as fh:
         fh.write(str(content))
     self.compiled_files.append(sass_filename)
     self.stdout.write("Compiled SASS/SCSS file: '{0}'\n".format(node.path))
Exemplo n.º 4
0
 def compile(self, node):
     sass_filename = find_file(node.path)
     if not sass_filename or sass_filename in self.compiled_files:
         return
     content = sass.compile(include_paths=node.include_paths, filename=sass_filename, output_style='compact')
     basename, _ = os.path.splitext(sass_filename)
     destpath = basename + '.css'
     with open(destpath, 'w') as fh:
         fh.write(content)
     self.compiled_files.append(sass_filename)
     if self.verbosity > 1:
         self.stdout.write("Compiled SASS/SCSS file: '{0}'\n".format(node.path))
 def delete_file(self, node):
     """
     Delete a *.css file, but only if it has been generated through a SASS/SCSS file.
     """
     sass_filename = find_file(node.path)
     if not sass_filename:
         return
     destpath = self.get_destination(sass_filename)
     if os.path.isfile(destpath):
         os.remove(destpath)
         self.compiled_files.append(sass_filename)
         if self.verbosity > 1:
             self.stdout.write("Deleted '{0}'\n".format(destpath))
 def delete_file(self, node):
     """
     Delete a *.css file, but only if it has been generated through a SASS/SCSS file.
     """
     sass_filename = find_file(node.path)
     if not sass_filename:
         return
     basename, _ = os.path.splitext(sass_filename)
     destpath = basename + '.css'
     if os.path.isfile(destpath):
         os.remove(destpath)
         self.compiled_files.append(sass_filename)
         self.stdout.write("Deleted '{0}'\n".format(destpath))
Exemplo n.º 7
0
 def delete_file(self, node):
     """
     Delete a *.css file, but only if it has been generated through a SASS/SCSS file.
     """
     sass_filename = find_file(node.path)
     if not sass_filename:
         return
     basename, _ = os.path.splitext(sass_filename)
     destpath = basename + '.css'
     if os.path.isfile(destpath):
         os.remove(destpath)
         self.compiled_files.append(sass_filename)
         if self.verbosity > 1:
             self.stdout.write("Deleted '{0}'\n".format(destpath))
 def parse_source(self, filename):
     """
     Extract the statements from the given file, look for function calls
     `sass_processor(scss_file)` and compile the filename into CSS.
     """
     callvisitor = FuncCallVisitor('sass_processor')
     tree = ast.parse(open(filename, 'rb').read())
     callvisitor.visit(tree)
     for sass_fileurl in callvisitor.sass_files:
         sass_filename = find_file(sass_fileurl)
         if not sass_filename or sass_filename in self.processed_files:
             continue
         if self.delete_files:
             self.delete_file(sass_filename, sass_fileurl)
         else:
             self.compile_sass(sass_filename, sass_fileurl)
Exemplo n.º 9
0
 def parse_source(self, filename):
     """
     Extract the statements from the given file, look for function calls
     `sass_processor(scss_file)` and compile the filename into CSS.
     """
     callvisitor = FuncCallVisitor('sass_processor')
     tree = ast.parse(open(filename, 'rb').read())
     callvisitor.visit(tree)
     for sass_fileurl in callvisitor.sass_files:
         sass_filename = find_file(sass_fileurl)
         if not sass_filename or sass_filename in self.processed_files:
             continue
         if self.delete_files:
             self.delete_file(sass_filename, sass_fileurl)
         else:
             self.compile_sass(sass_filename, sass_fileurl)
    def compile(self, node):
        sass_filename = find_file(node.path)
        if not sass_filename or sass_filename in self.compiled_files:
            return

        # add a functions to be used from inside SASS
        custom_functions = {'get-setting': get_setting}

        compile_kwargs = {
            'filename': sass_filename,
            'include_paths': node.include_paths,
            'custom_functions': custom_functions,
        }
        if self.sass_precision:
            compile_kwargs['precision'] = self.sass_precision
        if self.sass_output_style:
            compile_kwargs['output_style'] = self.sass_output_style
        content = sass.compile(**compile_kwargs)
        destpath = self.get_destination(sass_filename)
        with open(destpath, 'wb') as fh:
            fh.write(force_bytes(content))
        self.compiled_files.append(sass_filename)
        if self.verbosity > 1:
            self.stdout.write("Compiled SASS/SCSS file: '{0}'\n".format(node.path))