def __init__(self, outfiles, dirs, files=None, lib_dirs = None): self.outfiles = outfiles self.dirs = dirs self.lib_dirs = lib_dirs if lib_dirs else [] self.source_files = get_source_files(self.dirs, extensions=self.extension) if files: self.source_files += files super(FileSystemEventHandler, self).__init__()
def read_source(): inp = '' if args.sources: source_files = helpers.get_source_files(args.sources, args.extension) for f in source_files: with open(f) as reader: inp += reader.read() inp += '\n' else: # reading from standard input inp += sys.stdin.read() return inp
def process_task(self, taskname, extensions=".sass,.scss"): task = self[taskname] head_includes, tail_includes = None, None dirs = [] files = [] for s in task.sources: if os.path.isfile(s): files.append(s) else: dirs.append(s) lib_dirs = get_source_dirs(dirs) if lib_dirs: lib_dirs += lib_dirs lib_dirs = distinct(lib_dirs) source_files = get_source_files(dirs, extensions=extensions) if files: source_files += files compiler = SassCompiler(lib_dirs=lib_dirs, head_includes=task.include.head, tail_includes=task.include.tail) for sf in source_files: #print "Reading %s" % os.path.abspath(sf) if sf.endswith('.scss'): compiler.read_scss_file(sf) else: compiler.read_sass_file(sf) normal_output = compiler.get_css() if isinstance(task.output, basestring): task.output = {'normal': task.output} if 'normal' in task.output: normal_out_filename = os.path.abspath(task.output['normal']) print "Writing %s" % normal_out_filename with open(normal_out_filename, 'w') as of: of.write(normal_output) if 'minified' in task.output: minified_out_filename = os.path.abspath(task.output['minified']) print "Writing %s" % minified_out_filename with open(minified_out_filename, 'w') as of: of.write(minify(normal_output))