How to use the staticjinja.Reloader.event_handler function in staticjinja

To help you get started, we’ve selected a few staticjinja examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github PyConChina / PyConChina2016 / bin / staticpycon / gen.py View on Github external
if self.should_handle(event_type, src_path):
        print("%s %s" % (event_type, filename))
        if self.site.is_static(filename):
            files = self.site.get_dependencies(filename)
            self.site.copy_static(files)
            # js/css变化时, 强制重新渲染
            self.site.render_templates(self.site.templates)
        elif data_pattern.match(filename):
            # 数据文件变动时, 重新渲染
            self.site.render_templates(self.site.templates)
        else:
            templates = self.site.get_dependencies(filename)
            self.site.render_templates(templates)


Reloader.event_handler = event_handler


PROJECT_ROOT_DIR = dirname(dirname(realpath(dirname(__file__))))

SITE_SRC_DIR = join(PROJECT_ROOT_DIR, 'src')
SITE_ASSET_SRC_DIR = join(PROJECT_ROOT_DIR, 'asset')
DATA_SRC_DIR = join(SITE_SRC_DIR, "data")

SITE_ASSET_URL_PREFIX = './asset'
# 不能使用默认的 Cache 目录, 否则 Cache 也会被 staticjinja 拷贝
WEBASSETS_CACHE_DIR = join(PROJECT_ROOT_DIR, '.webassets-cache')

# 静态站点输出根目录
SITE_DIR = join(PROJECT_ROOT_DIR, 'public')
# webassets 输出根目录, 要输出到 SITE_SRC_DIR, 以便 staticjinja 监控文件变化
SITE_ASSET_DIR = join(SITE_SRC_DIR, 'asset')