def test_build(self, mock_start_server, tmp_path: Path): with directory(tmp_path): index = tmp_path / 'index' index.write_text('{{ site }}') run_site_cli("test_cli.py build", build=build_jinja_file) result = tmp_path / 'out' / 'index' assert result.read_text() == "http://localhost:8080/"
def test_specific_clean(self, tmp_path: Path): with directory(tmp_path): out = tmp_path / 'generated' out.mkdir(parents=True) (out / 'file').touch() run_site_cli("test_cli.py clean --out generated") assert not out.exists()
def test_clean(self, tmp_path: Path): with directory(tmp_path): out = tmp_path / 'out' out.mkdir(parents=True) (out / 'file').touch() run_site_cli("test_cli.py clean") assert not out.exists()
def test_build_host_port(self, mock_start_server, tmp_path: Path): with directory(tmp_path): index = tmp_path / 'index' index.write_text('{{ site }}') run_site_cli("test_cli.py build --host 0.0.0.0 --port 69", build=build_jinja_file) result = tmp_path / 'out' / 'index' assert result.read_text() == "http://0.0.0.0:69/"
def test_build_url(self, mock_start_server, tmp_path: Path): with directory(tmp_path): index = tmp_path / 'index' index.write_text('{{ site }}') run_site_cli("test_cli.py build --url https://example.com/", build=build_jinja_file) result = tmp_path / 'out' / 'index' assert result.read_text() == "https://example.com/"
def quickstart(location: str, title: Optional[str]): path = Path(location) path.mkdir(parents=True, exist_ok=True) abs_out = os.path.abspath(path) if not title: title = Path(abs_out).name title_slug = slugify_title(title) template_location = Path(__file__).parent / 'project-template' with directory(template_location), custom_jinja_tags(): site = Site(url="https://example.com/", title=title) [site.add(str(p), jinja(p)) for p in paths('_templates_/**/*.html')] [site.add(str(p), jinja(p)) for p in paths('*.html')] site.add('website.py', jinja('website.py.j2', title_slug=title_slug)) site.add('requirements.txt', jinja('requirements.txt.j2', version=lw_version())) site.add('posts') [ site.add(str(p), jinja(p)) for p in paths('styles/**/*css') if p.name != 'attributes.scss' ] site.add('styles/attributes.scss', jinja('styles/attributes.scss', accent=Color.bright())) site.add('js') site.add('img') site.generate(abs_out) website_file = os.path.join(abs_out, 'website.py') os.chmod(website_file, stat.S_IRWXU | stat.S_IRGRP | stat.S_IROTH) # -rwxr--r-- logger.info(f' Project initialized in: {abs_out}')
def out(self, tmp_path): with directory(tmp_path): yield tmp_path