def css_precompiled(data, offset_path='.', argv=None): """ 预编译css :param data: 规则字典 :param argv: 输入变量 :return: """ now_path = data['source_path'] + '/' + offset_path if os.path.isdir(now_path): fps = os.listdir(now_path) for fp in fps: css_precompiled(data, '/'.join([offset_path, fp]), argv) else: # 判断是不是修改了这个文件 if os.path.realpath(now_path) != os.path.realpath( argv['change_file_path']): return with open(now_path, 'r') as fp: file_type = tools.get_file_type(now_path) if file_type not in ['styl', 'less', 'scss', 'css', 'sass']: return if file_type == 'scss' or file_type == 'sass': fp_data = css_precompiled_lib.handle_scss(fp.read()) elif file_type == 'less': fp_data = css_precompiled_lib.handle_less(fp.read()) else: fp_data = fp.read() tools.output_file(data['target_path'] + '/' + offset_path + '.css', fp_data)
def css_precompiled(data, offset_path='.', argv=None): """ 预编译css :param data: 规则字典 :param argv: 输入变量 :return: """ now_path = data['source_path'] + '/' + offset_path if os.path.isdir(now_path): fps = os.listdir(now_path) for fp in fps: css_precompiled(data, '/'.join([offset_path, fp]), argv) else: # 判断是不是修改了这个文件 if os.path.realpath(now_path) != os.path.realpath(argv['change_file_path']): return with open(now_path, 'r') as fp: file_type = tools.get_file_type(now_path) if file_type not in ['styl', 'less', 'scss', 'css', 'sass']: return if file_type == 'scss' or file_type == 'sass': fp_data = css_precompiled_lib.handle_scss(fp.read()) elif file_type == 'less': fp_data = css_precompiled_lib.handle_less(fp.read()) else: fp_data = fp.read() tools.output_file(data['target_path'] + '/' + offset_path + '.css', fp_data)
def css_precompiled_get_str(data, offset_path='.'): """ 预编译css :param data: 规则字典 :param argv: 输入变量 :return: """ css_str = '' now_path = data['source_path'] + '/' + offset_path if os.path.isdir(now_path): fps = os.listdir(now_path) for fp in fps: css_str += css_precompiled_get_str(data, '/'.join([offset_path, fp])) else: with open(now_path, 'r') as fp: file_type = tools.get_file_type(now_path) if file_type not in ['styl', 'less', 'scss', 'css']: return if file_type == 'scss': fp_data = css_precompiled_lib.handle_scss(fp.read()) elif file_type == 'less': fp_data = css_precompiled_lib.handle_less(fp.read()) else: fp_data = fp.read() css_str += fp_data return css_str + '\n'