def cache_theme(self): """ Cache specific theme files """ conf.logger.info("Caching theme files") conf.logger.debug('Using theme files from %s' % (conf.theme_path)) # Post 404 html = render_theme_template(conf.e404_tpl) out = os.path.join(conf.target_path, conf.e404_tpl) u_write(out, html) # Post Search html = render_theme_template(conf.search_tpl) out = os.path.join(conf.target_path, conf.search_tpl) u_write(out, html) # Post Listing self.cache_postlist() # Home post home_page = conf.home_page if home_page in [conf.posts_tpl, conf.search_tpl]: html = render_theme_template(home_page) out = os.path.join(conf.target_path, conf.docroot_index) u_write(out, html) else: if not home_page.endswith(conf.source_ext): home_page = home_page + conf.source_ext home_page_path = os.path.join(conf.source_path, home_page) if os.path.exists(home_page_path): conf.logger.info('Writing %s as home post (%s)'\ %(home_page, conf.docroot_index)) pg = Post(home_page) html = render_theme_template(conf.post_tpl, post=pg) out = os.path.join(conf.target_path, conf.docroot_index) u_write(out, html) # Static files stat_src = os.path.join(conf.theme_path, 'static/') stat_dest = os.path.join(conf.target_path, 'static/') style_src = os.path.join(conf.style_path, 'static') style_dest = os.path.join(conf.target_path, 'static', 'style') if os.path.exists(stat_src): if os.path.exists(stat_dest): shutil.rmtree(stat_dest) shutil.copytree(stat_src, stat_dest) if os.path.exists(style_src): shutil.copytree(style_src, style_dest) # In case source doesn't have a static/ directory if not os.path.exists(style_dest): os.makedirs(style_dest) # Cache scss conf.logger.debug("Compiling scss to static/styles/style.css") style_data = scss.Compiler().compile(conf.style_file_path) with open(os.path.join(style_dest, 'style.css'), 'w') as fh: fh.write(style_data)
def get_scss_compiler(cls): if cls.__SCSS_COMPILER_INSTANCE is None: cls.__SCSS_COMPILER_INSTANCE = StaticFilesCompiler( scss.Compiler().compile, os.path.join(cls.GLADOS_ROOT, 'static/scss'), os.path.join(cls.GLADOS_ROOT, 'static/css/scss-gen'), '.scss', '.css', exclude_regex_str=r'^_.*' ) return cls.__SCSS_COMPILER_INSTANCE
def _sass(): _str = _files_content(build_config.get("scss")) _ionic_path = os.path.abspath( os.path.join(_cur_dir(), "../../resource/share/bower_components/ionic/scss/")) _scss_path = os.path.abspath( os.path.join(_cur_dir(), build_config.get("scssPath"))) _cstr = scss.Compiler( search_path=[_scss_path, _ionic_path]).compile_string(_str) return _cstr.encode("utf8")
def prepare_data(_logging_only: bool = False) -> List[str]: """ Rebuild any dynamically buildable data """ flavours = ["bacteria", "fungi", "plants"] with path.changed_directory(path.get_full_path(__file__, "css")): built_files = [os.path.abspath("%s.css" % flavour) for flavour in flavours] if path.is_outdated(built_files, glob.glob("*.scss")): logging.info("CSS files out of date, rebuilding") for flavour in flavours: target = "%s.css" % flavour assert os.path.exists(flavour + ".scss"), flavour result = scss.Compiler(output_style="expanded").compile(flavour + ".scss") assert result with open(target, "w") as out: out.write(result) return []
def _apply_theme_settings(self): ''' Apply the theme specified in the settings. ''' theme_path = self._settings['theme'] try: with open(theme_path) as theme: style_sheet = theme.read() except IOError: QMessageBox.critical( self, 'Invalid Setting', 'Unable to load theme:\n"{}"'.format(theme_path)) return style_sheet = scss.Compiler().compile_string(style_sheet) self.setStyleSheet(style_sheet)