def build_(source_dir, build_dir, static_dir, language=None): """ 1. Creates the tree from `source_dir` (:func:`create_tree`), sorts it (:func:`sort_tree`), paginates (:func:`paginate_tree`) and fills with contexts in given `language` (:func:`fill_tree`); 2. Tries to load translation from `./translations/<language>.po`; 3. Creates Jinja2 environment with webassets and i18n extensions and passes it to :func:`build_site`. """ source_path = lambda *args: os.path.join(source_dir, *args) tree = create_tree(source_path('pages'), 'ROOT') tree = sort_tree(tree, settings.ORDERING) tree = paginate_tree(tree, settings.PAGINATION) tree = fill_tree(tree, language=language) translations = None if language: translations_path = source_path('translations/%s.po' % language) if os.path.exists(translations_path): translations = get_translations(translations_path) assets_env = create_assets_env( source_path('static'), static_dir, settings.STATIC_URL, settings.BUNDLES) jinja2_env = create_jinja2_env( url_for=partial(url_for, tree), assets_env=assets_env, translations=translations) build_site(jinja2_env, build_dir, tree)
def test_webassets_integration(self): template = '{% assets "css" %}{{ ASSET_URL }}{% endassets %}' assets_env = create_assets_env('./tests/fixtures/bundle', self.build_dir, { 'css': Bundle('one.css', 'two.css', output='styles.css') }) jinja2_env = create_jinja2_env(assets_env=assets_env) result = jinja2_env.from_string(template).render() self.assertTrue('styles.css' in result)
def test(self): bundle = Bundle("one.css", "two.css", output="styles.css") assets_env = create_assets_env( source_dir="./tests/fixtures/bundle", build_dir=self.build_dir, static_url="/", bundles={} ) bundle.build(env=assets_env) self.assertTrue("styles.css" in os.listdir(self.build_dir))
def test_webassets_integration(self): template = '{% assets "css" %}{{ ASSET_URL }}{% endassets %}' assets_env = create_assets_env( source_dir="./tests/fixtures/bundle", build_dir=self.build_dir, static_url="/", bundles={"css": Bundle("one.css", "two.css", output="styles.css")}, ) jinja2_env = create_jinja2_env(assets_env=assets_env) result = jinja2_env.from_string(template).render() self.assertTrue("styles.css" in result)
def test(self): bundle = Bundle('one.css', 'two.css', output='styles.css') assets_env = create_assets_env('./tests/fixtures/bundle', self.build_dir, {}) bundle.build(env=assets_env) self.assertTrue('styles.css' in os.listdir(self.build_dir))